java - Traversing anonymous/blank nodes in Jena -
i using apache jena's api, graph contains anonymous/blank nodes well, due unionof , intersectionof. 1 of such example is:
<owl:class> <owl:unionof rdf:parsetype="collection"> <rdf:description rdf:about="http://www.summyurl.com/something#entity1"/> <rdf:description rdf:about="http://www.summyurl.com/something#entity2"/> </owl:unionof> </owl:class>
which anonymous node/resource. when try uri, like:
"-50a5734d:15d839467d9:-1b8b"
i neither able sparql query using such uris (due exception on parsing such uris), nor able find appropriate jena method handle it.
i looking way explode such nodes , nested resources of it.
for example in below case, should return <http:/.../entity1>
, <http:/.../entity2>
, <http:/.../entity3>
<owl:class> <owl:unionof rdf:parsetype="collection"> <rdf:description rdf:about="http://www.summyurl.com/something#entity1"/> <owl:unionof rdf:parsetype="collection"> <rdf:description rdf:about="http://www.summyurl.com/something#entity2"/> <rdf:description rdf:about="http://www.summyurl.com/something#entity3"/> </owl:unionof> </owl:unionof> </owl:class>
is there inbuilt method of jena handle it?
if not, how can efficiently?
using jena-model-api:
string s = "<rdf:rdf\n" + " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n" + " xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n" + " xmlns:owl=\"http://www.w3.org/2002/07/owl#\"\n" + " xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"\n" + " xmlns:xsd=\"http://www.w3.org/2001/xmlschema#\">\n" + " <owl:ontology/>\n" + " <owl:class>\n" + " <owl:unionof rdf:parsetype=\"collection\">\n" + " <owl:class rdf:about=\"http://www.summyurl.com/something#entity1\"/>\n" + " <owl:class>\n" + " <owl:unionof rdf:parsetype=\"collection\">\n" + " <owl:class rdf:about=\"http://www.summyurl.com/something#entity1\"/>\n" + " <owl:class rdf:about=\"http://www.summyurl.com/something#entity2\"/>\n" + " </owl:unionof>\n" + " </owl:class>\n" + " </owl:unionof>\n" + " </owl:class>\n" + "</rdf:rdf>"; model m = modelfactory.createdefaultmodel(); try (inputstream in = new bytearrayinputstream(s.getbytes(standardcharsets.utf_8))) { m.read(in, lang.rdfxml.getlabel()); } //m.write(system.out, "ttl"); m.liststatements() .mapwith(statement::getobject) .filterkeep(rdfnode::isuriresource) .mapwith(rdfnode::asresource) .filterdrop(owl.class::equals) .filterdrop(owl.ontology::equals) .filterdrop(rdf.nil::equals) .mapwith(resource::geturi) .foreachremaining(system.out::println);
the output:
http://www.summyurl.com/something#entity1 http://www.summyurl.com/something#entity2 http://www.summyurl.com/something#entity1
this example. there lot of ways handle anything
Comments
Post a Comment