sparql - Querying named RDF graphs in TDB using tdbquery -
i trying query newly created tdb database use tdbquery program. however, having hard time writing query targets correct named graph. doing following:
first create new dataset , add name graph called "facts"
dataset dataset = tdbfactory.createdataset("/tdb/"); dataset.begin(readwrite.write) ; try { model facts = rdfdatamgr.loadmodel("lineitem.ttl") ; dataset.addnamedmodel("facts", facts); dataset.commit(); tdb.sync(dataset); dataset.end(); } { dataset.close(); }
when query graphs in tdb database looks fine.
./tdbquery --loc /tdb/ "select * { graph ?g { ?s ?p ?o } }" -------------------------------------------------- | s | p | o | g | ================================================== | <fact1> | <predicate> | <nation> | <facts> | | <fact2> | <predicate> | <region> | <facts> | --------------------------------------------------
if try query named graph not find , triples.
./tdbquery -v --loc /tdb/ "select * { graph <facts> { ?s ?p ?o } }" or ./tdbquery -v --loc /tdb/ "select * named <facts> { ?s ?p ?o }" ------------- | s | p | o | ============= -------------
when @ algebra version of query see context (the graph) in quad wrong.
info exec :: algebra (quadpattern (quad <file:///usr/local/apache-jena-2.12.1/bin/facts> ?s ?p ?o))
i know quad pattern should be: (quad ?s ?p ?o)
how query named graph in tdb database?
regards
when @ algebra version of query see context (the graph) in quad wrong.
info exec :: algebra (quadpattern (quad <file:///usr/local/apache-jena-2.12.1/bin/facts> ?s ?p ?o))
i know quad pattern should be:
(quad ?s ?p ?o)
no correct (if not expect)
a quadpattern
searches against quads , includes 4 fields first of name of graph searched
and problem lies, graph names uris provided facts
name treated relative uri , such subject resolution may differ in different parts of system.
in example query parser uses working directory base uri leading strange graph name see in algebra plan.
you can see graph names in tdb store issuing following query:
select ?g { graph ?g { } }
if absolute uri can specify directly in original query, if not there no way query command line.
fixing issue
don't use relative uris wherever possible. if want use them don't use them without specifying base uri explicitly
so in code load data make sure give absolute uri graph e.g.
dataset.addnamedmodel("http://example.org/facts", facts);
and if want able use relative uris refer graph in queries use appropriate base
declaration uri resolved want e.g.
./tdbquery -v --loc /tdb/ "base <http://example.org/> select * { graph <facts> { ?s ?p ?o } }"
Comments
Post a Comment