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(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). 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]]. 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). article(a). article(the). noun(fido, [dog(fido)]). noun(man, [man(X)]). noun(dog, [dog(X)]). verb(likes, [action([liking(X)]), agent([animate(X)]), object([animate(Y)])]). verb(bites, [action([biting(Y)]), agent([dog(X)]), object([animate(Z)])]).