将个人从文本文件导入OWL本体(Protege)

时间:2014-03-25 12:00:26

标签: owl protege owl-api

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

感谢您的任何建议。

1 个答案:

答案 0 :(得分:1)

如果使用OWL API,有一个如何执行此操作的示例in the examples provided in the documentation

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()));
}