currently I am doing a project on Ontology Based Information Retrieval. I have created the base ontology using the ontology editor, Protege and obtained the file , say family.owl .Basically i want to perform a search function .The user provides the search term and then it is searched with the individuals in the ontology . If a match is found ,then print the comment associated with that individual .I have used the Jena API to parse the ontology .So far i am successful in obtaining the subject , predicate and object associated with each resource but i am not able to get the comment associate with each resource . A part of family.owl looks like this
<!-- http://www.semanticweb.org/ontologies/2012/9/family.owl#Beth -->
<owl:Thing rdf:about="#Beth">
<rdfs:comment>Beth is the Daughter of Adam . She is the Sister of Chuck .
She is the Mother of Dotty & Edward . She is the Aunt of Fran & Greg.
</rdfs:comment>
<isChildOf rdf:resource="#Adam"/>
<isSiblingOf rdf:resource="#Chuck"/>
</owl:Thing>
So when i search for Beth ,I should get the comment associated with it ie.Beth is the Daughter of Adam . She is the Sister of Chuck.She is the Mother of Dotty & Edward . She is the Aunt of Fran & Greg.The code i have used to get the subject,predicate and object is as follows
StmtIterator iter=model.listStatements();
while(iter.hasNext())
{
Statement stmt=iter.nextStatement();
String subject=stmt.getSubject().toString;
String predicate=stmt.getPredicate().toString();
String object=stmt.getObject().toString();
...
}
The rdfs:comment
should be there as one of the predicates that you get (its toString
, which you are advised not to rely on incidentally, will be: http://www.w3.org/2000/01/rdf-schema#comment
). If it's not there, then either your code isn't what you are showing us or the data is not what you quote. Since I couldn't find the ontology you refer to, we have no way of checking that.
An easier way to do what you want would be to use the Jena ontology API. Using the ontology API, you could do something like this (I haven't run this code, but it should work):
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
FileManager.get().readModel( m, "... your input file here ..." );
String NS = "http://www.semanticweb.org/ontologies/2012/9/family.owl#";
Individual beth = m.getIndividual( NS + "Beth" );
String comment = beth.getComment();