routes - How to programatically list the relationship between two instances in an ontology? -
i have ontology made of relationship follows
company1 :hassubsidary sub1 :hasdepartment cars1 :hassubdepartment manufacturing :isinbuilding area1 :hasunit precisionmaching :hasmachine lathemachine1
i have ontology model these individual created , relationships described.
howe can grammatically list relationship path given input parameters company1
, lathemachine1
using jena or other api?
you don't namespace ontology, i'm going speculate it's http://example.com/ontologies/test#
. given that, have 2 basic choices: use sparql, or use jena rdf api directly.
in first case, query simple:
prefix ex: <http://example.com/ontologies/test#> select distinct ?relationship { ex:company1 ?relationship ex:lathemchine1 }
you can see how run sparql query java code in jena documentation.
in second case, it's pretty straightforward:
model m = ... rdf model ... ; string ns = "http://example.com/ontologies/test#"; resource company1 = m.getresource( ns + "company1" ); resource lathe1 = m.getresource( ns + "lathemachine1" ); set<property> relationships = new hashset<property>(); (stmtiterator = m.liststatements( company1, null, lathe1 ); i.hasnext();) { statement s = i.next(); relationships.add( s.getpredicate() ); }
update after poster explained question more in comments:
ok, need path between given nodes. if want a path, opposed all paths, can use onttools.findshortestpath()
:
path p = onttools.findshortestpath( m, company1, lathe1, filter.any() );
if want paths, use code in findshortestpath
template simple breadth-first search.
Comments
Post a Comment