- From: Joy lix <joylix4112@outlook.com>
- Date: Mon, 19 Jul 2021 00:02:36 +0000
- To: Irene Polikoff <irene@topquadrant.com>
- CC: "public-shacl@w3.org" <public-shacl@w3.org>
- Message-ID: <OS0PR01MB5570C7071B4F5EF40FE438CBDBE19@OS0PR01MB5570.jpnprd01.prod.outlook.com>
Yes, Irene, My practical application might be better handled with sh:rule, which would look like this: The students have examination results for 10 courses, The corresponding mark for each course are as follows: [ 90 -100 ] --> A [ 80 - 89 ] --> B [ 60 - 79 ] --> C else [ 0 - 59] --> D if a student get 7A+ and no D, then he or she is considered "outstanding" else if 5A+ and no D, then "good" else if no D, then "passed" else "failed" So my input data is the scores of N students in each subject (percentage scale) , the output is a result sorted by label, it is essentially a question about classification rules. I think sh:count would be used here, but I'm not familiar with this yet. Do you think it is appropriate to use SHACL or SWRL to express these rules? Kind regards. Joylix ________________________________ 发件人: Irene Polikoff <irene@topquadrant.com> 发送时间: 2021年7月19日 0:56 收件人: Joy lix <joylix4112@outlook.com> 抄送: public-shacl@w3.org <public-shacl@w3.org> 主题: Re: how to use sh:if Rules are used to add triples - implementing inference. Your example asked about checking data validity. If you want to classify people based on their height, then, yes, a rule would be the way to go. I don’t think you need else if. You would simply specify a class for each range of heights. Here is an example of a rule: ex:Rectangle a rdfs:Class, sh:NodeShape ; rdfs:label "Rectangle" ; sh:property [ sh:path ex:height ; sh:datatype xsd:integer ; sh:maxCount 1 ; sh:minCount 1 ; sh:name "height" ; ] ; sh:property [ sh:path ex:width ; sh:datatype xsd:integer ; sh:maxCount 1 ; sh:minCount 1 ; sh:name "width" ; ] ; sh:rule [ a sh:TripleRule ; sh:subject sh:this ; sh:predicate rdf:type ; sh:object ex:Square ; sh:condition [ sh:property [ sh:path ex:width ; sh:equals ex:height ; ] ; ] ; ] . This rule infers that a rectangle with the equal width and height is a square. You can do something similar attaching rules to :Person class and specifying conditions that will infer the :ShortPerson, :TallPerson :MediumPerson types accordingly. On Jul 18, 2021, at 11:30 AM, Joy lix <joylix4112@outlook.com<mailto:joylix4112@outlook.com>> wrote: Hi, Irene, Thank you very much for your reply and detailed code. It's been very helpful to me. I've also been told to use sh:rule to implement this, I need to take a closer look at the examples in the SHACL test suite. But with respect to sh:if, it would be nice to have a more detailed example in the test set ,In the SHACL-AF specification, there are sh:if, sh:then, sh:else, So what about multiple branches like elseif? Is it necessary to add sh:elseif? Kind regards, Joylix ________________________________ 发件人: Irene Polikoff <irene@topquadrant.com<mailto:irene@topquadrant.com>> 发送时间: 2021年7月17日 7:39 收件人: Joy lix <joylix4112@outlook.com<mailto:joylix4112@outlook.com>> 抄送: public-shacl@w3.org<mailto:public-shacl@w3.org> <public-shacl@w3.org<mailto:public-shacl@w3.org>> 主题: Re: how to use sh:if Sorry was too quick to respond and made a couple of typos in the first option. Use the following: :TallPerson a owl:Class, sh:NodeShape; sh:property [sh:path :hasHeight; sh:datatype xsd:integer; sh:minInclusive 185;] ... . Or :TallPerson a owl:Class, sh:NodeShape; sh:property :TallPerson-height; ... . Together With :TallPerson-height a sh:PropertyShape; sh:path :hasHeight; sh:datatype xsd:integer; sh:minInclusive 185; . Or just the property shape with target :TallPerson-height a sh:PropertyShape; Sh:target :TallPerson sh:path :hasHeight; sh:datatype xsd:integer; sh:minInclusive 185; . On Jul 16, 2021, at 1:56 PM, Irene Polikoff <irene@topquadrant.com<mailto:irene@topquadrant.com>> wrote: You do not need to use sh:if for this example. Simply do: :ShortPerson a owl:Class, sh:NodeShape; sh:path :hasHeight; sh:datatype xsd:integer; sh:maxInclusive 155 ; . :MediumPerson a owl:Class, sh:NodeShape; sh:path :hasHeight; sh:minExclusive 155; sh:datatype xsd:integer; sh:maxExclusive 185; . :TallPerson a owl:Class, sh:NodeShape; sh:path :hasHeight; sh:datatype xsd:integer; sh:minInclusive 185; . This will give you a violation message for Bob. You can also make these property shapes within the node shape if you need to make some statements about other properties of these class members e.g. :TallPerson a owl:Class, sh:NodeShape; sh:property [sh:path :hasHeight; sh:datatype xsd:integer; sh:minInclusive 185;] ... . On Jul 16, 2021, at 3:28 AM, Joy lix <joylix4112@outlook.com<mailto:joylix4112@outlook.com>> wrote: Dear all: I'm not very clear about the use of sh:if, The examples given in the SHACL-AF specification are relatively simple so I don't understand them very well. Consider the following example: if someone.height>180 then someone is tallPerson else if someone.height>155 then someone is mediumPerson else someone is shortPerson How do I present it use sh:if in a shacl shape file? Can the SHACL validation engine give an violation message for the following data files? :bob a :Person ; :hasHeight 185 ; a :shortPerson . Because Bob, by definition, should be a tallPerson. Thank you for your help! Kind regards, Joylix
Received on Monday, 19 July 2021 00:02:55 UTC