2

我基本上在 .txt 的新行中有一个包含数千个名称的大文件。我正在使用 Protege 构建我的本体,我想要一种更快的方法将这些名称作为个体插入到我的本体中的“人”概念中。无论如何,这可以使用 Protege 或 OWL API 来完成,因为单击 protege 中的添加按钮并键入/复制每个名称,然后将其添加到“人”概念中需要一些时间。

感谢您的任何建议。

4

1 回答 1

2

如果使用 OWL API,文档中提供的示例中有一个如何做到这一点的示例:

public void shouldAddClassAssertion() throws OWLOntologyCreationException,
        OWLOntologyStorageException {
    // For more information on classes and instances see the OWL 2 Primer
    // http://www.w3.org/TR/2009/REC-owl2-primer-20091027/#Classes_and_Instances
    // In order to say that an individual is an instance of a class (in an
    // ontology), we can add a ClassAssertion to the ontology. For example,
    // suppose we wanted to specify that :Mary is an instance of the class
    // :Person. First we need to obtain the individual :Mary and the class
    // :Person Create an ontology manager to work with
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLDataFactory dataFactory = manager.getOWLDataFactory();
    // The IRIs used here are taken from the OWL 2 Primer
    String base = "http://example.com/owl/families/";
    PrefixManager pm = new DefaultPrefixManager(base);
    // Get the reference to the :Person class (the full IRI will be
    // <http://example.com/owl/families/Person>)
    OWLClass person = dataFactory.getOWLClass(":Person", pm);
    // Get the reference to the :Mary class (the full IRI will be
    // <http://example.com/owl/families/Mary>)
    OWLNamedIndividual mary = dataFactory
            .getOWLNamedIndividual(":Mary", pm);
    // Now create a ClassAssertion to specify that :Mary is an instance of
    // :Person
    OWLClassAssertionAxiom classAssertion = dataFactory
            .getOWLClassAssertionAxiom(person, mary);
    // We need to add the class assertion to the ontology that we want
    // specify that :Mary is a :Person
    OWLOntology ontology = manager.createOntology(IRI.create(base));
    // Add the class assertion
    manager.addAxiom(ontology, classAssertion);
    // Dump the ontology to stdout
    manager.saveOntology(ontology, new StreamDocumentTarget(
            new ByteArrayOutputStream()));
}
于 2014-03-26T07:17:42.623 回答