就我而言,有SingleChoice(SC)和MultipleChoice(MC)问题。 SC具有一组答案(作为空白节点),这些答案必须分别包含一个“点”和一个“文本”属性。 MC有一组答案,其中必须包含一个“点”,一个“文本”和一个“ pointsNegative” 属性。以乌龟为例:
prefix ex ...
ex:SC a ex:SingleChoice .
ex:hasAnswers [
a ex:Answer .
ex:text "Answer 1" .
ex:points 5 ;
],[ ...sameAsAbove ], ... ;
ex:MC a ex:MultipleChoice .
ex:hasAnswers [
a ex:Answer .
ex:text "Answer 1" .
ex:points 5 .
ex:pointsNegative 1 ;
],[ ...sameAsAbove ], ... ;
我设法编写了shacl规则来验证ex:Answer类的所有实例。但是我无法通过以下规则验证这些实例(SC或MC)所属的种类:
ex:AnswerShape
a sh:NodeShape ;
sh:targetClass ex:Answer ;
sh:property [
a sh:PropertyShape ;
sh:path ex:Text ;
sh:minCount 1 ;
sh:maxCount 1 ;
sh:dataType xsd:string .
] .
例如如果我为ex:pointsNegative添加另一个PropertyShape,则该形状对于SC问题的所有答案都将失败(因为这些答案没有ex:pointsNegative)。我可以省略minCount限制,但是MC问题的答案可能没有ex:pointsNegative属性。 如何根据类链接(属于SC或MC)对ex:Answer类的实例执行不同的规则? Shacl甚至有可能吗?
答案 0 :(得分:0)
一个简单的解决方案是对答案使用不同的类,例如ex:SingleChoiceAnswer
和ex:MultipleChoiceAnswer
。这样,您可以为每种答案类型创建专用形状。
# answers
prefix ex ...
ex:SC a ex:SingleChoice .
ex:hasAnswers [
a ex:SingleChoiceAnswer .
ex:text "Answer 1" .
ex:points 5 ;
],[ ...sameAsAbove ], ... ;
ex:MC a ex:MultipleChoice .
ex:hasAnswers [
a ex:MultipleChoiceAnswer .
ex:text "Answer 1" .
ex:points 5 .
ex:pointsNegative 1 ;
],[ ...sameAsAbove ], ... ;
# shapes
ex:AnswerShape
a sh:NodeShape ;
sh:targetClass ex:SingleChoiceAnswer ;
sh:property [
a sh:PropertyShape ;
...
] .
ex:AnswerShape
a sh:NodeShape ;
sh:targetClass ex:MultipleChoiceAnswer ;
sh:property [
a sh:PropertyShape ;
...
] .
另一种不更改原始架构的解决方案是使用属性路径。这样,您可以定位选择类型并为其声明专用的属性形状。
# shapes
ex:SingleChoiceShape
a sh:NodeShape ;
sh:targetClass ex:SingleChoice ;
sh:property [
a sh:PropertyShape ;
sh:path (ex:hasAnswers ex:text)
...
] .
ex:MultipleChoice
a sh:NodeShape ;
sh:targetClass ex:MultipleChoice ;
sh:property [
a sh:PropertyShape ;
sh:path (ex:hasAnswer ex:pointsNegative)
...
] .