%% john held the apple %% 1. Check objects match words %% 2. check relations match verb /** replace_slang('Johnny','John') replace_nonspecific('fruit','apple'). %% collect_changes([['Johnny','held','the','apple'],['John','held','the','apple']],Changes). collect_changes([Draft|Drafts],Changes) :- collect_changes(Draft,Drafts,[],Changes). collect_changes(Drafts,Draf collect_changes([Word|Words], **/ %% check new words based on object data %% object_to_noun([0.06,0.06,0.06,'red','red','opposite'],[['hand',0.2,0.105,0.045,'flesh-coloured','flesh-coloured','opposite'],['apple',0.06,0.06,0.06,'red','red','opposite']],Name). Name = apple ; object_to_noun([X,Y,Z,Colour1,Colour2,Position],Objects,Name) :- member([Name,X,Y,Z,Colour1,Colour2,Position],Objects). %% relation_to_verb([[0.2,0.105,0.045,'flesh-coloured','flesh-coloured','opposite'],[0.06,0.06,0.06,'red','red','opposite'],['yes','no','no']],[['hand',0.2,0.105,0.045,'flesh-coloured','flesh-coloured','opposite'],['apple',0.06,0.06,0.06,'red','red','opposite']],[['hand','apple','yes','no','no','held']],Action). Action=['I','held','the','apple','.']. relation_to_verb([Properties1,Properties2,[Touching,ChangeSize,ChangeColour]],Objects,Relations,Action) :- object_to_noun(Properties1,Objects,Name1), object_to_noun(Properties2,Objects,Name2), member([Name1,Name2,Touching,ChangeSize,ChangeColour,Verb],Relations), transform_subject(Name1,Name3), objects_to_action(Name3,Verb,Name2,Action). transform_subject('hand','I'). %% objects_to_action('I','held','apple',['I','held','the','apple','.']). %% objects_to_action([[subject,'I'],[verb,'held'],[article_the,'the'],[object,'apple']],[[sentence,[subject,verb_phrase]],[subject,noun],[verb_phrase,[verb,noun_phrase]],[noun_phrase,[article_the,object]],[object,noun],[noun,'I'],[noun,'apple'],[verb,'held'],[article_the,'the']],Action). Action=['I','held','the','apple','.'] objects_to_action(Words,Grammar,Action) :- objects_to_action(Words,_,Grammar,[],Action,sentence). %%objects_to_action(Words1,Words2,Grammar,Action1,Action2,Part) :- %% member([Part,[[Part1]]],Grammar), %% append(Action1,[[Part1]],Action2), %% delete1(Words1,Part1,Words2). objects_to_action([],[],_,Action,Action,_). objects_to_action(Words1,Words2,Grammar,Action1,Action2,Part) :- member([Part,[Part1,Part2]],Grammar), objects_to_action(Words1,Words3,Grammar,Action1,Action3,Part1), objects_to_action(Words3,Words2,Grammar,Action3,Action2,Part2). objects_to_action(Words1,Words2,Grammar,Action1,Action2,Part) :- optional_part(Part,Grammar,Words1,Part1,Words2), member([Part1,Part2],Grammar), atom(Part2), not(member([Part2,_],Grammar)), append(Action1,[Part2],Action2). optional_part(Part,Grammar,Words1,Part1,Words2) :- member([Part,Part1],Grammar), member([Part,Part1],Words1), delete1(Words1,[Part,Part1],Words2). optional_part(Part,_Grammar,Words1,Part1,Words2) :- delete1(Words1,[Part,Part1],Words2). %%objects_to_action(Words1,Words2,Grammar,Action1,Action2,Part). delete1(Words1,[Part,Part1],Words2) :- member([Part,Part1],Words1), delete(Words1,[Part,Part1],Words2),!. delete1(Words,_,Words). %%%% grammar_parser(Word,List1,List2) :- atom(Word),append(List1,[Word],List2). grammar_parser(tree(LT, RT),List1,List2) :- grammar_parser(LT,List1,List3), grammar_parser(RT,List3,List2). %%grammar_parser2(