如何从整个Ontology中提取特定个体的同义词?

How to extract the synonyms of a specific individual from the whole Ontology?

我正在使用 jena.I 在 Eclipse 中实现 ontology 我正在尝试从整个 ontology 中获取个人的同义词。

我如何从整个 ontology 中获取特定个体的所有同义词,而不考虑 class。

 static final String inputFileName = "http://word.owl";
OntModel inf = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
        InputStream in = FileManager.get().open(inputFileName);
        inf.read(in, "");       
        ExtendedIterator classes = inf.listClasses();
        while(classes.hasNext())
        {
            OntClass obj = (OntClass) classes.next();
            String className = obj.getLocalName().toString();
            System.out.println("Class Name : "+className);                         
        }   
        ExtendedIterator instances = inf.listIndividuals();
        while(instances.hasNext())
        {
            Individual ind = (Individual) instances.next();
            String indName = ind.getLocalName().toString();
            System.out.println("Individual Name : "+indName);                          
        }    

    ExtendedIterator property = inf.listDatatypeProperties();
   while(property.hasNext())
   {
       DatatypeProperty prop = (DatatypeProperty) property.next();
        String propName = prop.getLocalName().toString();
        System.out.println("Data Propties Name : "+propName);                           
    }
    ExtendedIterator property1 = inf.listObjectProperties();
    while(property1.hasNext())
    {
       ObjectProperty prop = (ObjectProperty) property1.next();
      String propName = prop.getLocalName().toString();
     System.out.println("Object Propties Name : "+propName);                           
}

    ObjectProperty isSynonymOf = inf.getObjectProperty("http://www.../Word#isSynonymOf"); 

    System.out.println("Individuals having isSynonymOf Proterty:");

    ExtendedIterator individuals1 = inf.listIndividuals();
    while(individuals1.hasNext())
    {
        Individual ind = (Individual) individuals1.next();
        if(ind.getProperty(isSynonymOf) != null)
       {
           String indName = ind.getLocalName().toString();
           System.out.println(indName);
       }


       }
}

问题:当我输入个人时 软件 它应该给我所有的同义词 - 软件
- 软件架构 - 软件设计 - 计划

这是我的 OWL 文件

  <?xml version="1.0"?>
  <rdf:RDF xmlns="http://www.semanticweb.org/ontologies/Word#"
  xml:base="http://www.semanticweb.org/ontologies/Word"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:owl="http://www.w3.org/2002/07/owl#"
  xmlns:xml="http://www.w3.org/XML/1998/namespace"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
 <owl:Ontology rdf:about="http://www.semanticweb.org/ontologies/Word"/>

默认 OntModel 不考虑应用 OWL 推理,因此,必须启用推理才能明确考虑对称属性:

OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);

有关详细信息,请参阅 documentation

附带说明一下,耶拿有很多方便的方法,例如使用

可以缩短您的代码
model.listSubjectsWithProperty(isSynonymOf)