Skip to content

Commit

Permalink
Debugging api.pl source_lang/1
Browse files Browse the repository at this point in the history
  • Loading branch information
jacintodavila committed Aug 6, 2024
1 parent 9d7363b commit 328c4b7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
4 changes: 2 additions & 2 deletions api.pl
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@
% Added for API LE
entry_point(R, _{results:AnswerExplanation}) :- get_dict(operation,R,explain), !,
term_string(Query,R.theQuery,[variable_names(_VarPairs_)]),
%print_message(informational,"entry point explain asking: ~w"-[Query]),
le_answer:parse_and_query_and_explanation(R.file, en(R.document), Query, with(R.scenario), AnswerExplanation).
print_message(informational,"entry point explain asking: ~w"-[Query]),
le_answer:parse_and_query_and_explanation_text(R.file, en(R.document), Query, with(R.scenario), AnswerExplanation).
%print_message(informational,"entry point query returning: ~w"-[AnswerExplanation]).

% Example:
Expand Down
20 changes: 12 additions & 8 deletions le_answer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@
% hack to bring in the reasoner for explanations.
targetBody(G, false, _, '', [], _) :-
this_capsule(SwishModule), extract_goal_command(G, SwishModule, _InnerG, Command),
print_message(informational, "Reducing ~w to ~w"-[G,Command]),
%print_message(informational, "Reducing ~w to ~w"-[G,Command]),
call(Command).

dump(templates, String) :-
Expand Down Expand Up @@ -674,13 +674,13 @@

dump(constraints, List, String) :- %trace,
findall((false :- Body),
(member( (:- Body_), List), unwrapBody(Body_, Body)), Predicates),
(member( (:- _:Body_), List), unwrapBody(Body_, Body)), Predicates),
with_output_to(string(String), forall(member(Clause, Predicates), portray_clause_ind(Clause))).
%print_message(informational, " Constraints ~w"-[String]).

dump(rules, List, String) :- %trace,
findall((Pred :- Body),
(member( (Pred :- Body_), List), unwrapBody(Body_, Body)), Predicates),
(member( (Pred :- _:Body_), List), unwrapBody(Body_, Body)), Predicates),
with_output_to(string(String), forall(member(Clause, Predicates), portray_clause_ind(Clause))).
%print_message(informational, " Rules ~w"-[String]).

Expand Down Expand Up @@ -744,13 +744,13 @@
%myDeclaredModule(SwishModule),
this_capsule(SwishModule),
%SwishModule=user,
%print_message(informational, "the dictionaries are being restored into module ~w"-[SwishModule]),
print_message(informational, "the dictionaries are being restored into module ~w"-[SwishModule]),
(SwishModule:local_dict(_,_,_) -> findall(dict(A,B,C), SwishModule:local_dict(A,B,C), ListDict) ; ListDict = []),
(SwishModule:local_meta_dict(_,_,_) -> findall(meta_dict(A,B,C), SwishModule:local_meta_dict(A,B,C), ListMetaDict); ListMetaDict = []),
%(local_dict(_,_,_) -> findall(dict(A,B,C), local_dict(A,B,C), ListDict) ; ListDict = []),
%(local_meta_dict(_,_,_) -> findall(meta_dict(A,B,C), local_meta_dict(A,B,C), ListMetaDict); ListMetaDict = []),
append(ListDict, ListMetaDict, DictEntries),
%print_message(informational, "the dictionaries being restored are ~w"-[DictEntries]),
print_message(informational, "the dictionaries being restored are ~w"-[DictEntries]),
collect_all_preds(SwishModule, DictEntries, Preds),
%print_message(informational, "the dictionaries being set dynamics are ~w"-[Preds]),
declare_preds_as_dynamic(SwishModule, Preds).
Expand Down Expand Up @@ -918,23 +918,25 @@
:- multifile kp_loader:myDeclaredModule_/1.

parse_and_query(File, Document, Question, Scenario, AnswerExplanation) :-
print_message(informational, "parse_and_query ~w ~w ~w ~w"-[File, Document, Question, Scenario]),
%print_message(informational, "parse_and_query ~w ~w ~w ~w"-[File, Document, Question, Scenario]),
%Answer = 'respuesta + explanation'.
%context_module(user), % LE programs are in the user module
%prolog_load_context(source,File), % atom_prefix(File,'pengine://'), % process only SWISH windows
%prolog_load_context(term_position,TP), stream_position_data(line_count,TP,Line),
le_taxlog_translate(Document, _, 1, TaxlogTerms),
%print_message(informational, "TaxlogTerms to be asserted "-[TaxlogTerms]),
%M = user,
this_capsule(M),
%api:set_le_program_module(M),
%M:assert(myDeclaredModule_(M)),
%print_message(informational, "Expanded to be asserted on ~w "-[M]),
non_expanded_terms(File, TaxlogTerms, ExpandedTerms),
print_message(informational, "Expanded to be asserted on ~w this ~w"-[M, ExpandedTerms]),
%print_message(informational, "Expanded to be asserted on ~w this ~w"-[M, ExpandedTerms]),
%forall(member(T, ExpandedTerms), (assertz(M:T), print_message(informational, "Asserted ~w"-[M:T]))), % simulating term expansion
%kp_loader:assert(myDeclaredModule_(user)),
%myDeclaredModule(M),
forall(member(T, [(:-module(File,[])), source_lang(le)|ExpandedTerms]), assertz(M:T)), % simulating term expansion
forall(member(T, [(:-module(File,[])), source_lang(en)|ExpandedTerms]), assertz(M:T)), % simulating term expansion
%restore_dicts,
answer( Question, Scenario, AnswerExplanation).

parse_and_query_and_explanation(File, Document, Question, Scenario, Answer) :-
Expand All @@ -960,8 +962,10 @@
parse_and_query_and_explanation_text(File, Document, Question, Scenario, Answer) :-
%print_message(informational, "parse_and_query and explanation ~w ~w ~w ~w"-[File, Document, Question, Scenario]),
le_taxlog_translate(Document, _, 1, TaxlogTerms),
%print_message(informational, "TaxlogTerms to be asserted "-[TaxlogTerms]),
this_capsule(M),
non_expanded_terms(File, TaxlogTerms, ExpandedTerms),
%print_message(informational, "Expanded to be asserted on ~w this ~w"-[M, ExpandedTerms]),
M:assertz(myDeclaredModule_(File)),
forall(member(T, [(:-module(File,[]))|ExpandedTerms]), assertz(M:T)), % simulating term expansion
hack_module_for_taxlog(M),
Expand Down
19 changes: 10 additions & 9 deletions syntax.pl
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,19 @@
% this_capsule(SwishModule),
% declare_facts_as_dynamic(SwishModule, [just_saved_scasp(_, _)]), !.


taxlog2prolog(if(_LineNumber,H,B), Spec, New) :- !, taxlog2prolog(if(H,B),Spec,New). % hack for LogicalEnglish
taxlog2prolog(if(function(Call,Result),Body), neck(if)-[delimiter-[head(meta,Call),classify],SpecB], (function(Call,Result):-Body)) :- !,
taxlogBodySpec(Body,SpecB).
taxlog2prolog(if(at(on(H,T),Url),B), neck(if)-[delimiter-[delimiter-[SpecH,classify],classify],SpecB], (H:-targetBody(B,true,T,Url,[],taxlog))) :- !,
taxlog2prolog(if(at(on(H,T),Url),B), neck(if)-[delimiter-[delimiter-[SpecH,classify],classify],SpecB], (H:-le_answer:targetBody(B,true,T,Url,[],taxlog))) :- !,
taxlogHeadSpec(H,SpecH), taxlogBodySpec(B,SpecB).
taxlog2prolog(if(at(H,Url),B), neck(if)-[delimiter-[SpecH,classify],SpecB], (H:-targetBody(B,false,_T,Url,[],taxlog))) :- !,
taxlog2prolog(if(at(H,Url),B), neck(if)-[delimiter-[SpecH,classify],SpecB], (H:-le_answer:targetBody(B,false,_T,Url,[],taxlog))) :- !,
taxlogHeadSpec(H,SpecH), taxlogBodySpec(B,SpecB).
taxlog2prolog(if(on(H,T),B), neck(if)-[delimiter-[SpecH,classify],SpecB], (H:-targetBody(B,true,T,'',[],taxlog))) :- !,
taxlog2prolog(if(on(H,T),B), neck(if)-[delimiter-[SpecH,classify],SpecB], (H:-le_answer:targetBody(B,true,T,'',[],taxlog))) :- !,
taxlogHeadSpec(H,SpecH), taxlogBodySpec(B,SpecB).
taxlog2prolog(if(H,B),neck(if)-[SpecH,SpecB],(H:-targetBody(B,false,_,'',[],taxlog))) :- !,
taxlog2prolog(if(H,B),neck(if)-[SpecH,SpecB],(H:-le_answer:targetBody(B,false,_,'',[],taxlog))) :- !,
taxlogHeadSpec(H,SpecH), taxlogBodySpec(B,SpecB).
taxlog2prolog((because(on(H,T),Why):-B), neck(clause)-[ delimiter-[delimiter-[SpecH,classify],classify], SpecB ], (H:-targetBody(call(B),true,T,'',Why,taxlog))) :- Why\==[], !,
taxlog2prolog((because(on(H,T),Why):-B), neck(clause)-[ delimiter-[delimiter-[SpecH,classify],classify], SpecB ], (H:-le_answer:targetBody(call(B),true,T,'',Why,taxlog))) :- Why\==[], !,
taxlogHeadSpec(H,SpecH), taxlogBodySpec(B,SpecB).
taxlog2prolog(mainGoal(G,Description),delimiter-[Spec,classify],(mainGoal(G,Description):-(_=1->true;GG))) :- !, % hack to avoid 'unreferenced' highlight in SWISH
functor(G,F,N), functor(GG,F,N), % avoid "Singleton-marked variable appears more than once"
Expand All @@ -143,16 +144,16 @@

% extending to cover new structural changes at semantical level

semantics2prolog(if(N,empty,B),neck(if)-[SpecH,SpecB],(:-targetBody(B,false,_,'',[],NN))) :- !, % working rule with line number
semantics2prolog(if(N,empty,B),neck(if)-[SpecH,SpecB],(:-le_answer:targetBody(B,false,_,'',[],NN))) :- !, % working rule with line number
NN is N + 3, % correction to linecount
taxlogHeadSpec(empty,SpecH), taxlogBodySpec(B,SpecB).
semantics2prolog(if(empty,B),neck(if)-[SpecH,SpecB],(:-targetBody(B,false,_,'',[],3))) :- !, % pre-settings without line numbers
semantics2prolog(if(empty,B),neck(if)-[SpecH,SpecB],(:-le_answer:targetBody(B,false,_,'',[],3))) :- !, % pre-settings without line numbers
taxlogHeadSpec(empty,SpecH), taxlogBodySpec(B,SpecB).
semantics2prolog(if(N,H,B),neck(if)-[SpecH,SpecB],(H:-targetBody(B,false,_,'',[],NN))) :- !, % working rule with line number
semantics2prolog(if(N,H,B),neck(if)-[SpecH,SpecB],(H:-le_answer:targetBody(B,false,_,'',[],NN))) :- !, % working rule with line number
H\=empty,
NN is N + 3, % correction to linecount
taxlogHeadSpec(H,SpecH), taxlogBodySpec(B,SpecB).
semantics2prolog(if(H,B),neck(if)-[SpecH,SpecB],(H:-targetBody(B,false,_,'',[],3))) :- !, % pre-settings without line numbers
semantics2prolog(if(H,B),neck(if)-[SpecH,SpecB],(H:-le_answer:targetBody(B,false,_,'',[],3))) :- !, % pre-settings without line numbers
H\=empty,
taxlogHeadSpec(H,SpecH), taxlogBodySpec(B,SpecB),
this_capsule(SwishModule),
Expand Down

0 comments on commit 328c4b7

Please sign in to comment.