如何在耶拿模型中为同一属性包含多个URI? [英] How to include multiple URI's for same property in Jena Model?

查看:128
本文介绍了如何在耶拿模型中为同一属性包含多个URI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种更有效的方法来创建以下内容:

Hi is there a more efficient way to create the following:

.addProperty(RDF.type, locah+"/Repository")
.addProperty(RDF.type, DCTerms.Agent)
.addProperty(RDF.type, FOAF.Agent);

拥有具有多个RDF.types的资源有什么优势?

What are the advantages of having a resource with multiple RDF.types?

推荐答案

多种RDF类型

在计算本体中,一个实例可以具有多个(类型).

分类

一开始这可能会造成混淆,因为例如医学上的分类这是不同的.在那里,您必须为实例选择一个完全相同的类".因此,医生必须只选择一个ICD 10代码进行初步诊断.

This can be confusing at first, because for example in medical classification this is different. There you have to choose exactly one "class" for an instance. So a doctor has to pick exactly one ICD 10 code for the primary diagnosis.

您可以想象这样的分类方案,例如厨房中的餐具抽屉,您必须确定是汤匙,叉子还是刀子,然后将其放在适当的隔间中.没有可以同时放在两个隔间中的汤匙".

You can imagine such classification schemes like a cutlery drawer in a kitchen where you have to decide whether something is a spoon, fork or knive and then put it in the appropriate compartment. There is no "spoonfork" that you can place in two compartments at the same time.

但是,当罕见的异常发生在某些地方确实无法容纳时,就会出现问题.为了解决这个问题,您需要剩余"类,您可以在其中放置这些异常.

However there are problems when the rare exception occurs where something really does not fit anywhere. To account for this, you need "left over" classes, where you can put those exceptions.

本体

现在本体的语义有所不同: class 只是其成员的集合(无论这些成员是否被明确指定).这意味着具有多个类(类型)的资源仅表示它属于多个集合.

Now the semantics of ontologies are different: A class is just a set of its members (whether those members are specified explicitly or not). This means, a resource having multiple classes (types) just means it belongs to multiple sets.

示例

  • 数字2属于素数集,偶数集,整数集正数集
  • John Doe 是一个男人, a 丈夫, a 父亲. (是"的意思是属于该集合")
  • the number 2 belongs to the set of prime numbers, the set of even numbers, the set of whole numbers and the set of positive numbers
  • John Doe is a man, a husband and a father. ("is a" means "belongs to the set of")

Jena 3.12.0不包含更简洁地添加多个属性的方法.但是,正如@AKSW建议的那样,如果您有大量的语句(可能不值得3条),则可以使用循环,例如:

Jena 3.12.0 does not contain a method to add multiple properties more concisely. However, as @AKSW suggested, if you have a large number of statements (3 would probably not be worth it), you can use a loop, such as:

types.forEach(type->{resource.addProperty(RDF.type, type);});

工作示例

import java.util.List;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.OWL;
import org.apache.jena.vocabulary.RDF;
import org.apache.jena.vocabulary.RDFS;
import org.apache.jena.vocabulary.SKOS;

public class Test
{

    public static void main(String[] args)
    {
        Model model = ModelFactory.createDefaultModel();
        Resource resource = model.createResource("test");
        List<Resource> types = List.of(OWL.Class, RDFS.Class,SKOS.Concept);

        types.forEach(type->{resource.addProperty(RDF.type, type);});       
    }

}

这篇关于如何在耶拿模型中为同一属性包含多个URI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆