我应该子类化rdf:Statement来具体化吗?



我想做一个具体化的'关于一个声明的声明',假设我有userX memberOf groupY,并想对它做一个声明(比如,他们在5月11日加入)。

所以,我有这样的东西:

statementX a rdf:statement
statementX subject userX
statementX predicate memberOf
statementX object groupY
statementX since "2022-05-11T11:32:52"^^xsd:dateTime

我的问题是,是否值得子类化rdf:statement?先说UserGroupStatement rdf:subClassOf rdf:statement,再说statementX a UserGroupStatement

这有意义吗?这是人们做的事情吗?或者人们只是使用rdf:statement,或者创建自己的加入类?它的利弊是什么?

在我看来,它至少允许我对某种类型的语句具有某些属性进行建模,例如,UserGroupStatement具有"since"属性(域UserGroupStatement,范围xsd:datetime)。但是我可以看到,它不能帮助我指定任何其他东西,因为UserGroupStatement的主语/谓语/宾语仍然可以是任何Resource。或者出于建模目的,我是否应该创建一个新的类似语句的链接对象,而完全忘记rdf:statement ?

如果它适合您的用例,您可以子类化rdf:Statement,但要注意大写的S,因为uri是区分大小写的。

您可以使用OWL进一步限制该子类上的属性,但这只能帮助您进行推理。我假设您想要验证您的数据,对于这种用例,acl或ShEx更适合。

<标题>SHACL例子
@prefix : <http://example.org/>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix sh: <http://www.w3.org/ns/shacl#>.

# Ontology
:UserStatement rdfs:subClassOf rdf:Statement.
## Knowledge Base
:GroupY a :Group.
:UserX a :User; :memberOf :GroupY.
:AdminX a :Admin; :memberOf :GroupY.    
:CorrectStatement a :UserStatement;
rdf:subject :UserX;
rdf:predicate :memberOf;
rdf:object :GroupY;
:since "2022-05-11T11:32:52"^^xsd:dateTime.
:IncorrectStatement1 a :UserStatement;
rdf:subject :AdminX;
rdf:predicate :memberOf;
rdf:object :GroupY;
:since "2022-05-11T11:32:52"^^xsd:dateTime.
:IncorrectStatement2 a :UserStatement;
rdf:subject :UserX;
rdf:predicate :schmemberOf;
rdf:object :GroupY;
:since "2022-05-11T11:32:52"^^xsd:dateTime.
:InorrectStatement3 a :UserStatement;
rdf:subject :UserX;
rdf:predicate :memberOf;
rdf:object :GroupY.
# SHACL Shape
:UserStatementShape a sh:NodeShape;
sh:targetClass :UserStatement;  
sh:property                                       
[sh:path rdf:type; sh:hasValue :UserStatement; sh:minCount 1; sh:maxCount 1],
[sh:path rdf:subject; sh:class :User; sh:minCount 1; sh:maxCount 1],
[sh:path rdf:predicate; sh:hasValue :memberOf; sh:minCount 1; sh:maxCount 1],
[sh:path rdf:object; sh:class :Group; sh:minCount 1; sh:maxCount 1],
[sh:path :since; sh:nodeKind sh:Literal; sh:datatype xsd:dateTime; sh:minCount 1; sh:maxCount 1];
sh:closed true.

输出将示例保存为test.ttl,安装pySHACL并运行pyshacl test.ttl,您将得到以下结果:

$ pyshacl test.ttl
Validation Report
Conforms: False
Results (3):
Constraint Violation in MinCountConstraintComponent (http://www.w3.org/ns/shacl#MinCountConstraintComponent):
Severity: sh:Violation
Source Shape: [ sh:datatype xsd:dateTime ; sh:maxCount Literal("1", datatype=xsd:integer) ; sh:minCount Literal("1", datatype=xsd:integer) ; sh:nodeKind sh:Literal ; sh:path :since ]
Focus Node: :InorrectStatement3
Result Path: :since
Message: Less than 1 values on :InorrectStatement3->:since
Constraint Violation in HasValueConstraintComponent (http://www.w3.org/ns/shacl#HasValueConstraintComponent):
Severity: sh:Violation
Source Shape: [ sh:hasValue :memberOf ; sh:maxCount Literal("1", datatype=xsd:integer) ; sh:minCount Literal("1", datatype=xsd:integer) ; sh:path rdf:predicate ]
Focus Node: :IncorrectStatement2
Result Path: rdf:predicate
Message: Node :IncorrectStatement2->rdf:predicate does not contain a value in the set: [':memberOf']
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
Severity: sh:Violation
Source Shape: [ sh:class :User ; sh:maxCount Literal("1", datatype=xsd:integer) ; sh:minCount Literal("1", datatype=xsd:integer) ; sh:path rdf:subject ]
Focus Node: :IncorrectStatement1
Value Node: :AdminX
Result Path: rdf:subject
Message: Value does not have class :User

相关内容

最新更新