Home » Projects » AI-Trader » Sample Session

  AI-Trader   |   Conceptual Graphs   |   Sample Session   |   Demo   |   Implementation   |   Publications   |   People  

AI-Trader

Sample Session

The interface of the AI-Trader is defined via simple ASCII-based commands. Although the graphical user interface masks these internal implementation details, the following sample session provides a good insight of the AI-Trader's capabilities. The script presented below runs without modification with the text based version of the AI-Trader.

/*
* STEP 1
* ------
* Define a few relations on words and their mathematical properties
* as well as the top and bottom element of the concept type lattice.
*/

@register-relation 'SYNONYM' : @reflexive, @transitive, @symmetric 
@register-relation 'ANTONYM' : @symmetric 
@register-relation 'IS_A'    : @reflexive, @transitive, @acyclic 

@add-word something 

/*
* STEP 2
* ------
* Define a matching rule which matches graphs based on
* syntactical equivalence.
*/

@define-matching-rule 'Specialization'
%
% Specialization
%
isa(Node1, Node2) :-
	cg_getname(Node1, Name1), cg_getname(Node2, Name2),
	cg_matchword(Name1, ['IS_A', 'SYNONYM'], Name2).

match(Q, T, Res) :-
	cg_gettype(Q, concept),
	isa(T, Q),
	cg_getsucc(T, Tsucc), cg_getsucc(Q, Qsucc),
	match_lists_con(Qsucc, Tsucc, Res, 0, 0).

match(Q, T, Res) :-
	cg_gettype(Q, relation),
	isa(T, Q),
	cg_getsucc(T, Tsucc), cg_getsucc(Q, Qsucc),
	match_lists_rel(Qsucc, Tsucc, Res, 0, 0).
%
% determine the value of the best match of Q againts any T in Tlist
% - if exists i: 0 <= i < sizeof(Tlist) and match(Q, T_i) < 0; then
%     Res = -1
% - else
%     Res = max{match(Q, T_i) | 0 <= i < sizeof(Tlist)}
%
best_match(_, [], MaxVal, MaxVal).
best_match(Q, [T|Tlist], MaxVal, Res) :-
	(cg_match(Q, T, Val) ; Val is 0),
	(Val < 0
	->	Res is Val
	;	best_match(Q, Tlist, max(Val, MaxVal), Res)).
%
% concept nodes:
% at least on subtree in the query must have a matching subtree in
% the type
%
match_lists_con([], _, 1000, _, 0) :- !.
match_lists_con([], _, Res, Sum, NSucc) :-
	Res is round(Sum/NSucc),
	Res > 0.

match_lists_con([Q|Qlist], Tlist, Res, Sum, NSucc) :-
	best_match(Q, Tlist, 0, BestMatch),
	(BestMatch > 0
	->	NewSum is Sum+BestMatch
	;	NewSum is Sum),
	match_lists_con(Qlist, Tlist, Res, NewSum, NSucc+1).

%
% relation nodes:
% every subtree in the query must have a matching subtree in the type
%
match_lists_rel([], _, 1000, _, 0) :- !.
match_lists_rel([], _, Res, Sum, NSucc) :-
       Res is round(Sum/NSucc),
       Res > 0.

match_lists_rel([Q|Qlist], Tlist, Res, Sum, NSucc) :-
       (Q, Tlist, 0, BestMatch),
       BestMatch > 0,
       match_lists_rel(Qlist, Tlist, Res, Sum+BestMatch, NSucc+1).

@end

/*
* STEP 3
* ------
* Define a matching rule for negation
*/

@define-matching-rule 'Negation'
%
% Negation
%
isa(Node1, Node2) :-
	cg_getname(Node1, Name1), cg_getname(Node2, Name2),
	cg_matchword(Name1, ['IS_A', 'SYNONYM'], Name2).

antonym(Node1, Node2) :-
	cg_getname(Node1, Name1), cg_getname(Node2, Name2),
	cg_matchword(Name1, ['IS_A', 'ANTONYM'], Name2).

match(Qcon, Tcon, -1) :-
	cg_gettype(Qcon, concept),
	isa(Tcon, Qcon),
	cg_getsucc(Qcon, QrelList), cg_getsucc(Tcon, TrelList),
	member(Qrel, QrelList), member(Trel, TrelList),
	antonym(Trel, Qrel),
	cg_getsucc(Qrel, QconList), cg_getsucc(Trel, TconList),
	member(Qcon2, QconList), member(Tcon2, TconList),
	isa(Tcon2, Qcon2).

@end

/*
* STEP 4
* ------
* Add the first conceptual graph describing 'vacation'.
* Before adding the graph, add the necessary words and relations
* (assume that our knowledge base already cantains 'culture', 'concert',
* 'exhibition', 'sightseeing' and 'characteristic').
*
* AI-Trader will return the unique service database key $0
* (output of the AI-Trader is not shown).
*
*/

@add-word vacation
@add-word activity
 
@add-relation vacation : 'IS_A' : something
@add-relation activity : 'IS_A' : human_activity
 
@add [vacation]->(characteristic)->[culture]- 
                                    ->(activity)->[concert], 
                                    ->(activity)->[exhibition], 
                                    ->(activity)->[sightseeing].

/*
* STEP 5
* ------
* A lookup which succeeds. It matches with vacation from STEP 4.
*/

@match 'Specialization', 'Negation' : 
       [something] -> (characteristic) -> [human_activity]

/*
* STEP 6
* ------
* A lookup which does not succeed.
*/

@match 'Specialization', 'Negation' : 
       [something] -> (location) -> [town]

/*
* STEP 7
* ------
* Learn the new features of vacation. The query from STEP 6
* will now succeed:
*     'vacation' is a specialization of 'something' and
*     'city' is a synonym for 'town' ('town' is already known).
*/

@add-word city 
@add-relation city : 'SYNONYM' : town

@join $0 : [vacation] -> (location) -> [city]

/*
* STEP 8
* ------
* A new service is to be exported. The conceptual graph which
* the service provider has chosen to "explain" his service is
* as follows:
*     [vacation] -> (characteristic) -> [human_activity]
*
* First check if another graph resembles this one via the
* "@match" command.
*/

@match 'Specialization', 'Negation' :
       [vacation] -> (characteristic) -> [human_activity]

/*
* STEP 9
* ------
* The description of a vacation from STEP 7 is too similar, the
* service provider decides to augment his inital description.
* He refines the definition of 'human_activity' und replaces it
* with `relaxation'.
* (assume that our knowledge base already cantains 'relaxation',
* 'beach', 'sport' and 'characteristic').
*
* AI-Trader will assign this graph the unique service database
* key $1.
*/

@add-word non_location
@add-relation location : 'ANTONYM' : non_location

@add [vacation] -
      -> (characteristic) -> [relaxation] , 
      -> (non_location) -> [city] ,
      -> (location) -> [beach] , 
      -> (activity) -> [sport] .

/*
* STEP 10
* -------
* The description of beach vacation is forwarded to the service
* provider offering a cultural vacation, where upon he decides to
* add a few describtion to his graph to refine it.
*
*/

@join $0 :  [vacation] -
              -> (accommodation) -> [hotel] , 
              -> (duration) -> ['day' : 7] . 

/*
* STEP 11
* -------
* The first query will *only* match "culture vacation" and the
* second *only* 'beach vacation'.
* The third query will match *both* graphs (i.e. $0 and $1).
*
*/

@match 'Specialization', 'Negation' :
       [something] -> (location) -> [city]

@match 'Specialization', 'Negation' :
       [something] -> (non_location) -> [town]

@match 'Specialization' :
       [something] -> (characteristic) -> [human_activity]

/*
* STEP 12
* -------
* Add the addresses of the service providers and do a checkpoint of
* the trader's database.
*/

@add-provider $0 : 'Happy Holiday',   'hh@foo1.bar1'
@add-provider $1 : 'Our World', 'OurWorld@foo2.bar2'
  
@save 'checkpoint.kb'
Last modified: Saturday, 4-Feb-2012 18:06:51 PST   (AP) 9080 visits