/** Number ?- question([how,many,marbles,did,john,throw],[[john,threw,2,marbles],[john,threw,3,marbles]],Number). C = 5 ; I threw 2 marbles I threw 3 marbles [ [i,need,me], [ [i,need,2,marbles],[the,A,marbles,were,thrown,by,me] ] ] **/ sentence_to_ontologies(Sentence,Ontologies) :- phrase(sentence(Ontologies),Sentence). sentence(Ontologies) --> noun_phrase(Subject), verb_phrase(Verb1,Object), {subject_to_object(Subject,Object2),append(Verb1,[by,Object2],Verb), append_list([Subject,need,Object],Copremise1), append_list([the,Object,Verb],Copremise2), Ontologies= [ [Subject,need,Object2], [ Copremise1,Copremise2 ] ]}. subject_to_object(i,me). noun_phrase(Noun) --> [Noun], {Noun=i}. verb_phrase(Verb2,Object2) --> [Verb1], [A], [Object], {Verb1=threw, Object=marbles, verb_transform(Verb1,A,Verb2), append([A],[Object],Object2)}. verb_transform(threw,A,[were,thrown]) :- number(A,plural). number(1,singular). number(2,plural). number(3,plural). value( [ [i,need,me], [ [i,need,A,marbles],[the,A,marbles,were,thrown,by,me] ] ] ,A). sum([Sentence1,Sentence2],C) :- sentence_to_ontologies(Sentence1,Ontologies1),value(Ontologies1,A), sentence_to_ontologies(Sentence2,Ontologies2),value(Ontologies2,B), C is A+B. append_list([A|B],C) :- append_list([],[A,B],C). append_list(A,[],A). append_list(A,[[B1|B1s]|Bs],C) :- append_list(A,[B1|B1s],C1), append_list(C1,Bs,C), !. append_list(A,[B|Bs],C) :- append(A,[B],C1), append_list(C1,Bs,C).