无法获取单词 ontology 的子类和实例
can not get the subclasses and instances of word ontology
我想实现一个 ontology of Word
,其中包括三个子 类:
我试图从文件中加载 ontology,但我无法获取 Word
的子 类 和指定子类的所有实例。我的代码如下所示:
import java.util.Iterator;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.SystemOutDocumentTarget;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.semanticweb.owlapi.model.PrefixManager;
import org.semanticweb.owlapi.util.AutoIRIMapper;
import org.semanticweb.owlapi.util.DefaultPrefixManager;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntResource;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
public class Main {
public static OWLOntologyManager create() {
OWLOntologyManager m = OWLManager.createOWLOntologyManager();
// PriorityCollection<OWLOntologyIRIMapper> iriMappers = m.getIRIMappers();
// iriMappers.add(new AutoIRIMapper(new File("materializedOntologies"), true));
return m;
}
public static void main(String[] args) throws OWLOntologyCreationException, OWLOntologyStorageException {
// Get hold of an ontology manager
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
// Load an ontology from the Web
IRI iri = IRI.create("http://anywhere");
OWLOntology pizzaOntology = `manager.loadOntologyFromOntologyDocument(iri);`
System.out.println("Loaded ontology: " `enter code here`+ WordOntology);
manager.removeOntology(WordOntology);
File file = new File("word.owl");
OWLDataFactory dataFactory = manager.getOWLDataFactory();
PrefixManager pm = new DefaultPrefixManager(base);
OWLClass Word = dataFactory.getOWLClass(":Word", pm);
OWLNamedIndividual Software = `dataFactory.getOWLNamedIndividual(":Software", pm);`
OWLClassAssertionAxiom classAssertion =
dataFactory.getOWLClassAssertionAxiom(Word, Software);
OWLOntology ontology = manager.createOntology(IRI.create(base));
manager.addAxiom(ontology, classAssertion);
manager.saveOntology(ontology, new SystemOutDocumentTarget());
OWLOntologyManager m = create();
OWLOntology o = m.loadOntologyFromOntologyDocument(iri);
assertNotNull(o);
OWLDataFactory factory = manager.getOWLDataFactory();
for (OWLClass cls : o.getClassesInSignature())
System.out.println(cls);
}
}
OWLOntology::getSubClassAxiomsForSuperClass(OWLClass)
将 return subclass 公理,其中指定的 class 是 superclass - subclass 中的在您的示例中,公理将是 Word
的子 class。
OWLOntology::getClassAssertionAxioms(OWLClass)
returns class 具有指定 class 的断言 - 这些公理中的个体将是 Word
.[=16 的实例=]
请注意,这些方法仅 return 在 ontology 中显式的数据;要查找可以推断的数据,您需要使用 OWLReasoner
。 OWLReasoner
的正确实现存在于 OWLAPI 之外,例如参见 Pellet、HermiT、FaCT++、Konclude、JFact(开源)和 StarDog(商业许可)。
我想实现一个 ontology of Word
,其中包括三个子 类:
我试图从文件中加载 ontology,但我无法获取 Word
的子 类 和指定子类的所有实例。我的代码如下所示:
import java.util.Iterator;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.SystemOutDocumentTarget;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.semanticweb.owlapi.model.PrefixManager;
import org.semanticweb.owlapi.util.AutoIRIMapper;
import org.semanticweb.owlapi.util.DefaultPrefixManager;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntResource;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
public class Main {
public static OWLOntologyManager create() {
OWLOntologyManager m = OWLManager.createOWLOntologyManager();
// PriorityCollection<OWLOntologyIRIMapper> iriMappers = m.getIRIMappers();
// iriMappers.add(new AutoIRIMapper(new File("materializedOntologies"), true));
return m;
}
public static void main(String[] args) throws OWLOntologyCreationException, OWLOntologyStorageException {
// Get hold of an ontology manager
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
// Load an ontology from the Web
IRI iri = IRI.create("http://anywhere");
OWLOntology pizzaOntology = `manager.loadOntologyFromOntologyDocument(iri);`
System.out.println("Loaded ontology: " `enter code here`+ WordOntology);
manager.removeOntology(WordOntology);
File file = new File("word.owl");
OWLDataFactory dataFactory = manager.getOWLDataFactory();
PrefixManager pm = new DefaultPrefixManager(base);
OWLClass Word = dataFactory.getOWLClass(":Word", pm);
OWLNamedIndividual Software = `dataFactory.getOWLNamedIndividual(":Software", pm);`
OWLClassAssertionAxiom classAssertion =
dataFactory.getOWLClassAssertionAxiom(Word, Software);
OWLOntology ontology = manager.createOntology(IRI.create(base));
manager.addAxiom(ontology, classAssertion);
manager.saveOntology(ontology, new SystemOutDocumentTarget());
OWLOntologyManager m = create();
OWLOntology o = m.loadOntologyFromOntologyDocument(iri);
assertNotNull(o);
OWLDataFactory factory = manager.getOWLDataFactory();
for (OWLClass cls : o.getClassesInSignature())
System.out.println(cls);
}
}
OWLOntology::getSubClassAxiomsForSuperClass(OWLClass)
将 return subclass 公理,其中指定的 class 是 superclass - subclass 中的在您的示例中,公理将是 Word
的子 class。
OWLOntology::getClassAssertionAxioms(OWLClass)
returns class 具有指定 class 的断言 - 这些公理中的个体将是 Word
.[=16 的实例=]
请注意,这些方法仅 return 在 ontology 中显式的数据;要查找可以推断的数据,您需要使用 OWLReasoner
。 OWLReasoner
的正确实现存在于 OWLAPI 之外,例如参见 Pellet、HermiT、FaCT++、Konclude、JFact(开源)和 StarDog(商业许可)。