Querying named RDF graphs in TDB using tdbquery

前端 未结 2 1924
南笙
南笙 2021-01-25 15:54

I am trying to query my newly created TDB database use the tdbquery program. However, I am having a hard time writing a query that targets the correct named graph. I am doing th

2条回答
  •  悲哀的现实
    2021-01-25 16:27

    The problem here is that you have put a relative URI graph name into the data. RDF is define to work with absolute URIs (i.e start with "http:" or some other URI-scheme name).

    Try

    RDFDataMgr.write(System.out, dataset, Lang.NQUADS)
    

    to see more clearly what's in the dataset. The output of tdbquery may invoke URI shorteners so some of your data has absolute URIs and some relative but it looks the same in the text format.

    When "SELECT * { GRAPH { ?s ?p ?o } }" is parsed, just like if you read data from a file, relative URIs are resolved - the base URI is where the code is running so you get file:///usr/local/apache-jena-2.12.1/bin/facts

    Try dataset.addNamedModel("http://example/facts", facts);

    PS 1

    Model m = dataset.getNamedModel("http://example/facts") ;
    m.read("lineitem.ttl") ;
    

    PS 2 sync() isn't necessary if you use transactions

提交回复
热议问题