📄 sentence_recognise.pro
字号:
domains
sentence = sentence(noun_phrase, verb_phrase)
noun_phrase = noun(noun); noun_phrase(determiner, noun_expression)
noun_expression = noun(noun); noun_expression(adjective, noun)
noun = string
adjective = string
verb_phrase = verb(verb); verb_phrase(verb, noun_phrase)
verb = string
determiner = string
predicates
s_sentence(string, sentence) - nondeterm (i,o)
s_noun_phrase(string, string, noun_phrase) - nondeterm (i,o,o), nondeterm (i,i,o)
s_verb_phrase(string, verb_phrase) - nondeterm (i,o)
s_noun_expression(string, string, noun_expression) - nondeterm (i,o,o), nondeterm (i,i,o)
nondeterm command_loop
nondeterm write_message
facts - general
a(string) %- determ (i)
d(string) %- determ (i)
n(string) %- nondeterm (i)
v(string) %- determ (i)
clauses
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% 一个句子可拆分为名词短语和动词短语 %%%%%%%
s_sentence(Str, sentence(N_Phrase, V_Phrase)):-
s_noun_phrase(Str, Rest, N_Phrase),
s_verb_phrase(Rest, V_Phrase).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% 分析名词短语 %%%%%%%%%%%%%%%%%%%%%
s_noun_phrase(Str, Rest, noun_phrase(Deter, N_Exp)):-
fronttoken(Str, Deter, Rest1),
d(Deter),
write("article=", Deter), nl,
s_noun_expression(Rest1, Rest, N_Exp).
/*s_noun_phrase(Str, Rest, noun(Noun)):-
fronttoken(Str, Noun, Rest),
not(n(Noun)),write("This program doesn't know the word:", Noun), nl,
write("Please append it to the database!"), nl,
command_loop. */
s_noun_phrase(Str, Rest, noun(Noun)):-
fronttoken(Str, Noun, Rest),
n(Noun),
write("noun=", Noun), nl.
s_noun_expression(Str, Rest, noun_expression(Adj, Noun)):-
fronttoken(Str, Adj, Rest1),
a(Adj),
fronttoken(Rest1,Noun,Rest),
n(Noun),
write("adjective=", Adj), nl,
write("noun=", Noun), nl.
s_noun_expression(Str, Rest, noun(Noun)):-
fronttoken(Str, Noun, Rest),
n(Noun),
write("noun=", Noun), nl.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%% 分析动词短语 %%%%%%%%%%%%%%%%%%
s_verb_phrase(Str, verb(Verb)):-
fronttoken(STR, Verb, ""),
v(Verb),
write("verb=", Verb), nl.
s_verb_phrase(Str, verb_phrase(Verb, N_Phrase)):-
fronttoken(Str, Verb, Rest1),
v(Verb),
write("verb=", Verb), nl,
s_noun_phrase(Rest1, "", N_Phrase).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%% 单词数据库 %%%%%%%%%%%%%%%%%%
/* adjective */
a("big").
a("small").
a("brown").
a("lazy").
/* article */
d("the").
d("a").
/* noun */
n("dog").
n("bone").
n("mouse").
n("cat").
/* verb */
v("ate").
v("eat").
v("chases").
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% 循环提示输入句子并分析 %%%%%%%%%%%%
command_loop:-
write("Please input a sentence:"),
nl,
readln(S),
not(s_sentence(S, _)),
write_message,
command_loop.
command_loop:-
write("This is a valid sentence!"), nl, nl,
command_loop.
write_message:-
write("This is a invalid sentence!"), nl, nl.
goal
command_loop.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -