I am trying to write a grammar for the English language in Prolog, with some basic rules, such as:
s --> np, vp.
np --> pn.
np --> det, noun.
pn --> [vincent].
pn --> [mia].
det --> [a].
I do understand how these work and how to query them using the phrase statement, but when it comes to rules like:
noun(X, woman(X)) --> [woman].
iv(Y, snort(Y)) --> [snorts].
I'm lost. What do these mean? Why is variable X repeated?
np --> det, noun.You should show the context where noun//2 is actually used... The X argument it's most likely a kind of lambda expression, it will 'transfer' semantic information among phrase' POS (part of speech). BTW you're not obliged to accept an answer, just because it has been posted, if it doesn't help you to understand your quest - CapelliCnoun(X, woman(X))it means that unification is occurring between all those variables labeledX. For example, if you had a rule,same(X, X).then queried,same(Foo, bar)you would get the solution,Foo = bar..noun(X, woman(X)) --> [woman].will only do this unfication ifwomanis seen in the input. This is very basic Prolog behavior. A study of introductory material on the Prolog language will provide more information. - lurkernoun --> [woman]will recognize thewomanin the input stream and that's all. It will collect no further information based upon that success.noun(X, woman(X))allows you to callnoun(A, B)and then ifwomanis seen on the input, you getB = woman(A). That's a bit abstract I realize, but I have no other context of your problem to know why that's of value in this case, but it is evidently useful in the broader scope of the code you're looking for. You need to check contexts in the code that callnoun(...)to see what it does with those arguments. - lurker