I am studying DCG grammars and parse trees in Prolog using Ivan Bratko’s Programming for Artificial Intelligence. In a program that uses a DCG grammar to extrapolate the meaning of a sentence, I find these two predicates that, I think, represent a kind of semantic knowledge:
properName(john) --> [john].
properName(mary) --> [mary].
How should I read these predicates? I am thinking that they mean: it is true that an element of a list represented by the string “john” is a proper name and this proper name is John (same thing for Mary).
Is it my reading correct or are there some other implications?
2
Answers
This is a trivial predicate that does not lend itself to interpretation outside of the context in which it is used.
In other words, it can only be used to demand that a proper name is used in a certain way, by a DCG rule that uses it on its right-hand side. The way you have shown it, in isolation, it means nothing more than:
EDIT
I might be wrong here, but you are still abusing the English language to describe things that are best described using a formal language. Prolog is a formal language, with a defined syntax and semantics. It can be used to formally describe logical relationships, or computation. Trying to faithfully translate it into English is bound to be clumsy and unnecessary. Something as trivial as the predicate in your question turns into something that is silly, difficult to understand, and difficult to work with.
P.S. The correct spelling of the word you like so much is representation.
properName(X)
is just an unary rule (in the context of DCG; it is a ternary predicate in Prolog – check it out with?- listing(properName)
). you could’ve called it “socks”, or “jam”, it’s totally up to you. So the semantic knowledge about it representing proper name “john” or “mary” is nowhere to be found in the code (it uses naming as self-documenting feature, but documentation is not code).The predicate allows for an atom
john
ormary
to be present in the input stream, and nothing else; and demands thatX
unified with that atom.You could’ve defined it thus:
then,