2014-03-25 37 views
1

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

感谢您的任何建议。

+0

如果你打开使用OWLAPI,我预计这应该是相当简单:通过迭代文件中的行,并为每个人创建一个个人IRI,并使其类型人。有没有不适合你的理由? –

+0

@JoshuaTaylor 只有我缺乏Java知识。我基本上是这样读取文件: 'code' import java.io.BufferedReader; import java.io.FileReader; 公共类FileReading { \t公共静态无效的主要(字串[] args) \t { \t \t的BufferedReader读者=新的BufferedReader(新的FileReader( “/用户/克里斯/桌面/ Players.txt”)); \t \t String line = null; ((line = reader.readLine())!= null){ \t \t while((line = reader.readLine())!= null)\t \t \t System.out.println(line); \t \t} \t}} 'code' 然后,我只需要打印语句更改如下所示的ClassAssertion,这是我能做到的。上面的代码是否会读取每行并将每行打印出来? – ChrisDLFC

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