如何从超类

时间:2016-06-14 20:12:42

标签: owl ontology protege owl-api reasoning

我正在使用owlapi和java开发我的本体,但在这种情况下我无法找到解决方案:

这里我有一个类结构,例如:

  • 电子
    • 无线电
      • 手持

我为这些类创建了与其类同名的人。由于电子类有一个名为电子产品的个人。

  • 分类:电子产品

    相当于:关键字{" electronics"}

  • 分类:方便

    Dataproperty:关键字

    数据属性值:"方便" ,类型:字符串

我使用隐士搜索个人关键字{" electronics"," handy"}

我把正确的人当作电子设备并且方便。

当我想在我的Java代码中列出个人的dataproperty 关键字值时,我无法获得电子设备的关键字值。 结果如下:

  • 个人:电子产品关键字:null
  • 个人:方便关键字:"方便" (必须是"电子产品""便利&# 34;,但我不能列出关键字值"电子产品"为方便的个人而设

如何获取电子类的数据表值,以及如何计算匹配的关键字。

我想将查询结果显示为:

  • 个人:电子产品,关键字:" 电子产品",匹配关键字数量:1
  • 个人:方便,关键字{" electronics"," handy" },匹配关键字 count:2

谢谢。

这是我的本体论:

<?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 

- &gt;`以下是我在java中的一些代码,我将indivduals的关键字值与KeywordArray元素进行比较:

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 + " ]");
}'

0 个答案:

没有答案