简体   繁体   English

在本体中插入多个人

[英]Insert multiple individuals in an ontology

I have created a simple ontology as shown below 我创建了一个简单的本体,如下所示 显示 with 4 classes, 1 objectTypeProperty and 2 DatatypeProperties. 具有4个类,1个objectTypeProperty和2个DatatypeProperties。 Now I want to create different individuals of same ontology. 现在,我想创建具有相同本体的不同个体。 By Individual, I mean a row of data shown in below table 所谓个人,是指下表中显示的一行数据 图 . I am trying to insert these individuals in the ontology with Jena directly. 我正在尝试将这些人直接与Jena插入本体中。

Till now, I have read the ontology in Jena, but how should I insert all these individuals. 到目前为止,我已经阅读了耶拿的本体论,但是我应该如何插入所有这些个体。 Do I need to use any type of loop or there is specific provision in Jena to insert repetitive information. 我是否需要使用任何类型的循环,还是Jena中有特定规定插入重复信息?

Note: I have asked similar type of question before at http://answers.semanticweb.com/questions/31641/use-an-ontology-to-store-csv-data-into-rdf-form . 注意:在http://answers.semanticweb.com/questions/31641/use-an-ontology-to-store-csv-data-into-rdf-form之前,我曾问过类似的问题。 I got the answer, but I want to know without using alignment ApI, can I do it purely using Jena. 我得到了答案,但是我想知道不使用对齐ApI,我可以仅使用耶拿(Jena)做吗?

Note: It seems that answers.semanticweb.com is down currently. 注意:看来Answers.semanticweb.com目前关闭。

It's probably easiest to insert multiple triples using SPARQL. 使用SPARQL插入多个三元组可能是最简单的 It'd essentially be 本质上是

prefix : <...>

insert data {
  :individual1 :place :p1 ; :date "110114" ; temperature 13 .
  :individual2 :place :p2 ; :date "120114" ; temperature 14 .
  :individual3 :place :p3 ; :date "130114" ; temperature 15 .
}

That's convenient if you already know the data you need to insert. 如果您已经知道需要插入的数据,那将很方便。 If you don't, or you're reading it from some other file, it might be easier to construct it through code. 如果不这样做,或者您正在从其他文件读取它,则通过代码构造它可能会更容易。

Since I can't post a comment, I'll do it here... 由于我无法发表评论,因此我将在这里进行...

Haroon, about the question at answers.semanticweb.com, I just followed with Alignment API because you said you needed to find the mappings between the CSV columns and the concepts. Haroon,关于answers.semanticweb.com上的问题,我只是使用Alignment API,因为您说过需要查找CSV列与概念之间的映射。 Using only Jena, you can't do it, because as far as I know, Jena doesn't give you any method or any kind of support for alignment or semantic annotations. 仅使用Jena是无法做到的,因为据我所知,Jena并没有为您提供任何方法或对对齐或语义注释的任何支持。 In fact, you can do this without Alignment API too, by using some other library like second string (one of my comments there), or any other that allows you to run string comparison (or structural or semantic...). 实际上,您也可以在不使用Alignment API的情况下执行此操作,方法是使用其他一些库,例如第二个字符串(我的注释之一),或任何其他可以运行字符串比较(或结构或语义...)的库。

If you don't need to calculate the alignment during runtime, I mean, if you have it set manually, you can use Jena to create the individuals. 如果您不需要在运行时计算路线,我的意思是,如果您手动设置了路线,则可以使用Jena创建个人。 Besides using SPARQL as pointed in the first answer, you could load the ontology into a Jena model and create the individuals using Jena methods. 除了如第一个答案中所述使用SPARQL之外,您还可以将本体加载到Jena模型中,并使用Jena方法创建个体。 If your get a OntClass, there's a method 'createIndividual' that allows you to create an Individual of that type. 如果获得OntClass,则可以使用方法'createIndividual'创建该类型的个人。

If your ontology is too large, you can get part of it, or just create the resources you need and append it to your model later. 如果您的本体太大,则可以获取其中一部分,或者只是创建所需的资源,然后将其追加到模型中。 You could do this by using Jena methods, or creating the SPARQL Update by code as Joshua Taylor said. 您可以使用Jena方法执行此操作,也可以按照Joshua Taylor所说通过代码创建SPARQL Update。

If you take the code example in the other answer and exclude Alignment API part, you have this Jena implementation (the official documentation is pretty easy to understand too). 如果您在另一个答案中使用代码示例,并排除Alignment API部分,则您具有此Jena实现(官方文档也很容易理解)。 Just keep the mapping at some storage (file, database, whatever) and use it to map the columns to concepts. 只需将映射保留在某些存储(文件,数据库等)中,然后使用它将列映射到概念。

Once you created the individuals in the Jena model, they will be part of your ontology, but only to the version you have in memory, so, you need to save it back to where it came from: some file or SPARQL endpoint with SPARQL Update support. 一旦在Jena模型中创建了个体,它们将成为您本体的一部分,但仅限于内存中的版本,因此,您需要将其保存回其来源:某些文件或具有SPARQL Update的SPARQL端点支持。

Hope this can enlighten you for the solution! 希望这能对您有所启发!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM