Debian Codegraph @

reasoning/four-types-of-specification/agri-drought-relief.n3

raw
1 ### 1) VOCAB_TTL ###
2 @prefix ex: <https://example.org/agri#> .
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:Farm a rdfs:Class ; rdfs:label "Farm" .
10 ex:DroughtApplication a rdfs:Class ; rdfs:label "Drought Relief Application" .
11 ex:ReliefPayment a rdfs:Class ; rdfs:label "Relief Payment" .
12
13 ex:DroughtReliefGrant a skos:Concept ; skos:prefLabel "Drought Relief Grant" .
14
15 ex:hasApplicant a rdf:Property ; rdfs:domain ex:DroughtApplication ; rdfs:range ex:Farm ; rdfs:label "has applicant" .
16 ex:appliesFor a rdf:Property ; rdfs:domain ex:DroughtApplication ; rdfs:range skos:Concept ; rdfs:label "applies for" .
17 ex:status a rdf:Property ; rdfs:domain ex:DroughtApplication ; rdfs:label "status" .
18 ex:eligible a rdf:Property ; rdfs:domain ex:DroughtApplication ; rdfs:label "eligible" .
19 ex:issuedPayment a rdf:Property ; rdfs:domain ex:DroughtApplication ; rdfs:range ex:ReliefPayment ; rdfs:label "issued payment" .
20
21 ex:totalArea a rdf:Property ; rdfs:domain ex:Farm ; rdfs:label "total area (ha)" .
22 ex:rainfallLast30d a rdf:Property ; rdfs:domain ex:Farm ; rdfs:label "rainfall last 30 days (mm)" .
23 ex:baselineYield a rdf:Property ; rdfs:domain ex:Farm ; rdfs:label "baseline yield (kg/ha)" .
24 ex:currentYield a rdf:Property ; rdfs:domain ex:Farm ; rdfs:label "current yield (kg/ha)" .
25
26 ex:hasEvidence a rdf:Property ; rdfs:domain ex:DroughtApplication ; rdfs:label "has evidence" .
27 ex:AreaEvidence a rdfs:Class ; rdfs:label "Area Evidence" .
28 ex:RainfallEvidence a rdfs:Class ; rdfs:label "Rainfall Evidence" .
29 ex:YieldEvidence a rdfs:Class ; rdfs:label "Yield 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/agri#> .
39 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
40
41 ex:DroughtApplicationShape a sh:NodeShape ;
42 sh:targetClass ex:DroughtApplication ;
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:DroughtReliefGrant ;
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 (area, rainfall, yield)
60 ] .
61
62 ex:FarmShape a sh:NodeShape ;
63 sh:targetClass ex:Farm ;
64 sh:property [
65 sh:path ex:totalArea ;
66 sh:minCount 1 ;
67 sh:datatype xsd:integer ;
68 ] ;
69 sh:property [
70 sh:path ex:rainfallLast30d ;
71 sh:minCount 1 ;
72 sh:datatype xsd:integer ;
73 ] ;
74 sh:property [
75 sh:path ex:baselineYield ;
76 sh:minCount 1 ;
77 sh:datatype xsd:integer ;
78 ] ;
79 sh:property [
80 sh:path ex:currentYield ;
81 sh:minCount 1 ;
82 sh:datatype xsd:integer ;
83 ] .
84
85 ### 3) RULES_N3 ###
86 # Interaction pattern: Drought Relief Grant
87 # States: Submitted -> (Eligible?) -> Approved/Rejected
88 # Preconditions: Application conforms to DroughtApplicationShape; Farm conforms to FarmShape
89 # Abstract messages: submitApplication, validate, decide, notify
90
91 @prefix ex: <https://example.org/agri#> .
92 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
93 @prefix math: <http://www.w3.org/2000/10/swap/math#> .
94
95 # R1: Eligibility — area ≥ 5, rainfallLast30d < 20, yield drop ≥ 30
96 # drop = baselineYield - currentYield
97 {
98 ?app ex:appliesFor ex:DroughtReliefGrant .
99 ?app ex:hasApplicant ?farm .
100 ?farm ex:totalArea ?area .
101 ?farm ex:rainfallLast30d ?rain .
102 ?farm ex:baselineYield ?by .
103 ?farm ex:currentYield ?cy .
104 (?by ?cy) math:difference ?drop .
105 "5"^^xsd:integer math:notGreaterThan ?area .
106 ?rain math:lessThan "20"^^xsd:integer .
107 ?drop math:notLessThan "30"^^xsd:integer .
108 }
109 =>
110 {
111 ?app ex:eligible true .
112 } .
113
114 # R2: Approve — eligible true AND status Submitted → status Approved + payment issuance
115 {
116 ?app ex:eligible true .
117 ?app ex:status ex:Submitted .
118 }
119 =>
120 {
121 ?app ex:status ex:Approved .
122 _:pay a ex:ReliefPayment .
123 ?app ex:issuedPayment _:pay .
124 } .
125
126 # R3: Reject — eligible false AND status Submitted → status Rejected
127 {
128 ?app ex:eligible false .
129 ?app ex:status ex:Submitted .
130 }
131 =>
132 {
133 ?app ex:status ex:Rejected .
134 } .
135
136 ### DATA (Turtle from FACTS) ###
137 @prefix ex: <https://example.org/agri#> .
138 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
139 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
140 @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
141
142 ex:APP-DR-01
143 ex:appliesFor ex:DroughtReliefGrant ;
144 ex:hasApplicant ex:FarmAlpha ;
145 ex:hasEvidence "AreaEvidence" ;
146 ex:hasEvidence "RainfallEvidence" ;
147 ex:hasEvidence "YieldEvidence" ;
148 ex:status ex:Submitted .
149
150 ex:FarmAlpha
151 ex:baselineYield 100 ;
152 ex:currentYield 60 ;
153 ex:rainfallLast30d 12 ;
154 ex:totalArea 8 .
155