Warm tip: This article is reproduced from serverfault.com, please click

How to specify a class property using foaf

发布于 2021-02-11 20:47:13

I'd like to create an ontology which describe interactions between users in a social network and which I want to import in GraphDB. I have decided to use the vocabulary foaf in order to exploit the resources already defined inside it. I'm creating the ontology's schema and I'm developing the User class as type of foaf:Person, each user has got a string name so I want to add this relation inside user class using foaf:name property.

My question is, since this isn't an instance of a user, what object shall I use in the class description beside the predicate foaf:name?

@prefix : <http://xmlns.com/swp/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/TR/rdf-schema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

# BASE INFORMATION

:User a foaf:Person ;
    rdfs:label "User" ;
    rdfs:comment "A person who has got an account" ;
    foaf:name ??? ;
    foaf:title :EducationalQualification .

EDIT I thought that maybe the right object could be xsd:string:

:User a foaf:Person ;
    rdfs:label "User" ;
    rdfs:comment "A person who has got an account" ;
    foaf:name xsd:string ;
    foaf:title :EducationalQualification .
Questioner
M.Morris
Viewed
2
IS4 2021-02-12 22:35:51

I recommend studying the RDF Schema for instructions how to write your own basic vocabulary. You don't need to use any of that, but it is certainly useful for anyone who would like to use or understand your custom vocabulary.

Let's think about the problem domain now. You have users with names and titles. You want your names to be plain strings and your titles to be instances of :EducationalQualification. Let's try to express that, not using but extending FOAF.

First, you want to express that every :User is a foaf:Person. Writing :User a foaf:Person is not correct because it means that a resource identified by :User is a particular instance of a person, which it isn't – it's a class!

:User a rdfs:Class ;
  rdfs:subClassOf foaf:Person .

This is a good definition of your new class – from this someone can infer that users in your dataset can be treated as FOAF persons.

For names of people, I'd argue that rdf:langString (i.e. language-tagged strings) is a better class for names of people, especially if you go with foaf:name, so I will use that (but there is no difference in the usage anyway).

:name a rdf:Property ;
  rdfs:domain :User ;
  rdfs:range rdf:langString ;
  rdfs:subPropertyOf foaf:name .

This is again pretty simple: :name is a property that can (must) be attached to a :User and has (must have) a value of rdf:langString. If any two resources are linked via this property, it implies that they are linked with foaf:name as well (due to the sub-property).

Same for titles:

:title a rdf:Property ;
  rdfs:domain :User ;
  rdfs:range :EducationalQualification ;
  rdfs:subPropertyOf foaf:title .

Your original intention was to express that anything attached via foaf:title to a :User is :EducationalQualification. This can be expressed as well, but you need something stronger than RDFS, like OWL:

@prefix owl: <http://www.w3.org/2002/07/owl#> .

[ a owl:Restriction ;
  owl:onProperty [ owl:inverseOf foaf:title ] ;
  owl:someValuesFrom :User
] rdfs:subClassOf :EducationalQualification .

I don't think this is a good idea however, since it modifies foaf:title in a way that is not expected. It's better to using a specialized property if you have a specialized meaning in mind.