How to include multiple URI's for same property in Jena Model?

你离开我真会死。 提交于 2020-01-06 05:30:06

问题


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

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


回答1:


Multiple RDF types

In computational ontologies, an instance can have multiple classes (types).

Classification

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.

Ontologies

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.

Examples

  • 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")

Efficient Way to Create Multiple Type Statements

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

Working Example

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

}


来源:https://stackoverflow.com/questions/52623064/how-to-include-multiple-uris-for-same-property-in-jena-model

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!