Presentation is loading. Please wait.

Presentation is loading. Please wait.

Изкуствен интелект Изкуствен интелект Упражнение № 9 спец. Информатика, ФМИ 2004/2005.

Similar presentations


Presentation on theme: "Изкуствен интелект Изкуствен интелект Упражнение № 9 спец. Информатика, ФМИ 2004/2005."— Presentation transcript:

1 Изкуствен интелект Изкуствен интелект Упражнение № 9 спец. Информатика, ФМИ 2004/2005

2 Формална граматика  букви  правила  лексикон - списък от думи групирани в категории (части на речта):  отворени класове съществителнo (noun,pronoun) глагол (verb) прилагателно (adjective)  затворени класове определителeн член (a definite article, determiner) предлог (preposition) съюз (conjunction) наречие (adverb)

3 Формална граматика  нетерминални символи  S (sentence)  NP (noun phrase)  VP (verb phrase)  PP (prepositional phrase)  RelClause (relative clause)

4 Формална граматика S  NP VP S  S Conjunction S NP  Pronoun NP  Noun NP  Det Noun NP  NP PP NP  NP RelClause

5 Формална граматика VP  Verb VP  VP NP VP  VP Adjective VP  VP PP VP  VP Adverb PP  Preposition NP RelClause  that VP

6 Обработка на естествен език  Синтактичен анализ (syntactic analysis, parsing)  Семантичен анализ (semantic analysis)

7 Основни алгоритми за синтактичен анализ Top-down parsing  Отгоре надолу ( Top-down parsing ) Bottom-up parsing  Отдолу нагоре ( Bottom-up parsing )

8 Отдолу нагоре ( Bottom-up parsing) the cat is dead Det Det cat is dead(Det->the) Det Noun Det Noun is dead(Noun->cat) NP NP is dead(NP -> Det Noun) NP Verb NP Verb dead(Verb->is) NP Verb Adj NP Verb Adj(Adj->dead) NP VP NP VP(VP-> Verb Adj) S S(S-> NP VP)

9 Отгоре надолу ( Top-down parsing) S NP VP NP VP(S-> NP VP) Det Noun VP Det Noun VP(NP -> Det Noun) Noun VP the Noun VP (Det->the) VP the cat VP (Noun->cat) Verb Adj the cat Verb Adj (VP-> Verb Adj) Adj the cat is Adj (Verb->is) the cat is dead(Adj->dead)

10 S NPVP DetNounVerbAdj Thedeadiscat

11 S NPVP DetNounVerbAdj Thebigisdog

12 Отгоре надолу det([the]).det([a]).noun([cat]).noun([dog]).verb([is]).adj([big]).adj([dead]).

13 Недетерминиран append append([X|Y],Z,[X|L]):-append(Y,Z,L).append([],X,X):-!.

14 sentence(S):-append(NP,VP,S),np(NP),vp(VP).

15 np(NP):-append(Det,Noun,NP),det(Det),noun(Noun),write(det=Det),nl,write(noun=Noun),nl.

16 vp(VP):-append(Verb,Adj,VP),verb(Verb),adj(Adj),write(verb=Verb),nl,write(adj=Adj),nl.

17 Пример | ?- sentence([the,cat,is,dead]). det=[the]noun=[cat]verb=[is]adj=[dead]yes

18 S ProN VP Verb NP PP saw PPNounDet NP NounDet Prep NP NounDet Prep Ithe man on the telescopethe withhill

19 S ProN VP Verb NP PP saw PP NounDet NP NounDet Prep NP NounDet Prep Ithe man on the telescopethe withhill

20 sentence --> noun_phrase verb_phrase noun_phrase --> determiner noun rel_clause noun_phrase --> proper_noun verb_phrase --> trans_verb noun_phrase verb_phrase --> intrans_verb rel_clause --> that verb_phrase rel_clause --> or verb_phrase rel_clause -->

21 determiner --> every determiner --> a noun --> man noun --> woman noun --> student proper_noun --> john proper_noun --> mary trans_verb --> loves trans_verb --> is trans_verb --> lives

22 Отдолу нагоре % noun(Sentence,Rest,Var,LF) noun([man|Rest],Rest,X,man(X)). noun([woman|Rest],Rest,X,woman(X)). noun([student|Rest],Rest,X,student(X)). % proper_noun(Sentence,Rest,LF) proper_noun([john|Rest],Rest,john). proper_noun([mary|Rest],Rest,mary).

23 % trans_verb(Sentence,Rest,Var1,Var2,LF) trans_verb([loves|Rest],Rest,X,Y,loves(X,Y)). trans_verb([is|Rest],Rest,X,Y,is_a(X,Y)). % intrans_verb(Sentence,Rest,Var,LF) intrans_verb([lives|Rest],Rest,X,lives(X)).

24 :-op(800,xfy,#).:-op(700,xfy,&). rel_clause([that|Rest1],Rest,X,N_LF,(N_LF & VP_LF)):- verb_phrase(Rest1,Rest,X,VP_LF). verb_phrase(Rest1,Rest,X,VP_LF). rel_clause([or|Rest1],Rest,X,N_LF,(N_LF # VP_LF)):- verb_phrase(Rest1,Rest,X,VP_LF). verb_phrase(Rest1,Rest,X,VP_LF). determiner([every|Rest],Rest,X, R_LF,V_LF,all(X,(R_LF -> V_LF))). determiner([a|Rest],Rest,X, R_LF,V_LF,exists(X,(R_LF & V_LF))).

25 sentence(S,Rest,LF) :- noun_phrase(S,NPRest,X,VP_LF,LF), noun_phrase(S,NPRest,X,VP_LF,LF), verb_phrase(NPRest,Rest,X,VP_LF). verb_phrase(NPRest,Rest,X,VP_LF). noun_phrase(S,Rest,X,VP_LF,VP_LF) :- proper_noun(S,Rest,X). proper_noun(S,Rest,X). noun_phrase(S,Rest,X,VP_LF,LF) :- determiner(S,DRest,X,R_LF,VP_LF,LF), determiner(S,DRest,X,R_LF,VP_LF,LF), noun(DRest,NRest,X,N_LF), noun(DRest,NRest,X,N_LF), rel_clause(NRest,Rest,X,N_LF,R_LF). rel_clause(NRest,Rest,X,N_LF,R_LF).

26 verb_phrase(S,Rest,X,LF) :- trans_verb(S,VRest,X,Y,V_LF), trans_verb(S,VRest,X,Y,V_LF), noun_phrase(VRest,Rest,Y,V_LF,LF). noun_phrase(VRest,Rest,Y,V_LF,LF). verb_phrase(S,Rest,X,LF) :- intrans_verb(S,Rest,X,LF). intrans_verb(S,Rest,X,LF). rel_clause(S,S,_,LF,LF).

27 Пример | ?- sentence([a,man,loves,a,woman],Rest,LF). Rest = [], LF = exists(_A, man(_A)& exists(_B, woman(_B)&loves(_A,_B))) ? woman(_B)&loves(_A,_B))) ? yes yes | ?- sentence([john,loves,mary],Rest,LF). Rest = [], LF = loves(john,mary) ?

28 Пример |?-sentence([every,man,that,lives,loves,a,woman], Rest,LF). Rest = [], LF = all(_A,(man(_A)&lives(_A)-> exists(_B,woman(_B)&loves(_A,_B))))


Download ppt "Изкуствен интелект Изкуствен интелект Упражнение № 9 спец. Информатика, ФМИ 2004/2005."

Similar presentations


Ads by Google