Debian Codegraph @

reasoning/four-types-of-specification/leisure-sports-voucher.n3

raw
1 ### 1) VOCAB_TTL ###
2 @prefix ex: <https://example.org/leisure#> .
3 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
4 @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
5 @prefix foaf: <http://xmlns.com/foaf/0.1/> .
6 @prefix dct: <http://purl.org/dc/terms/> .
7 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
8
9 ex:Person a rdfs:Class ; rdfs:label "Person" ; rdfs:subClassOf foaf:Person .
10 ex:LeisureApplication a rdfs:Class ; rdfs:label "Leisure Voucher Application" .
11 ex:LeisureVoucher a rdfs:Class ; rdfs:label "Leisure Voucher" .
12
13 ex:SportsVoucher a skos:Concept ; skos:prefLabel "Community Sports Voucher" .
14
15 ex:hasApplicant a rdf:Property ; rdfs:domain ex:LeisureApplication ; rdfs:range ex:Person ; rdfs:label "has applicant" .
16 ex:appliesFor a rdf:Property ; rdfs:domain ex:LeisureApplication ; rdfs:range skos:Concept ; rdfs:label "applies for" .
17 ex:status a rdf:Property ; rdfs:domain ex:LeisureApplication ; rdfs:label "status" .
18 ex:eligible a rdf:Property ; rdfs:domain ex:LeisureApplication ; rdfs:label "eligible" .
19 ex:issuedVoucher a rdf:Property ; rdfs:domain ex:LeisureApplication ; rdfs:range ex:LeisureVoucher ; rdfs:label "issued voucher" .
20
21 ex:hasAge a rdf:Property ; rdfs:domain ex:Person ; rdfs:label "age" .
22 ex:commitsSessionsPerWeek a rdf:Property ; rdfs:domain ex:Person ; rdfs:label "committed sports sessions per week" .
23 ex:minutesPerSession a rdf:Property ; rdfs:domain ex:Person ; rdfs:label "minutes per session" .
24 ex:householdIncome a rdf:Property ; rdfs:domain ex:Person ; rdfs:label "household income" .
25
26 ex:hasEvidence a rdf:Property ; rdfs:domain ex:LeisureApplication ; rdfs:label "has evidence" .
27 ex:AgeEvidence a rdfs:Class ; rdfs:label "Age Evidence" .
28 ex:ActivityEvidence a rdfs:Class ; rdfs:label "Activity Evidence" .
29 ex:IncomeEvidence a rdfs:Class ; rdfs:label "Income Evidence" .
30
31 # Minimal statuses as SKOS concepts
32 ex:Submitted a skos:Concept ; skos:prefLabel "Submitted" .
33 ex:Approved a skos:Concept ; skos:prefLabel "Approved" .
34 ex:Rejected a skos:Concept ; skos:prefLabel "Rejected" .
35
36 ### 2) PROFILE_SHACL_TTL ###
37 @prefix sh: <http://www.w3.org/ns/shacl#> .
38 @prefix ex: <https://example.org/leisure#> .
39 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
40
41 ex:LeisureApplicationShape a sh:NodeShape ;
42 sh:targetClass ex:LeisureApplication ;
43 sh:property [
44 sh:path ex:hasApplicant ;
45 sh:minCount 1 ;
46 sh:nodeKind sh:IRI ;
47 ] ;
48 sh:property [
49 sh:path ex:appliesFor ;
50 sh:hasValue ex:SportsVoucher ;
51 sh:minCount 1 ;
52 ] ;
53 sh:property [
54 sh:path ex:status ;
55 sh:minCount 1 ;
56 ] ;
57 sh:property [
58 sh:path ex:hasEvidence ;
59 sh:minCount 3 ; # require at least 3 evidences (age, activity, income)
60 ] .
61
62 ex:PersonShape a sh:NodeShape ;
63 sh:targetClass ex:Person ;
64 sh:property [
65 sh:path ex:hasAge ;
66 sh:minCount 1 ;
67 sh:datatype xsd:integer ;
68 ] ;
69 sh:property [
70 sh:path ex:commitsSessionsPerWeek ;
71 sh:minCount 1 ;
72 sh:datatype xsd:integer ;
73 ] ;
74 sh:property [
75 sh:path ex:minutesPerSession ;
76 sh:minCount 1 ;
77 sh:datatype xsd:integer ;
78 ] ;
79 sh:property [
80 sh:path ex:householdIncome ;
81 sh:minCount 1 ;
82 sh:datatype xsd:integer ;
83 ] .
84
85 ### 3) RULES_N3 ###
86 # Interaction pattern: Community Sports Voucher
87 # States: Submitted -> (Eligible?) -> Approved/Rejected
88 # Preconditions: Application conforms to LeisureApplicationShape; Person conforms to PersonShape
89 # Abstract messages: submitApplication, validate, decide, notify
90
91 @prefix ex: <https://example.org/leisure#> .
92 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
93 @prefix math: <http://www.w3.org/2000/10/swap/math#> .
94
95 # R1: Eligibility — age∈[12,30), sessions≥3, weeklyMinutes≥150, income<30000
96 # weeklyMinutes = sessions * minutesPerSession
97 {
98 ?app ex:appliesFor ex:SportsVoucher .
99 ?app ex:hasApplicant ?p .
100 ?p ex:hasAge ?age .
101 ?p ex:commitsSessionsPerWeek ?s .
102 ?p ex:minutesPerSession ?m .
103 ?p ex:householdIncome ?inc .
104 "12"^^xsd:integer math:notGreaterThan ?age .
105 ?age math:lessThan "30"^^xsd:integer .
106 "3"^^xsd:integer math:notGreaterThan ?s .
107 (?s ?m) math:product ?weekMin .
108 ?weekMin math:notLessThan "150"^^xsd:integer .
109 ?inc math:lessThan "30000"^^xsd:integer .
110 }
111 =>
112 {
113 ?app ex:eligible true .
114 } .
115
116 # R2: Approve — eligible true AND status Submitted → status Approved + voucher issuance
117 {
118 ?app ex:eligible true .
119 ?app ex:status ex:Submitted .
120 }
121 =>
122 {
123 ?app ex:status ex:Approved .
124 _:v a ex:LeisureVoucher .
125 ?app ex:issuedVoucher _:v .
126 } .
127
128 # R3: Reject — eligible false AND status Submitted → status Rejected
129 {
130 ?app ex:eligible false .
131 ?app ex:status ex:Submitted .
132 }
133 =>
134 {
135 ?app ex:status ex:Rejected .
136 } .
137
138 ### DATA (Turtle from FACTS) ###
139 @prefix ex: <https://example.org/leisure#> .
140 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
141 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
142 @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
143
144 ex:APP-LEIS-01
145 ex:appliesFor ex:SportsVoucher ;
146 ex:hasApplicant ex:Liam ;
147 ex:hasEvidence "ActivityEvidence" ;
148 ex:hasEvidence "AgeEvidence" ;
149 ex:hasEvidence "IncomeEvidence" ;
150 ex:status ex:Submitted .
151
152 ex:Liam
153 ex:commitsSessionsPerWeek 4 ;
154 ex:hasAge 19 ;
155 ex:householdIncome 20000 ;
156 ex:minutesPerSession 45 .
157