Reputation: 1
I have a .owl file generated by Protege. (rdf/xml) I have some individuals and I want to get the value of the DataProperty "hasAge".
<owl:NamedIndividual rdf:about="&untitled-ontology-23;a1a">
<untitled-ontology-23:hasAge rdf:datatype="&xsd;int">12</untitled-ontology-23:hasAge>
<untitled-ontology-23:isPartOf rdf:resource="&untitled-ontology-23;A123" />
<rdf:type rdf:resource="&untitled-ontology-23;a1" />
<rdfs:comment>张三</rdfs:comment>
<rdfs:comment>like</rdfs:comment>
<rdfs:isDefinedBy>mike</rdfs:isDefinedBy>
<rdfs:label>gaga</rdfs:label>
<rdfs:label>zeze</rdfs:label>
</owl:NamedIndividual>
How can I get the value "12" (the value of hasAge) by using Ontology API or other ways?
Thanks for answering!!!
Upvotes: 0
Views: 148
Reputation: 1932
With the Ontology API only a small number of generic properties are directly exposed for individuals. To access your ontology-specific properties you need to access the triples in the graph more directly.
If you don't have the Individual instance for the resource already then it might be simplest to use the lower-level IGraph operations instead like this:
var ageTriple = g.GetTriplesWithSubjectPredicate(
g.CreateUriNode(UriFactory.Create("http://example.org/a1a")),
g.CreateUriNode(UriFactory.Create("http://example.org/hasAge")))
.FirstOrDefault();
var ageNode = ageTriple.Object.AsValuedNode();
var age = ageNode.AsInteger();
If you do already have the Individual, you can use its Resource property rather than having to create a UriNode for the first parameter:
var ageTriple = g.GetTriplesWithSubjectPredicate(
individual.Node,
g.CreateUriNode(UriFactory.Create("http://example.org/hasAge")))
.FirstOrDefault();
NOTE As your sample snippet doesn't show what namespace your ontology uses, I have used http://example.org/
as the namespace in the example above - you will need to replace this with the current namespace URI.
Upvotes: 0