?? 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).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%% 單詞數(shù)據(jù)庫 %%%%%%%%%%%%%%%%%%
/* 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").
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% 循環(huán)提示輸入句子并分析 %%%%%%%%%%%%
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 + -