【问题标题】:Importing Individuals from a text file into an OWL Ontology (Protege)将文本文件中的个体导入 OWL 本体 (Protege)
【发布时间】:2014-05-03 06:14:15
【问题描述】:

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

感谢您的任何建议。

【问题讨论】:

  • 如果您愿意使用 OWLAPI,我希望这应该相当简单:遍历文件中的行,并为每一行为个人创建一个 IRI,然后制作它人的类型。有什么不适合你的原因吗?
  • @JoshuaTaylor 只是我缺乏 Java 知识。我基本上是这样读取文件的:code import java.io.BufferedReader;导入 java.io.FileReader;公共类 FileReading { public static void main(String [] args) { BufferedReader reader = new BufferedReader(new FileReader("/Users/Chris/Desktop/Players.txt"));字符串线=空; while ((line = reader.readLine()) != null) { System.out.println(line); } } } code 那我只要把print语句改成如下所示的ClassAssertion,就可以了。上面的代码会读取每一行并打印出每一行吗?
  • 请不要在cmets中放代码;这几乎是不可能阅读的。您的问题下方有一个“编辑”链接;请编辑问题并在此处添加代码。
  • 谢谢,我的第一个问题。我假设当它为我提供代码标签时,它会缩进等。我在上面发布的围绕 Ignazio 的 API 代码的循环混合让我可以解决这个问题。

标签: owl protege owl-api


【解决方案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()));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-03
    • 1970-01-01
    • 2013-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多