Skip to content

Commit

Permalink
Rule ML Example (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 1, 2020
1 parent eaa54fb commit 50fcdb1
Show file tree
Hide file tree
Showing 18 changed files with 3,235 additions and 274 deletions.
19 changes: 19 additions & 0 deletions .burgessrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"indent_size": "4",
"indent_char": " ",
"max_preserve_newlines": "5",
"preserve_newlines": true,
"keep_array_indentation": false,
"break_chained_methods": false,
"indent_scripts": "normal",
"brace_style": "collapse",
"space_before_conditional": true,
"unescape_strings": false,
"jslint_happy": false,
"end_with_newline": false,
"wrap_line_length": "0",
"indent_inner_html": false,
"comma_first": false,
"e4x": false,
"indent_empty_lines": false
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules

example/
175 changes: 175 additions & 0 deletions BurgessExample.ruleml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<!-- writing comment
Document (
Prefix(: <http://psoa.ruleml.org/usecases/PortClearance#>)
Prefix(math: <http://psoa.ruleml.org/lib/math#>)
Prefix(phys: <http://psoa.ruleml.org/lib/phys#>)
Import(<http://psoa.ruleml.org/lib/math.psoa>)
Import(<http://psoa.ruleml.org/lib/phys.psoa>)

Group (
% Port Clearance Knowledge Base
% Version: 2020-06-08
% Copy&paste-ready KB file in presentation syntax (PSOA RuleML/PS):
% http://psoa.ruleml.org/usecases/PortClearance/PortClearance.psoa
% To be complemented by KB file in serialization syntax (PSOA RuleML/XML):
% PSOA RuleML/PS can be directly used as a PSOATransRun input file:
% http://wiki.ruleml.org/index.php/PSOA_RuleML#PSOATransRun (Current Release)

% Main relational rule invokes inspection rule for certificate And safety

% Rule 2
Forall ?s (
:MayEnterDutchPortUnloaded(?s) :-
:CompliesInspectionRequirementsUnloaded(?s)
)
% Rule 3
Forall ?s (
:CompliesInspectionRequirementsUnloaded(?s) :-
And(:HasValidCertificate(?s)
:MeetsSafetyRequirementsUnloaded(?s))
)
% Object-relational certificate rule compares ship’s registry expiration with current date

% Rule 10
Forall ?s ?d ?e (
:HasValidCertificate(?s) :-
And(?s#:Ship(:registryExpirationDate->?e)
%
phys:currentDate(?d) % Uncomment for local date (deployment)
:currentDate(?d)
phys:lessThanDate(?d ?e))
)
% Object-relational size-switched safety rules check status (small) or status and hull (large)
% Rule 8 (includes disjunct of original Rule 6)
Forall ?s ?h (
:MeetsSafetyRequirementsUnloaded(?s) :-
?s#:Ship(:size->:small
:hold->?h#:ShipHold(:status->:clean))
)
% Rule 7 (includes disjunct of original Rule 6)
Forall ?s ?h (
:MeetsSafetyRequirementsUnloaded(?s) :-
?s#:Ship(:size->:large
:hold->?h#:ShipHold(:status->:clean
:hull->:double))
)
% Object-centered (except for math) rules to get qualitative size by thresholding length
% Rule 9
Forall ?s ?l (
?s#Top(:size->:small) :-
And(?s#:Ship(:totalLength->?l)
math:lessThan(?l 80))
)

% Rule 4
Forall ?s ?l (
?s#Top(:size->:large) :-
And(?s#:Ship(:totalLength->?l)
math:greaterEq(?l 80))
)
% Object-centered (except for math) rule to get qualitative status by thresholding residual
% Rule 1&5 (combines Rule 1 and Rule 5)
Forall ?h ?c (
?h#Top(:status->:clean) :-
And(?h#:ShipHold(:residualCargoMeasurement->?c)
math:lessEq(?c 0.5))
)
:currentDate(phys:date(2020 5 6)) % Uncomment for fixed date (reproducibility)



% Ship facts (No or Yes refer to answers for queries, as of 2020-05-06, with :ship1, :ship2, ... as arguments)
% Facts covering all cases with qualitative slot-filler distinctions
% Explanatory comments for Yes answers focus on the most relevant slots
% Distinction for :registryExpirationDate
% Ship 1 - No, registry has expired



:ship1#:Ship(:registryExpirationDate->phys:date(2020 5 1)
:totalLength->20
:hold->:h1#:ShipHold(:residualCargoMeasurement->0.2
:hull->:single))

% Ship 2 - Yes, registry is valid
:ship2#:Ship(:registryExpirationDate->phys:date(2020 10 1)
:totalLength->20
:hold->:h2#:ShipHold(:residualCargoMeasurement->0.2
:hull->:single))

% Distinction for :residualCargoMeasurement
% Ship 3 - No, hold not clean
:ship3#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->70
:hold->:h3#:ShipHold(:residualCargoMeasurement->0.6
:hull->:single))

% Ship 4 - Yes, hold clean (qualitatively the same as for Ship 2)
:ship4#:Ship(:registryExpirationDate->phys:date(2020 1 1 )
:totalLength->70
:hold->:h4#:ShipHold(:residualCargoMeasurement->0.4
:hull->:single))

% Distinctions for :residualCargoMeasurement and :hull
% Ship 5 - No, hold not clean
:ship5#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->90
:hold->:h5#:ShipHold(:residualCargoMeasurement->0.6
:hull->:double))

% Ship 6 - No, size large yet hold single-hulled
:ship6#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->90
:hold->:h6#:ShipHold(:residualCargoMeasurement->0.4
:hull->:single))

% Ship 7 - Yes, hold clean and double-hulled
:ship7#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->90
:hold->:h7#:ShipHold(:residualCargoMeasurement->0.4
:hull->:double))

% Facts with multiple reasons for No or Yes
% Three reasons for No
% Ship 8 - No, registry expired, hold not clean, and size large yet hold single-hulled
:ship8#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->90
:hold->:h8#:ShipHold(:residualCargoMeasurement->0.9
:hull->:single))

% Two reasons for No
% Ship 9 - No, hold not clean and size large yet hold single-hulled
:ship9#:Ship(:registryExpirationDate->phys:date(2018 1 1)
:totalLength->90
:hold->:h9#:ShipHold(:residualCargoMeasurement->0.9
:hull->:single))

% Ship 10 - No, registry expired and size large yet hold single-hulled
:ship10#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->90
:hold->:h10#:ShipHold(:residualCargoMeasurement->0.2
:hull->:single))

% Ship 11 - No, registry expired and hold not clean
:ship11#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->90
:hold->:h11#:ShipHold(:residualCargoMeasurement->0.9
:hull->:double))

% Two reasons for Yes
% Ship 12 - Yes, size small nevertheless hold double-hulled
:ship12#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->60
:hold->:h12#:ShipHold(:residualCargoMeasurement->0.1
:hull->:double))

% Facts probing special cases
% Ship 13 - No, large ship must have some (a double) hull
:ship13#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->120
:hold->:h13#:ShipHold(:residualCargoMeasurement->0.2))
% Ship 14 - Yes, date, length, and measurement are at the threshold
:ship14#:Ship(:registryExpirationDate->phys:date(2020 5 7)
:totalLength->80
:hold->:h14#:ShipHold(:residualCargoMeasurement->0.5
:hull->:double))
175 changes: 175 additions & 0 deletions CustomsClearance.ruleml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<!-- writing comment
Document (
Prefix(: <http://psoa.ruleml.org/usecases/PortClearance#>)
Prefix(math: <http://psoa.ruleml.org/lib/math#>)
Prefix(phys: <http://psoa.ruleml.org/lib/phys#>)
Import(<http://psoa.ruleml.org/lib/math.psoa>)
Import(<http://psoa.ruleml.org/lib/phys.psoa>)

Group (
% Port Clearance Knowledge Base
% Version: 2020-06-08
% Copy&paste-ready KB file in presentation syntax (PSOA RuleML/PS):
% http://psoa.ruleml.org/usecases/PortClearance/PortClearance.psoa
% To be complemented by KB file in serialization syntax (PSOA RuleML/XML):
% PSOA RuleML/PS can be directly used as a PSOATransRun input file:
% http://wiki.ruleml.org/index.php/PSOA_RuleML#PSOATransRun (Current Release)

% Main relational rule invokes inspection rule for certificate And safety

% Rule 2
Forall ?s (
:MayEnterDutchPortUnloaded(?s) :-
:CompliesInspectionRequirementsUnloaded(?s)
)
% Rule 3
Forall ?s (
:CompliesInspectionRequirementsUnloaded(?s) :-
And(:HasValidCertificate(?s)
:MeetsSafetyRequirementsUnloaded(?s))
)
% Object-relational certificate rule compares ship’s registry expiration with current date

% Rule 10
Forall ?s ?d ?e (
:HasValidCertificate(?s) :-
And(?s#:Ship(:registryExpirationDate->?e)
%
phys:currentDate(?d) % Uncomment for local date (deployment)
:currentDate(?d)
phys:lessThanDate(?d ?e))
)
% Object-relational size-switched safety rules check status (small) or status and hull (large)
% Rule 8 (includes disjunct of original Rule 6)
Forall ?s ?h (
:MeetsSafetyRequirementsUnloaded(?s) :-
?s#:Ship(:size->:small
:hold->?h#:ShipHold(:status->:clean))
)
% Rule 7 (includes disjunct of original Rule 6)
Forall ?s ?h (
:MeetsSafetyRequirementsUnloaded(?s) :-
?s#:Ship(:size->:large
:hold->?h#:ShipHold(:status->:clean
:hull->:double))
)
% Object-centered (except for math) rules to get qualitative size by thresholding length
% Rule 9
Forall ?s ?l (
?s#Top(:size->:small) :-
And(?s#:Ship(:totalLength->?l)
math:lessThan(?l 80))
)

% Rule 4
Forall ?s ?l (
?s#Top(:size->:large) :-
And(?s#:Ship(:totalLength->?l)
math:greaterEq(?l 80))
)
% Object-centered (except for math) rule to get qualitative status by thresholding residual
% Rule 1&5 (combines Rule 1 and Rule 5)
Forall ?h ?c (
?h#Top(:status->:clean) :-
And(?h#:ShipHold(:residualCargoMeasurement->?c)
math:lessEq(?c 0.5))
)
:currentDate(phys:date(2020 5 6)) % Uncomment for fixed date (reproducibility)



% Ship facts (No or Yes refer to answers for queries, as of 2020-05-06, with :ship1, :ship2, ... as arguments)
% Facts covering all cases with qualitative slot-filler distinctions
% Explanatory comments for Yes answers focus on the most relevant slots
% Distinction for :registryExpirationDate
% Ship 1 - No, registry has expired



:ship1#:Ship(:registryExpirationDate->phys:date(2020 5 1)
:totalLength->20
:hold->:h1#:ShipHold(:residualCargoMeasurement->0.2
:hull->:single))

% Ship 2 - Yes, registry is valid
:ship2#:Ship(:registryExpirationDate->phys:date(2020 10 1)
:totalLength->20
:hold->:h2#:ShipHold(:residualCargoMeasurement->0.2
:hull->:single))

% Distinction for :residualCargoMeasurement
% Ship 3 - No, hold not clean
:ship3#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->70
:hold->:h3#:ShipHold(:residualCargoMeasurement->0.6
:hull->:single))

% Ship 4 - Yes, hold clean (qualitatively the same as for Ship 2)
:ship4#:Ship(:registryExpirationDate->phys:date(2020 1 1 )
:totalLength->70
:hold->:h4#:ShipHold(:residualCargoMeasurement->0.4
:hull->:single))

% Distinctions for :residualCargoMeasurement and :hull
% Ship 5 - No, hold not clean
:ship5#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->90
:hold->:h5#:ShipHold(:residualCargoMeasurement->0.6
:hull->:double))

% Ship 6 - No, size large yet hold single-hulled
:ship6#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->90
:hold->:h6#:ShipHold(:residualCargoMeasurement->0.4
:hull->:single))

% Ship 7 - Yes, hold clean and double-hulled
:ship7#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->90
:hold->:h7#:ShipHold(:residualCargoMeasurement->0.4
:hull->:double))

% Facts with multiple reasons for No or Yes
% Three reasons for No
% Ship 8 - No, registry expired, hold not clean, and size large yet hold single-hulled
:ship8#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->90
:hold->:h8#:ShipHold(:residualCargoMeasurement->0.9
:hull->:single))

% Two reasons for No
% Ship 9 - No, hold not clean and size large yet hold single-hulled
:ship9#:Ship(:registryExpirationDate->phys:date(2018 1 1)
:totalLength->90
:hold->:h9#:ShipHold(:residualCargoMeasurement->0.9
:hull->:single))

% Ship 10 - No, registry expired and size large yet hold single-hulled
:ship10#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->90
:hold->:h10#:ShipHold(:residualCargoMeasurement->0.2
:hull->:single))

% Ship 11 - No, registry expired and hold not clean
:ship11#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->90
:hold->:h11#:ShipHold(:residualCargoMeasurement->0.9
:hull->:double))

% Two reasons for Yes
% Ship 12 - Yes, size small nevertheless hold double-hulled
:ship12#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->60
:hold->:h12#:ShipHold(:residualCargoMeasurement->0.1
:hull->:double))

% Facts probing special cases
% Ship 13 - No, large ship must have some (a double) hull
:ship13#:Ship(:registryExpirationDate->phys:date(2020 1 1)
:totalLength->120
:hold->:h13#:ShipHold(:residualCargoMeasurement->0.2))
% Ship 14 - Yes, date, length, and measurement are at the threshold
:ship14#:Ship(:registryExpirationDate->phys:date(2020 5 7)
:totalLength->80
:hold->:h14#:ShipHold(:residualCargoMeasurement->0.5
:hull->:double))
8 changes: 8 additions & 0 deletions EmptyKB.psoa
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
RuleML ( % Empty KB but allowing built-ins and libraries
Prefix(pred: <http://www.w3.org/2007/rif-builtin-predicate#>)
Prefix(func: <http://www.w3.org/2007/rif-builtin-function#>)
Prefix(math: <http://psoa.ruleml.org/lib/math#>)
Prefix(phys: <http://psoa.ruleml.org/lib/phys#>)
Import(<http://psoa.ruleml.org/lib/math.psoa>)
Import(<http://psoa.ruleml.org/lib/phys.psoa>)
)
Loading

0 comments on commit 50fcdb1

Please sign in to comment.