问题
I am working on my ontology using owlapi and java, but I cant find a solution in such a case:
Here I have a class structure such as:
- Electronics
- Radio
- Handy
- Radio
I created individuals to these classes having the same name as their class. As Electronics class has an individual named electronics.
Class: Electronics
Equivalent to: keyword some {"electronics"}.
Class: Handy
Dataproperty: keyword
Data property value: "handy", type:string
I use Hermit to search for individuals as keyword some {"electronics","handy"}.
I get the correct individuals as electronics and handy.
When I want to list the dataproperty keyword values of individuals in my Java code I cannot get keyword value of electronics. Result is as follows:
- Individual: electronics and keyword: null
- Individual: handy and keyword: "handy" (It must be "electronics" and "handy", but I can not list the keyword value "electronics" for handy individual)
How can I get dataproperty value of electronics class and how can I count matching keywords.
I want to display my query results as:
- Individual: electronics, keyword:"electronics", matching keyword count:1
- Individual:handy, keyword {"electronics","handy"}, matching keyword count:2
Thank you.
Here is my ontology:
<?xml version="1.0" encoding="UTF-8"?>
<Ontology xml:base="http://www.semanticweb.org/2015/ipek_ontology" ontologyIRI="http://www.semanticweb.org/2015/ipek_ontology">
<Prefix name="" IRI="http://www.w3.org/2002/07/owl#"/>
<Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
<Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
<Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
<Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/>
<Declaration>
<Class IRI="#Electronics"/>
</Declaration>
<Declaration>
<Class IRI="#Handy"/>
</Declaration>
<Declaration>
<Class IRI="#Radio"/>
</Declaration>
<Declaration>
<DataProperty IRI="#GTIP_number"/>
</Declaration>
<Declaration>
<DataProperty IRI="#Keyword"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#Electronics"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#handy"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#radio"/>
</Declaration>
<EquivalentClasses>
<Class IRI="#Electronics"/>
<DataHasValue>
<DataProperty IRI="#Keyword"/>
<Literal datatypeIRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral">electronics</Literal>
</DataHasValue>
</EquivalentClasses>
<SubClassOf>
<Class IRI="#Handy"/>
<Class IRI="#Radio"/>
</SubClassOf>
<SubClassOf>
<Class IRI="#Radio"/>
<Class IRI="#Electronics"/>
</SubClassOf>
<ClassAssertion>
<Class IRI="#Electronics"/>
<NamedIndividual IRI="#Electronics"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Handy"/>
<NamedIndividual IRI="#handy"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Radio"/>
<NamedIndividual IRI="#radio"/>
</ClassAssertion>
<DataPropertyAssertion>
<DataProperty IRI="#GTIP_number"/>
<NamedIndividual IRI="#Electronics"/>
<Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#string">20.12 </Literal>
</DataPropertyAssertion>
<DataPropertyAssertion>
<DataProperty IRI="#GTIP_number"/>
<NamedIndividual IRI="#handy"/>
<Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#string">20.12.15.47</Literal>
</DataPropertyAssertion>
<DataPropertyAssertion>
<DataProperty IRI="#Keyword"/>
<NamedIndividual IRI="#handy"/>
<Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#string">handy</Literal>
</DataPropertyAssertion>
<DataPropertyAssertion>
<DataProperty IRI="#GTIP_number"/><NamedIndividual IRI="#radio"/>
<Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#string">20.12.15</Literal>
</DataPropertyAssertion>
<DataPropertyRange>
<DataProperty IRI="#GTIP_number"/>
<Datatype abbreviatedIRI="xsd:string"/>
</DataPropertyRange>
<DataPropertyRange>
<DataProperty IRI="#Keyword"/>
<Datatype abbreviatedIRI="xsd:string"/>
</DataPropertyRange>
<AnnotationAssertion>
<AnnotationProperty abbreviatedIRI="rdfs:label"/><IRI>#Electronics</IRI>
<Literal datatypeIRI="http://www.w3.org/2000/01/rdf-schema#Literal">Electronics</Literal>
</AnnotationAssertion>
<AnnotationAssertion>
<AnnotationProperty abbreviatedIRI="rdfs:label"/>
<IRI>#GTIP_number</IRI>
<Literal datatypeIRI="http://www.w3.org/2000/01/rdf-schema#Literal">GTIP_number</Literal>
</AnnotationAssertion>
<AnnotationAssertion>
<AnnotationProperty abbreviatedIRI="owl:deprecated"/><IRI>#Keyword</IRI>
<Literal datatypeIRI="http://www.w3.org/2000/01/rdf-schema#Literal">Keyword</Literal>
</AnnotationAssertion>
<AnnotationAssertion>
<AnnotationProperty abbreviatedIRI="rdfs:label"/><IRI>#Radio</IRI>
<Literal datatypeIRI="http://www.w3.org/2000/01/rdf-schema#Literal">Radio</Literal>
</AnnotationAssertion>
<AnnotationAssertion>
<AnnotationProperty abbreviatedIRI="rdfs:comment"/>
<AbbreviatedIRI>rdfs:isDefinedBy</AbbreviatedIRI>
<Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#string">Product Code</Literal>
</AnnotationAssertion>
<AnnotationAssertion>
<AnnotationProperty abbreviatedIRI="rdfs:isDefinedBy"/>
<AbbreviatedIRI>rdfs:isDefinedBy</AbbreviatedIRI>
<Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#Name">Funda</Literal>
</AnnotationAssertion>
<AnnotationAssertion>
<AnnotationProperty abbreviatedIRI="owl:versionInfo"/>
<AbbreviatedIRI>rdfs:isDefinedBy</AbbreviatedIRI>
<Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#string">1.0</Literal>
</AnnotationAssertion>
</Ontology>
<!-- Generated by the OWL API (version 3.4.2) http://owlapi.sourceforge.net
-->`And the following is some piece of my code in java, I compare keyword values of indivduals with KeywordArray elements:
public static String RankEntity(OWLEntity entity){ //rank results
StringBuilder sb=new StringBuilder();
OWLDataProperty p = factory.getOWLDataProperty(IRI.create(base + "keyword"));
String keyword="";
Set<OWLNamedIndividual> result = entity.getIndividualsInSignature();
for (OWLNamedIndividual owlNamedIndividual : result) {
for (OWLClassExpression eclass:EntitySearcher.getTypes(owlNamedIndividual, ontology)){
for (OWLLiteral lit: EntitySearcher .getDataPropertyValues(owlNamedIndividual,p,ontology)){
for (int j=0;j<KeywordArray.length;j++){
if (KeywordArray[j]!=null){
if(lit.getLiteral().equals(KeywordArray[j]))
{
if (keyword=="")
keyword+= " " + KeywordArray[j];
else
keyword+= ", " + KeywordArray[j];
erank++;
}
}
}
}
}
System.out.println("Rank: [ " + erank + " ]\t " +
"keywords: [ " + keyword + " ]");
}
return ("Rank: [ " + erank + " ]\t " +
"Keywords: [ " + keyword + " ]");
}'
来源:https://stackoverflow.com/questions/37821246/howto-get-dataproperty-inherited-from-superclass