You do not need to use the loader; if you do the input must be N-Quads if you pass in an InputStream. At a guess, and we can't see the data, the app tried to read JSON-LD.


Use RDFDataMgr.read.


dataset.begin(ReadWrite.WRITE);
try {
RDFDataMgr.read(dataset,
               "/Users/izharullah/workspace/MyTDB/Soil1A.jsonld") ;
dataset.commit();
} finally { dataset.end(); }


Or

Txn.executeWrite(dataset, ()->
   RDFDataMgr.read(dataset,
               "/Users/izharullah/workspace/MyTDB/Soil1A.jsonld") ;
   );

        Andy

On 26/01/17 07:54, Lorenz B. wrote:
Hello Izhar,

from the error messages I guess that the data is invalid:


[line: 2, col: 10] Expected BNode or IRI: Got: 
[STRING2:56e1613a0dd8e408f1ca4d9d]


You can check line 2 or post here at least the beginning of the file
(~10 lines or something) that you load into TDB.


Lorenz

Hi,

I just started learning Jena programming and have very little acquaintance with 
its APIs. I ran the following code using TDB and a SPARQL query just to test it 
but I got some errors after running the program. Here is the code:


public class TDBexample2 {


    public static void main(String[] args) {

        FileManager fm = FileManager.get();

        fm.addLocatorClassLoader(TDBexample2.class.getClassLoader());

        InputStream in = 
fm.open("/Users/izharullah/workspace/MyTDB/Soil1A.jsonld");


        Location location = Location.create 
("/Users/izharullah/workspace/MyTDB");


        // Load some initial data

        
TDBLoader.load(TDBInternal.getBaseDatasetGraphTDB(TDBFactory.createDatasetGraph(location)),
 in, false);



        String queryString =



            "SELECT (COUNT(*) AS ?count) { " +

            "    ?s ?p ?o . " +

            "}" ;





        Dataset dataset = TDBFactory.createDataset(location);

        dataset.begin(ReadWrite.READ);

        try {

            Query query = QueryFactory.create(queryString);

            QueryExecution qexec = QueryExecutionFactory.create(query, dataset);

            try {

                ResultSet results = qexec.execSelect();

                while ( results.hasNext() ) {

                    QuerySolution soln = results.nextSolution();

                    Literal count = soln.getLiteral("count");

                    System.out.println(count);

                }

            } finally {

                qexec.close();

            }

        } finally {

            dataset.end();

        }

    }


}


I got some unexpected errors, here is the snapshot:


Exception in thread "main" org.apache.jena.riot.RiotException: [line: 2, col: 
10] Expected BNode or IRI: Got: [STRING2:56e1613a0dd8e408f1ca4d9d]

at 
org.apache.jena.riot.system.ErrorHandlerFactory$ErrorHandlerStd.fatal(ErrorHandlerFactory.java:136)

at org.apache.jena.riot.lang.LangEngine.raiseException(LangEngine.java:165)

at org.apache.jena.riot.lang.LangEngine.exceptionDirect(LangEngine.java:158)

at org.apache.jena.riot.lang.LangEngine.exception(LangEngine.java:151)

at org.apache.jena.riot.lang.LangNTuple.checkIRIOrBNode(LangNTuple.java:90)

at org.apache.jena.riot.lang.LangNQuads.parseOne(LangNQuads.java:86)

at org.apache.jena.riot.lang.LangNQuads.runParser(LangNQuads.java:54)

at org.apache.jena.riot.lang.LangBase.parse(LangBase.java:42)

at 
org.apache.jena.riot.RDFParserRegistry$ReaderRIOTLang.read(RDFParserRegistry.java:178)

at org.apache.jena.riot.RDFDataMgr.process(RDFDataMgr.java:859)

at org.apache.jena.riot.RDFDataMgr.parse(RDFDataMgr.java:698)

at org.apache.jena.riot.RDFDataMgr.parse(RDFDataMgr.java:677)

at 
org.apache.jena.tdb.store.bulkloader.BulkLoader.loadQuads$(BulkLoader.java:152)

at 
org.apache.jena.tdb.store.bulkloader.BulkLoader.loadDataset(BulkLoader.java:115)

at org.apache.jena.tdb.TDBLoader.loadDataset$(TDBLoader.java:265)

at org.apache.jena.tdb.TDBLoader.loadDataset(TDBLoader.java:200)

at org.apache.jena.tdb.TDBLoader.load(TDBLoader.java:85)

at TDBexample2.main(TDBexample2.java:28)


Can someone help me what is the problem with the code?

Many thanks in advance.


Best regards,


Izhar


Reply via email to