Yalnız Mesajı Göster

Cevap : Prolog Örnekleri | Prolog Examples

Eski 04-07-2009   #9
[KAPLAN]
Varsayılan

Cevap : Prolog Örnekleri | Prolog Examples



Program 93 - a DCG and associated code to interface with the inference maker


Grammar and dictionary describe some family relations of the Tudor kings and queens of England
The top-level predicate is run Valid sentences include:
  • [henry8, is, male]
  • [catherine_of_aragon, is, female]
  • [henry8, is, a, parent, of, mary]
  • [catherine_of_aragon, is, a, parent, of, mary]
  • etc
To stop the program, enter [stop]


s(_, _) -->
[stop],
{ abort }

s(s(NP, VP), VP_Sem) -->
np(NP, NP_Sem),
vp(VP, VP_Sem, NP_Sem)

np(propn('Henry VII'), 'Henry VII') -->
[henry7]
np(propn('Henry VIII'), 'Henry VIII') -->
[henry8]
np(propn('Elizabeth of York'), 'Elizabeth of York') -->
[elizabeth_of_york]
np(propn('Catherine of Aragon'), 'Catherine of Aragon') -->
[catherine_of_aragon]
np(propn('Ann Boleyn'), 'Ann Boleyn') -->
[ann_boleyn]
np(propn('Jane Seymour'), 'Jane Seymour') -->
[jane]
np(propn('Anne of Cleeves'), 'Anne of Cleves') -->
[ann_of_cleeves]
np(propn('Catherine Howard'), 'Catherine Howard') -->
[catherine_howard]
np(propn('Catherine Parr'), 'Catherine Parr') -->
[catherine_parr]
np(propn('Edward VI'), 'Edward VI') -->
[edward]
np(propn('Mary Tudor'), 'Mary') -->
[mary]
np(propn('Elizabeth I'), 'Elizabeth I') -->
[elizabeth]

np(np(Det, Noun), Sem) -->
det(Det),
noun(Noun, Sem)

pp(pp(Prep, NP), Sem) -->
prep(Prep),
np(NP, Sem)

vp(vp(is, Adj_P), Sem, Agent) -->
[is],
adj_phrase(Adj_P, Sem),
{ functor(Sem, _, 1),
arg(1, Sem, Agent) }

vp(vp(is, NP, PP), Sem, Agent) -->
[is],
np(NP, Sem),
pp(PP, Patient),
{ functor(Sem, _, 2),
arg(1, Sem, Agent),
arg(2, Sem, Patient) }

adj_phrase(adj_p(NP), Sem) -->
np(NP, Sem)
adj_phrase(adj_p(Adj), Sem) -->
adj(Adj, Sem)

adj(adj(female), female(_)) -->
[female]
adj(adj(male), male(_)) -->
[male]

det(det(a)) -->
[a]
det(det(the)) -->
[the]

noun(noun(parent), parent(_, _)) -->
[parent]

prep(prep(of)) -->
[of]

run :-
write('Input text: '),
read(Text),
nl,
s(Tree, Sem, Text, []),
write('Syntax: '),
write(Tree),
nl,
write('Semantics: '),
write(Sem),
nl,
add(Sem, 'user input'),
nl,
run


Program 94 - code for running pre-prepared examples and two examples


The examples are based on the family relations of the Tudor kings and queens of England No guarantee is given of accuracy as the examples have been devised from memory - in the absence of a suitable family tree
The top-level predicate is run/1where the argument is the identifier of a group of queries, eg:
  • | ?- run(1)

run(Text) :-
write('Input text: '),
write(Text),
nl,
s(Tree, Sem, Text, []),
tab(5),
write('Syntax: '),
write(Tree),
nl,
tab(5),
write('Semantics: '),
write(Sem),
nl,
add(Sem, 'user input'),
nl

example(Corpus) :-
findall(Text, text(Corpus, Text), Texts),
process_texts(Texts)

process_texts([])
process_texts([Head|Tail]) :-
run(Head),
process_texts(Tail)

text(1, [henry8, is, male])
text(1, [henry8, is, a, parent, of, mary])

text(2, [henry8, is, male])
text(2, [catherine_of_aragon, is, female])
text(2, [ann_boleyn, is, female])
text(2, [catherine_parr, is, female])
text(2, [elizabeth, is, female])
text(2, [mary, is, female])
text(2, [edward, is, male])
text(2, [henry8, is, a, parent, of, mary])
text(2, [henry8, is, a, parent, of, elizabeth])
text(2, [henry8, is, a, parent, of, edward])
text(2, [catherine_of_aragon, is, a, parent, of, mary])
text(2, [ann_boleyn, is, a, parent, of, elizabeth])
text(2, [catherine_parr, is, a, parent, of, edward])

Alıntı Yaparak Cevapla