Skip to content

Commit

Permalink
Merge branch 'LogicalContracts:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
joewatt95 authored May 27, 2024
2 parents fbdc4ba + 9a4a7a3 commit ebb6ab9
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 12 deletions.
25 changes: 25 additions & 0 deletions kb/censusbook.le
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
the templates are:
*a subject* owns *a number* of the sheeps.
*a number* of sheeps do all my subjects together own.

the knowledge base censusbook includes:

a number N of sheeps do all my subjects together own
if N is the sum of each other number such that
a subject owns the other number of the sheeps.

scenario today is:
John Smith owns 1 of the sheeps.
Mary Jones owns 2 of the sheeps.
Elon Musk owns 5626 of the sheeps.

scenario tomorrow is:
John Smith owns 1 of the sheeps.
Mary Jones owns 3 of the sheeps.
Elon Musk owns 5626 of the sheeps.

query total is:
which number of sheeps do all my subjects together own.

query percapita is:
which person owns which number of the sheeps.
39 changes: 39 additions & 0 deletions kb/censusbook.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
:- module(censusbook,[]).

en("the target language is: prolog.

the templates are:
*a subject* owns *a number* of the sheeps.
*a number* of sheeps do all my subjects together own.

the knowledge base censusbook includes:

a number N of sheeps do all my subjects together own
if N is the sum of each other number such that
a subject owns the other number of the sheeps.

scenario today is:
John Smith owns 1 of the sheeps.
Mary Jones owns 2 of the sheeps.
Elon Musk owns 5626 of the sheeps.

scenario tomorrow is:
John Smith owns 1 of the sheeps.
Mary Jones owns 3 of the sheeps.
Elon Musk owns 5626 of the sheeps.

query total is:
which number of sheeps do all my subjects together own.

query percapita is:
which person owns which number of the sheeps.

").

/** <examples>
?- answer("total with scenario today").
?- answer("total with scenario tomorrow").
?- answer("percapita with scenario today").
?- answer("percapita with scenario tomorrow").
?- show prolog.
*/
70 changes: 58 additions & 12 deletions le_input.pl
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,11 @@
{append(Setting, RS, AllS), append(Rules, RRules, AllR)}, !.
settings([], [], Stay, Stay) :- !,
( phrase(rules_previous(_), Stay, _) ;
phrase(ontology_, Stay, _) ;
phrase(scenario_, Stay, _) ;
phrase(query_, Stay, _) ;
phrase(the_plots_are_, Stay, _) ).
% settings ending with the start of the knowledge base or scenarios or queries.
% settings ending with the start of the knowledge base or ontology or scenarios or queries.
settings(_, _, Rest, _) :-
asserterror('LE error in the declarations on or before ', Rest),
fail.
Expand All @@ -313,20 +314,20 @@
content(T) --> %{print_message(informational, "going for KB:"-[])},
spaces_or_newlines(_), rules_previous(Kbname), %{print_message(informational, "KBName: ~w"-[Kbname])},
kbase_content(S), %{print_message(informational, "KB: ~w"-[S])},
content(R),
{append([kbname(Kbname)|S], R, T)}, !.
content(R), {append([kbname(Kbname)|S], R, T)}, !.
content(T) --> %{print_message(informational, "going for the ontology:"-[])},
spaces_or_newlines(_), ontology_content(S), %{print_message(informational, "ontology: ~w"-[S])},
content(R), {append(S, R, T)}, !.
% the annexes to the contract are:
content(T) --> %{print_message(informational, "going for the annexes:"-[])},
spaces_or_newlines(_), annexes_content(S), %{print_message(informational, "annexes: ~w"-[S])},
content(R), {append(S, R, T)}, !.
content(T) --> %{print_message(informational, "going for scenario:"-[])},
spaces_or_newlines(_), scenario_content(S), %{print_message(informational, "scenario: ~w"-[S])},
content(R),
{append(S, R, T)}, !.
content(R), {append(S, R, T)}, !.
content(T) --> %{print_message(informational, "going for query:"-[])},
spaces_or_newlines(_), query_content(S), content(R),
{append(S, R, T)}, !.
content(T) -->
spaces_or_newlines(_), plot_content(S), content(R),
{append(S, R, T)}, !.
content([]) -->
spaces_or_newlines(_).
spaces_or_newlines(_), query_content(S), content(R), {append(S, R, T)}, !.
content([]) --> spaces_or_newlines(_).
content(_, Rest, _) :-
asserterror('LE error in the content ', Rest),
fail.
Expand Down Expand Up @@ -470,6 +471,9 @@
next_section(StopHere, StopHere) :-
phrase(files_to_include_previous(_), StopHere, _), !.

next_section(StopHere, StopHere) :-
phrase(ontology_, StopHere, _), !.

next_section(StopHere, StopHere) :-
phrase(rules_previous(_), StopHere, _), !. % format(string(Message), "Next knowledge base", []), print_message(informational, Message).

Expand Down Expand Up @@ -535,6 +539,35 @@
scenario_content(_, Rest, _) :-
asserterror('LE error found around this scenario expression: ', Rest), fail.

% ontology_content/1 or /3
% an ontology description. All assumptions are added to the kb after verification.
ontology_content(Ontology) --> %spypoint, %{print_message(informational, "starting scenario: "-[])},
ontology_previous(_Name), kbase_content(Ontology), !.
% for the moment, the ontology is added directly to the kb. .

ontology_content(_, Rest, _) :-
asserterror('LE error found around this ontology expression: ', Rest), fail.

% ontology_previous//1
ontology_previous(default) -->
spaces_or_newlines(_), ss_([the, ontology, is, :]), spaces_or_newlines(_).
ontology_previous(KBName) -->
ontology_, [named], spaces(_), [','], extract_constant([',', is, es, est, 'è'], NameWords), [','], spaces(_), is_colon_, spaces_or_newlines(_), %{print_message(informational, " scenario: ~w"-[NameWords])},
{name_as_atom(NameWords, KBName)}.

% annexes_content/1 or /3
% an annexes description. All assumptions are added to the kb after verification.
annexes_content(Annexes) --> %spypoint, %{print_message(informational, "starting scenario: "-[])},
annexes_previous(_Name), kbase_content(Annexes), !.
% for the moment, the ontology is added directly to the kb. .

annexes_content(_, Rest, _) :-
asserterror('LE error found around this annexes expression: ', Rest), fail.

% annexes_previous//1
annexes_previous(default) -->
spaces_or_newlines(_), ss_([the, annexes, to, the, contract, are, :]), spaces_or_newlines(_).


% query_content/1 or /3
% statement: the different types of statements in a LE text
Expand Down Expand Up @@ -1269,6 +1302,12 @@
it_must_not_be_true_that_ -->
it_, [must], spaces(_), [not], spaces(_), [be], spaces(_), [true], spaces(_), [that], spaces(_).

ontology_ --> spaces_or_newlines(_), ['Ontology'], !, spaces(_).
ontology_ --> spaces_or_newlines(_), [ontology], spaces(_). % english
ontology_ --> spaces_or_newlines(_), [the], spaces(_), [ontology], spaces(_). % english
ontology_ --> spaces_or_newlines(_), ['l\''], spaces(_), [ontologie], spaces(_). % french
ontology_ --> spaces_or_newlines(_), [la], spaces(_), ['ontología'], spaces(_). % spanish

/* --------------------------------------------------- Supporting code */
% indentation code
% ri/2 ri(-Conditions, +IndentedForm).
Expand Down Expand Up @@ -1324,6 +1363,13 @@
c2p(RestA, RestAA).

/* --------------------------------------------------- More Supporting code */
% scape spaces ss_/3
ss_(All, [' '|RestIn], Output) :-
ss_(All, RestIn, Output).
ss_([Word|Rest], [Word|RestIn], Output) :-
ss_(Rest, RestIn, Output).
ss_([], Rin, Rout) :- spaces(_, Rin, Rout).

clean_comments([], []) :- !.
clean_comments(['%'|Rest], New) :- % like in prolog comments start with %
jump_comment(Rest, Next),
Expand Down

0 comments on commit ebb6ab9

Please sign in to comment.