
/* Simple SIR program */

sir :-
   read_sentence(Sent),
   process_sentence(Sent).

process_sentence([bye]) :- !.
process_sentence(Sent) :-
   response(Sent,Resp),
   display_response(Resp), !,
   nl, nl,
   sir.
process_sentence(Sent) :-
   error('No response provided for sentence',[Sent]).

/* Read in a sentence (use POP-11) */

read_sentence(Sent) :-
   Sent is prolog_safereadline('Input? ').

/* Print out a reponse */

display_response([First|Rest]) :- !,
   write(First),
   write(' '),
   display_response(Rest).
display_response([]) :- !.
display_response(Other) :-
   write(Other).

/* Allow a predicate to fail if no clauses */

allow(F,N) :- functor(T,F,N), clause(T,_), !.
allow(F,N) :- functor(T,F,N), assert(T), retract(T), !.

/* Representation of properties.
   Expected to appear in the database:

        has_property(Person,Property)
        implies(Property1,Property2)
*/

:- allow(has_property,2), allow(implies,2).

inferred_property(Indiv,Prop) :-
   has_property(Indiv,Prop).
inferred_property(Indiv,Prop) :-
   implies(Other,Prop),
   inferred_property(Indiv,Other).

/* See result of current session within VED */

:- prolog_language("pop11").

define list_to_ved(pred);
   vars cucharout, curr_file;
   vedcurrent -> curr_file;
   'property.pl' -> vedargument;
   ved_ved();
   vedendfile();
   vedcharinsert -> cucharout;
   erase(prolog_invoke(prolog_maketerm(pred,"listing",1)));
   curr_file -> vedargument;
   ved_ved()
enddefine;

:- prolog_language("prolog").

list_to_ved(Pred) :-
   prolog_eval(list_to_ved(quote(Pred))).

list :-
   list_to_ved(has_property),
   list_to_ved(implies).
