我已经在Prolog中设置了自然语言分析任务。到目前为止,我的程序在某种程度上工作。到目前为止,如果我输入[the,cat,sat,on,the,mat]
的列表,那么它将打印sentence(noun_phrase(det(the), np2(noun(cat))), verb_phrase(verb(sat), pp(prep(on), noun_phrase(det(the), np2(noun(mat))))))
,这很好。从序言结构中提取单词
下一个任务我必须做的是从句子中提取的关键字,即提取的名词短语的名词,在动词短语动词和动词短语的名词,所以我可以返回一个列表: [猫,饱和,垫。任何人都可以帮我开始,因为我很坚持这一点。谢谢!
我当前的代码是:
sentence(S,sentence((NP), (VP))):-
nl,
np(S, NP, R),
vp(R, VP, []),
write('sentence('), nl, write(' '), write((NP))
,nl,write(' '), write((VP)),nl,write(' ').
np([X | S], noun_phrase(det(X), NP2), R) :-
det(X),
np2(S, NP2, R).
np(S, NP, R) :-
np2(S, NP, R).
np(S, np(NP, PP), R) :-
append(X, Y, S), /* Changed here - otherwise possible endless recursion */
pp(Y, PP, R),
np(X, NP, []).
np2([X | R], np2(noun(X)), R) :-
noun(X).
np2([X | S], np2(adj(X), NP), R) :-
adj(X),
np2(S, NP, R).
pp([X | S], pp(prep(X), NP), R):-
prep(X),
np(S, NP, R).
vp([X | R], verb_phrase(verb(X)), R) :- /* Changed here - added the third argument */
verb(X).
vp([X | S], verb_phrase(verb(X), PP), R) :-
verb(X),
pp(S, PP, R).
vp([X | S], verb_phrase(verb(X), NP), R) :-
verb(X),
np(S, NP, R).
det(the).
det(with).
noun(cat).
noun(mat).
verb(sat).
prep(on).
adj(big).
好的,感谢您的答复。然而,我宁愿不改变我已经有的标记,因为时间是一个问题:( – MartinM 2011-04-05 13:20:11