PROLOG


/* A recursive Semantic Net Parser (Chinese Version)
  Author: Shuda Li (李书达)
  Date:06/03/2004
  Design: Very basic Chinese Grammar

  test1 :- utterance([这个, 人, 喜欢, 这条, 狗], X). It means the man likes the dog.
  test2 :- utterance([花点, 喜欢, 这个, 人], W).     It means Huadian, the name of a doge, likes the man 
  test3 :- utterance([李小明, 咬了, 花点], Z).       It means Xiaoming Li, the name of a person, bites the dog.
  test4 :- utterance([这只, 猫, 喜欢, 这个, 人], K). It means the cat likes the man.
  test5 :- utterance([这条, 狗, 咬了, 这只, 猫], L). It means the dog bites the cat.
  test6 :- utterance([花点,咬了,这只,猫],M). It means Huandian, the name of a dog, bites the cat.

  
*/

utterance(X, Sentence_graph) :-	sentence(X, [], Sentence_graph).

sentence(Start, End, Sentence_graph) :-
		nounphrase(Start, Rest, Subject_graph),
		verbphrase(Rest, End, Predicate_graph),
		join([agent(Subject_graph)],Predicate_graph, Sentence_graph).

nounphrase([Noun|End], End, Noun_phrase_graph) :-
		noun(Noun, Noun_phrase_graph).

nounphrase([Article, Noun| End], End, Noun_phrase_graph) :-
		article(Article), noun(Noun, Noun_phrase_graph).

verbphrase([Verb| End], End, Verb_phrase_graph) :-
		verb(Verb, Verb_phrase_graph).

verbphrase([Verb|Rest], End, Verb_phrase_graph) :-
		verb(Verb, Verb_graph),
		nounphrase(Rest, End, Noun_phrase_graph),
		join([object(Noun_phrase_graph)],Verb_graph,Verb_phrase_graph).


join_frames([A|B], C, D, OK) :-
		join_slot_to_frame(A, C, E), !,
		join_frames(B, E, D, ok).

join_frames([A|B], C, [A|D], OK) :-
		join_frames(B, C, D, OK), !.

join_frames([], A, A, ok).

join_slot_to_frame(A, [B|C], [D|C]) :-
		join_slots(A, B, D).

join_slot_to_frame(A, [B|C], [B|D]) :-
		join_slot_to_frame(A, C, D).
		join_slots(A, B, D) :-
		functor(A, FA, _),
		functor(B, FB, _),
		match_with_inheritance(FA, FB, FN),
		arg(1, A, Value_a),
		arg(1, B, Value_b),
		join(Value_a, Value_b, New_value),
		D =..[FN|[New_value]].

join(X, X, X).

join(A, B, C) :- isframe(A), isframe(B), !,
		join_frames(A, B, C, not_joined).

join(A, B, C) :- isframe(A), is_slot(B), !,
		join_slot_to_frame(B, A, C).

join(A, B, C) :- isframe(B), is_slot(A), !,
		join_slot_to_frame(A, B, C).

join(A, B, C) :- is_slot(A), is_slot(B), !,
		join_slots(A, B, C).

isframe([_|_]).
isframe([]).

is_slot(A) :- functor(A, _, 1).

match_with_inheritance(X, X, X).
match_with_inheritance(dog, animate, dog).
match_with_inheritance(animate, dog, dog).
match_with_inheritance(man, animate, man).
match_with_inheritance(animate, man, man).
match_with_inheritance(animate, man, 李小明).
match_with_inheritance(catt, animate, catt).
match_with_inheritance(animate, catt, catt).

article(一个).
article(这个).
article(这条).
article(这只).

noun(花点, [dog(花点)]).
noun(人, [man(X)]).
noun(李小明, [man(李小明)]).
noun(狗, [dog(X)]).
noun(猫, [catt(X)]).

verb(喜欢,[action([liking(X)]),agent([animate(X)]),
		object([animate(Y)])]).
verb(咬了,[action([biting(Y)]),agent([dog(X)]),
		object([animate(Z)])]).
verb(咬了,[action([biting(Y)]),agent([catt(X)]),
		object([animate(Z)])]).

 
test1 :- utterance([这个, 人, 喜欢, 这条, 狗], X).
test2 :- utterance([花点, 喜欢, 这个, 人], W). 
test3 :- utterance([李小明, 咬了, 花点], Z).
test4 :- utterance([这只, 猫, 喜欢, 这个, 人], K).
test5 :- utterance([这条, 狗, 咬了, 这只, 猫], L).
test6 :- utterance([花点, 咬了, 这只, 猫],M). 
      

Close Window