1 / 28

Изкуствен интелект Упражнение № 9

Изкуствен интелект Упражнение № 9. спец. Информатика, ФМИ 200 4 /200 5. Формална граматика. букви правила лексикон - списък от думи групирани в категории (части на речта) : отворени класове съществителн o ( noun,pronoun) глагол (verb) прилагателно (adjective) затворени класове

Download Presentation

Изкуствен интелект Упражнение № 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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) • Отдолу нагоре (Bottom-upparsing)

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

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

  10. S NP VP Det Noun Verb Adj The cat is dead

  11. S NP VP Det Noun Verb Adj The dog is big

  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 Prep NP Det Noun PP NP Det Noun Prep Det Noun I saw on the the telescope the man hill with

  19. S ProN VP Verb NP PP PP Prep NP Det Noun NP Prep Det Noun Det Noun I saw on the the telescope the man hill with

  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). rel_clause([or|Rest1],Rest,X,N_LF,(N_LF # 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), verb_phrase(NPRest,Rest,X,VP_LF). noun_phrase(S,Rest,X,VP_LF,VP_LF) :- proper_noun(S,Rest,X). noun_phrase(S,Rest,X,VP_LF,LF) :- determiner(S,DRest,X,R_LF,VP_LF,LF), noun(DRest,NRest,X,N_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), noun_phrase(VRest,Rest,Y,V_LF,LF). verb_phrase(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))) ? 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))))

More Related