I found the problem: spaces in the triple components

What would be a reasonable way to encode the triple strings?

On Tue 3 Mar, 2020 10:01 pm Andy Seaborne, <[email protected]> wrote:

> That codes OK - it uses transactions.
>
> Are you starting with a fresh database or an existing one with some data?
>
>      Andy
>
> On 03/03/2020 14:45, Diptendu Dutta wrote:
> > The code that is used to populate the database is given below.
> > It is called in side a FOR loop. Why is the database getting corrupted?
> >
> > static public void writeTriple(String corpus_file_id, String subject,
> > String predicate, String object) {
> >
> > dataset.begin(ReadWrite.WRITE) ;
> > Model model = null;
> >
> > try {
> >
> > model = dataset.getNamedModel(corpus_file_id);
> >
> >         Resource subjectResource =
> model.createResource(ns.concat(subject));
> >
> >         Property property = model.createProperty(ns.concat(predicate));
> >
> >         Resource objectResource =
> model.createResource(ns.concat(object));
> >
> >         model.add(subjectResource, property, objectResource);
> >         Statement statement = model.createStatement(subjectResource,
> > property, objectResource);
> >         model.add(statement);
> >         model.close();
> >         dataset.commit();
> > }
> > catch(Exception ex) {
> > ex.printStackTrace();
> > }
> > finally {
> >         dataset.end();
> > }
> >
> > }
> >
> > I can see that the database has been created:
> >
> > image.png
> >
> >
> > On Tue, Mar 3, 2020 at 7:40 PM Andy Seaborne <[email protected]
> > <mailto:[email protected]>> wrote:
> >
> >     It looks like previously you were using the database withotu
> >     transactions and didn't shutdown cleanly.
> >
> >     The database has been corrupted. You'll need to rebuild it.
> >
> >     The code below is fine - the problem happened beforehand and is only
> >     now
> >     showing up.
> >
> >           Andy
> >
> >     On 03/03/2020 14:01, Diptendu Dutta wrote:
> >      > I am getting java.lang.StringIndexOutOfBoundsException while
> writing
> >      > RDF from a model (model.write()). I have tried with other
> mechanisms
> >      > such as RDFWriter, RDFDataMgr but I get exactly the same error.
> >      > Here is the code:
> >      >
> >      > static public String getRDF(String corpus_file_id) {
> >      >
> >      > String rdfString = null;
> >      >
> >      > Model model = null;
> >      >
> >      > dataset.begin(ReadWrite.READ) ;
> >      >
> >      > try {
> >      > model = dataset.getNamedModel(corpus_file_id);
> >      > model.write(System.out, "RDF/XML");
> >      > } catch (Exception e) {
> >      > // TODO Auto-generated catch block
> >      > e.printStackTrace();
> >      > }finally {
> >      > model.close();
> >      >         dataset.end();
> >      > }
> >      > return rdfString;
> >      > }
> >      >
> >      > java.lang.StringIndexOutOfBoundsException: String index out of
> >     range: 46
> >      > at java.lang.String.charAt(String.java:658)
> >      > at org.apache.jena.atlas.lib.StrUtils.decodeHex(StrUtils.java:212)
> >      > at
> >
>  org.apache.jena.tdb.store.nodetable.NodecSSE.decode(NodecSSE.java:121)
> >      > at org.apache.jena.tdb.lib.NodeLib.decode(NodeLib.java:120)
> >      > at org.apache.jena.tdb.lib.NodeLib.fetchDecode(NodeLib.java:97)
> >      > at
> >      >
> >
>  
> org.apache.jena.tdb.store.nodetable.NodeTableNative.readNodeFromTable(NodeTableNative.java:182)
> >      > at
> >      >
> >
>  
> org.apache.jena.tdb.store.nodetable.NodeTableNative._retrieveNodeByNodeId(NodeTableNative.java:108)
> >      > at
> >      >
> >
>  
> org.apache.jena.tdb.store.nodetable.NodeTableNative.getNodeForNodeId(NodeTableNative.java:67)
> >      > at
> >      >
> >
>  
> org.apache.jena.tdb.store.nodetable.NodeTableCache._retrieveNodeByNodeId(NodeTableCache.java:128)
> >      > at
> >      >
> >
>  
> org.apache.jena.tdb.store.nodetable.NodeTableCache.getNodeForNodeId(NodeTableCache.java:82)
> >      > at
> >      >
> >
>  
> org.apache.jena.tdb.store.nodetable.NodeTableWrapper.getNodeForNodeId(NodeTableWrapper.java:50)
> >      > at
> >      >
> >
>  
> org.apache.jena.tdb.store.nodetable.NodeTableInline.getNodeForNodeId(NodeTableInline.java:67)
> >      > at org.apache.jena.tdb.lib.TupleLib.quad(TupleLib.java:126)
> >      > at org.apache.jena.tdb.lib.TupleLib.quad(TupleLib.java:120)
> >      > at
> >      >
> >
>  org.apache.jena.tdb.lib.TupleLib.lambda$convertToQuads$3(TupleLib.java:59)
> >      > at org.apache.jena.atlas.iterator.Iter$2.next(Iter.java:352)
> >      > at org.apache.jena.atlas.iterator.Iter$2.next(Iter.java:352)
> >      > at org.apache.jena.atlas.iterator.Iter.next(Iter.java:1072)
> >      > at
> >      >
> >
>  org.apache.jena.util.iterator.WrappedIterator.next(WrappedIterator.java:94)
> >      > at
> >     org.apache.jena.util.iterator.Map1Iterator.next(Map1Iterator.java:46)
> >      > at
> >
>  org.apache.jena.util.iterator.NiceIterator.asSet(NiceIterator.java:208)
> >      > at
> >
>  org.apache.jena.util.iterator.NiceIterator.toSet(NiceIterator.java:199)
> >      > at
> org.apache.jena.graph.GraphUtil.listPredicates(GraphUtil.java:66)
> >      > at
> >
>  org.apache.jena.rdf.model.impl.ModelCom.listPredicates(ModelCom.java:999)
> >      > at
> >      >
> >
>  org.apache.jena.rdf.model.impl.ModelCom.listNameSpaces(ModelCom.java:1012)
> >      > at
> >      >
> >
>  
> org.apache.jena.rdfxml.xmloutput.impl.BaseXMLWriter.addNameSpaces(BaseXMLWriter.java:219)
> >      > at
> >      >
> >
>  
> org.apache.jena.rdfxml.xmloutput.impl.BaseXMLWriter.setupNamespaces(BaseXMLWriter.java:488)
> >      > at
> >      >
> >
>  
> org.apache.jena.rdfxml.xmloutput.impl.BaseXMLWriter.write(BaseXMLWriter.java:470)
> >      > at
> >      >
> >
>  
> org.apache.jena.rdfxml.xmloutput.impl.BaseXMLWriter.write(BaseXMLWriter.java:460)
> >      > at
> >      >
> >
>  
> org.apache.jena.riot.adapters.AdapterRDFWriter.write(AdapterRDFWriter.java:64)
> >      > at org.apache.jena.riot.RDFWriter.write$(RDFWriter.java:202)
> >      > at org.apache.jena.riot.RDFWriter.output(RDFWriter.java:161)
> >      > at org.apache.jena.riot.RDFWriter.output(RDFWriter.java:112)
> >      > at
> >
>  org.apache.jena.riot.RDFWriterBuilder.output(RDFWriterBuilder.java:205)
> >      > at
> >
>  org.apache.jena.riot.adapters.RDFWriterRIOT.write(RDFWriterRIOT.java:86)
> >      > at
> org.apache.jena.rdf.model.impl.ModelCom.write(ModelCom.java:379)
> >      > at knowledgegraph.JenaProcessor.getRDF(JenaProcessor.java:89)
> >      >
> >
>

Reply via email to