Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* MicroWatson 2015 */
- 'Some nigga':-
- write('232').
- micro_watson:-
- write('1. Novels/Films of the 20th Century'),nl,
- write('2. Novels of the 19th Century'),nl,
- write('3. Novels of the 18th Century'),nl,
- write('Please enter a category number!'),nl,
- read(Category),
- (Category == 1 -> micro_watson2; write('Goodbye')).
- micro_watson2:-
- write('Please give me an answer.'),nl,
- write('micro_watson: '),
- read(Sentence),
- sentence(Sentence,Output),
- write(Output),
- parse(Sentence,_,TargetList),
- write(TargetList).
- sentence(Sentence,sentence(np(Noun_Phrase),vp(Verb_Phrase))):-
- /* so take a sentence (first arg) and parse it into a noun phrase and a verb phase */
- np(Sentence,Noun_Phrase,Rem),
- write(Noun_Phrase),nl,
- vp(Rem,Verb_Phrase),
- write(Verb_Phrase),nl.
- /* NP -> Det NP2 */
- np([X|T],np(det(X),NP2),Rem):-
- det(X),
- np2(T,NP2,Rem).
- /* NP -> NP2 */
- np(Sentence,Parse,Rem):- np2(Sentence,Parse,Rem).
- /* NP -> NP PP */
- np(Sentence,np(NP,PP),Rem):-
- np(Sentence,NP,Rem1),
- pp(Rem1,PP,Rem).
- /* NP2 -> Noun */
- np2([H|T],np2(noun(H)),T):- noun(H).
- /* NP2 -> Adj NP2 */
- np2([H|T],np2(adj(H),Rest),Rem):- adj(H),np2(T,Rest,Rem).
- /* PP -> Prep NP */
- pp([H|T],pp(prep(H),Parse),Rem):-
- prep(H),
- np(T,Parse,Rem).
- /* VP -> Verb */
- vp([H|[]],verb(H)):-verb(H).
- /* VP -> Verb Adverb NP */
- vp([H|[T|Rest]],vp(verb(H),adverb(T),RestParsed)):-
- verb(H),adverb(T),
- np(Rest,RestParsed,_).
- /* Vp -> Verb Adverb */
- vp([H|[T]],verb(H)):-adverb(T).
- /* Vp -> Verb NP */
- vp([H|Rest],vp(verb(H),RestParsed)):-
- verb(H),
- pp(Rest,RestParsed,_).
- /* Vp -> Verb PP */
- vp([H|Rest],vp(verb(H),RestParsed)):-
- verb(H),
- np(Rest,RestParsed,_).
- /* extracting SOV */
- parse(Sentence,VP_List,TargetList):-
- parse_SOV(Sentence,VP_List,TargetList).
- parse_SOV(Sentence,VP_List,TargetList):-
- /* Grab the first noun from the sentence and assume it is the subject */
- member(Subject,Sentence),
- noun(Subject),
- /* Grab the first noun from the verb phrase and assume it is the object */
- member(Object,VP_List),
- noun(Object),
- /* Grab the verb from the verb phrase */
- member(Verb,VP_List),
- verb(Verb),
- nl,
- TargetList = parse_sov(subject(Subject),object(Object),verb(Verb)).
- /* dictionary */
- det(a).
- det(the).
- adj(young).
- adj(middle_aged).
- adj(magic).
- adj(faithful).
- adj(paranoid).
- prep(on).
- prep(by).
- verb(finds).
- verb(destroys).
- verb(saves).
- verb(is).
- noun(expelled).
- noun(hobbit).
- noun(ring).
- noun(valet).
- noun(butler).
- noun(robot).
- noun(day).
- noun(holden).
- noun(marvin).
- adverb(quietly).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement