Debian Codegraph @

reasoning/four-types-of-specification/bikepass-youth-discount.n3

raw
1 ### 1) VOCAB_TTL ###
2 @prefix ex: <https://example.org/bikepass#> .
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:BikePassApplication a rdfs:Class ; rdfs:label "BikePass Discount Application" .
11 ex:BikePass a rdfs:Class ; rdfs:label "BikePass" .
12
13 ex:YouthDiscount a skos:Concept ; skos:prefLabel "BikePass Youth Discount" .
14
15 ex:hasApplicant a rdf:Property ; rdfs:domain ex:BikePassApplication ; rdfs:range ex:Person ; rdfs:label "has applicant" .
16 ex:appliesFor a rdf:Property ; rdfs:domain ex:BikePassApplication ; rdfs:range skos:Concept ; rdfs:label "applies for" .
17 ex:status a rdf:Property ; rdfs:domain ex:BikePassApplication ; rdfs:label "status" .
18 ex:eligible a rdf:Property ; rdfs:domain ex:BikePassApplication ; rdfs:label "eligible" .
19 ex:issuedPass a rdf:Property ; rdfs:domain ex:BikePassApplication ; rdfs:range ex:BikePass ; rdfs:label "issued pass" .
20 ex:approvedPrice a rdf:Property ; rdfs:domain ex:BikePassApplication ; rdfs:label "approved price (monthly)" .
21
22 ex:hasAge a rdf:Property ; rdfs:domain ex:Person ; rdfs:label "age" .
23 ex:tripsPerWeek a rdf:Property ; rdfs:domain ex:Person ; rdfs:label "committed trips per week" .
24
25 ex:baseMonthlyPrice a rdf:Property ; rdfs:domain ex:BikePassApplication ; rdfs:label "base monthly price" .
26
27 ex:hasEvidence a rdf:Property ; rdfs:domain ex:BikePassApplication ; rdfs:label "has evidence" .
28 ex:AgeEvidence a rdfs:Class ; rdfs:label "Age Evidence" .
29 ex:TripsEvidence a rdfs:Class ; rdfs:label "Trips Evidence" .
30 ex:PriceEvidence a rdfs:Class ; rdfs:label "Price Evidence" .
31
32 # Minimal statuses as SKOS concepts
33 ex:Submitted a skos:Concept ; skos:prefLabel "Submitted" .
34 ex:Approved a skos:Concept ; skos:prefLabel "Approved" .
35 ex:Rejected a skos:Concept ; skos:prefLabel "Rejected" .
36
37 ### 2) PROFILE_SHACL_TTL ###
38 @prefix sh: <http://www.w3.org/ns/shacl#> .
39 @prefix ex: <https://example.org/bikepass#> .
40 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
41
42 ex:BikePassApplicationShape a sh:NodeShape ;
43 sh:targetClass ex:BikePassApplication ;
44 sh:property [
45 sh:path ex:hasApplicant ;
46 sh:minCount 1 ;
47 sh:nodeKind sh:IRI ;
48 ] ;
49 sh:property [
50 sh:path ex:appliesFor ;
51 sh:hasValue ex:YouthDiscount ;
52 sh:minCount 1 ;
53 ] ;
54 sh:property [
55 sh:path ex:baseMonthlyPrice ;
56 sh:minCount 1 ;
57 sh:datatype xsd:integer ;
58 ] ;
59 sh:property [
60 sh:path ex:status ;
61 sh:minCount 1 ;
62 ] ;
63 sh:property [
64 sh:path ex:hasEvidence ;
65 sh:minCount 3 ; # require at least 3 evidences (age, trips, price)
66 ] .
67
68 ex:PersonShape a sh:NodeShape ;
69 sh:targetClass ex:Person ;
70 sh:property [
71 sh:path ex:hasAge ;
72 sh:minCount 1 ;
73 sh:datatype xsd:integer ;
74 ] ;
75 sh:property [
76 sh:path ex:tripsPerWeek ;
77 sh:minCount 1 ;
78 sh:datatype xsd:integer ;
79 ] .
80
81 ### 3) RULES_N3 ###
82 # Interaction pattern: BikePass Youth Discount
83 # States: Submitted -> (Eligible?) -> Approved/Rejected
84 # Preconditions: Application conforms to BikePassApplicationShape; Person conforms to PersonShape
85 # Abstract messages: submitApplication, validate, decide, notify
86
87 @prefix ex: <https://example.org/bikepass#> .
88 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
89 @prefix math: <http://www.w3.org/2000/10/swap/math#> .
90
91 # R1: Eligibility — age∈[12,26) and tripsPerWeek ≥ 3
92 {
93 ?app ex:appliesFor ex:YouthDiscount .
94 ?app ex:hasApplicant ?p .
95 ?p ex:hasAge ?age .
96 ?p ex:tripsPerWeek ?t .
97 "12"^^xsd:integer math:notGreaterThan ?age .
98 ?age math:lessThan "26"^^xsd:integer .
99 "3"^^xsd:integer math:notGreaterThan ?t .
100 }
101 =>
102 {
103 ?app ex:eligible true .
104 } .
105
106 # R2a: Approve & compute price for age < 18 → 60% discount
107 # price = base - (base * 60 / 100)
108 {
109 ?app ex:eligible true .
110 ?app ex:status ex:Submitted .
111 ?app ex:baseMonthlyPrice ?bp .
112 ?app ex:hasApplicant ?p .
113 ?p ex:hasAge ?age .
114 ?age math:lessThan "18"^^xsd:integer .
115 (?bp "60"^^xsd:integer) math:product ?tmp .
116 (?tmp "100"^^xsd:integer) math:quotient ?discAmt .
117 (?bp ?discAmt) math:difference ?price .
118 }
119 =>
120 {
121 ?app ex:status ex:Approved .
122 ?app ex:approvedPrice ?price .
123 _:pass a ex:BikePass .
124 ?app ex:issuedPass _:pass .
125 } .
126
127 # R2b: Approve & compute price for 18 ≤ age < 26 → 40% discount
128 # price = base - (base * 40 / 100)
129 {
130 ?app ex:eligible true .
131 ?app ex:status ex:Submitted .
132 ?app ex:baseMonthlyPrice ?bp .
133 ?app ex:hasApplicant ?p .
134 ?p ex:hasAge ?age .
135 "18"^^xsd:integer math:notGreaterThan ?age .
136 ?age math:lessThan "26"^^xsd:integer .
137 (?bp "40"^^xsd:integer) math:product ?tmp2 .
138 (?tmp2 "100"^^xsd:integer) math:quotient ?discAmt2 .
139 (?bp ?discAmt2) math:difference ?price2 .
140 }
141 =>
142 {
143 ?app ex:status ex:Approved .
144 ?app ex:approvedPrice ?price2 .
145 _:pass a ex:BikePass .
146 ?app ex:issuedPass _:pass .
147 } .
148
149 # R3: Reject — eligible false AND status Submitted → status Rejected
150 {
151 ?app ex:eligible false .
152 ?app ex:status ex:Submitted .
153 }
154 =>
155 {
156 ?app ex:status ex:Rejected .
157 } .
158
159 ### DATA (Turtle from FACTS) ###
160 @prefix ex: <https://example.org/bikepass#> .
161 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
162 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
163 @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
164
165 ex:APP-BP-01
166 ex:appliesFor ex:YouthDiscount ;
167 ex:baseMonthlyPrice 30 ;
168 ex:hasApplicant ex:Zoe ;
169 ex:hasEvidence "AgeEvidence" ;
170 ex:hasEvidence "PriceEvidence" ;
171 ex:hasEvidence "TripsEvidence" ;
172 ex:status ex:Submitted .
173
174 ex:Zoe
175 ex:hasAge 17 ;
176 ex:tripsPerWeek 5 .
177