Debian Codegraph @

reasoning/four-types-of-specification/student-grant-needbased.n3

raw
1 ### 1) VOCAB_TTL ###
2 @prefix ex: <https://example.org/edu#> .
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:Student a rdfs:Class ; rdfs:label "Student" ; rdfs:subClassOf foaf:Person .
10 ex:GrantApplication a rdfs:Class ; rdfs:label "Need-based Grant Application" .
11 ex:GrantPayment a rdfs:Class ; rdfs:label "Grant Payment" .
12
13 ex:NeedBasedGrant a skos:Concept ; skos:prefLabel "Need-based Student Grant" .
14
15 ex:hasApplicant a rdf:Property ; rdfs:domain ex:GrantApplication ; rdfs:range ex:Student ; rdfs:label "has applicant" .
16 ex:appliesFor a rdf:Property ; rdfs:domain ex:GrantApplication ; rdfs:range skos:Concept ; rdfs:label "applies for" .
17 ex:status a rdf:Property ; rdfs:domain ex:GrantApplication ; rdfs:label "status" .
18 ex:eligible a rdf:Property ; rdfs:domain ex:GrantApplication ; rdfs:label "eligible" .
19 ex:issuedPayment a rdf:Property ; rdfs:domain ex:GrantApplication ; rdfs:range ex:GrantPayment ; rdfs:label "issued payment" .
20
21 ex:householdIncome a rdf:Property ; rdfs:domain ex:Student ; rdfs:label "household income (annual)" .
22 ex:householdSize a rdf:Property ; rdfs:domain ex:Student ; rdfs:label "household size" .
23 ex:enrolledECTS a rdf:Property ; rdfs:domain ex:Student ; rdfs:label "enrolled ECTS credits" .
24 ex:tuitionAmount a rdf:Property ; rdfs:domain ex:Student ; rdfs:label "tuition amount" .
25
26 ex:hasEvidence a rdf:Property ; rdfs:domain ex:GrantApplication ; rdfs:label "has evidence" .
27 ex:IncomeEvidence a rdfs:Class ; rdfs:label "Income Evidence" .
28 ex:EnrollmentEvidence a rdfs:Class ; rdfs:label "Enrollment Evidence" .
29 ex:HouseholdEvidence a rdfs:Class ; rdfs:label "Household 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/edu#> .
39 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
40
41 ex:GrantApplicationShape a sh:NodeShape ;
42 sh:targetClass ex:GrantApplication ;
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:NeedBasedGrant ;
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 (income, household, enrollment)
60 ] .
61
62 ex:StudentShape a sh:NodeShape ;
63 sh:targetClass ex:Student ;
64 sh:property [
65 sh:path ex:householdIncome ;
66 sh:minCount 1 ;
67 sh:datatype xsd:integer ;
68 ] ;
69 sh:property [
70 sh:path ex:householdSize ;
71 sh:minCount 1 ;
72 sh:datatype xsd:integer ;
73 ] ;
74 sh:property [
75 sh:path ex:enrolledECTS ;
76 sh:minCount 1 ;
77 sh:datatype xsd:integer ;
78 ] ;
79 sh:property [
80 sh:path ex:tuitionAmount ;
81 sh:minCount 1 ;
82 sh:datatype xsd:integer ;
83 ] .
84
85 ### 3) RULES_N3 ###
86 # Interaction pattern: Need-based Student Grant
87 # States: Submitted -> (Eligible?) -> Approved/Rejected
88 # Preconditions: Application conforms to GrantApplicationShape; Student conforms to StudentShape
89 # Abstract messages: submitApplication, validate, decide, notify
90
91 @prefix ex: <https://example.org/edu#> .
92 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
93 @prefix math: <http://www.w3.org/2000/10/swap/math#> .
94
95 # R1: Eligibility — ECTS ≥ 30, perCapitaIncome ≤ 18000, tuition > 0
96 # perCapitaIncome = householdIncome / householdSize
97 {
98 ?app ex:appliesFor ex:NeedBasedGrant .
99 ?app ex:hasApplicant ?s .
100 ?s ex:enrolledECTS ?ects .
101 ?s ex:householdIncome ?inc .
102 ?s ex:householdSize ?hh .
103 ?s ex:tuitionAmount ?fee .
104 "30"^^xsd:integer math:notGreaterThan ?ects .
105 (?inc ?hh) math:quotient ?pc .
106 ?pc math:notGreaterThan "18000"^^xsd:integer .
107 ?fee math:greaterThan "0"^^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:GrantPayment .
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/edu#> .
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-GR-01
143 ex:appliesFor ex:NeedBasedGrant ;
144 ex:hasApplicant ex:Alice ;
145 ex:hasEvidence "EnrollmentEvidence" ;
146 ex:hasEvidence "HouseholdEvidence" ;
147 ex:hasEvidence "IncomeEvidence" ;
148 ex:status ex:Submitted .
149
150 ex:Alice
151 ex:enrolledECTS 60 ;
152 ex:householdIncome 36000 ;
153 ex:householdSize 3 ;
154 ex:tuitionAmount 1200 .
155