1

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?

false
  • 10,264
  • 13
  • 101
  • 209
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
  • The grammar from the book doesn't seem to be online (e.g,. a Google Books preview), but more of the grammar is shown in [this question](http://stackoverflow.com/q/16674593/1281433), for those who are interested. – Joshua Taylor Sep 26 '13 at 19:55

2 Answers2

2

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:

'john' is a proper name, and so is 'mary'.

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.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
  • 1
    English reading is a habit I encourage, but I agree with you that Andrea has taken it too far. The point I tried (and failed, apparently) to make is simply that it is wrong and unhelpful to try to read Prolog imperatively like C or Python. English is a decent declarative "target," but not a great one; Prolog is best read as Prolog alone. – Daniel Lyons May 17 '13 at 15:36
2

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 or mary to be present in the input stream, and nothing else; and demands that X unified with that atom.

You could've defined it thus:

name(X) --> [X], { member(X, [john, mary]) }.

then,

4 ?- phrase( name(X), [john,jack], Z).
X = john,
Z = [jack] ;
false.

5 ?- phrase( name(X), [jack,john], Z).
false.

8 ?- phrase( name(X), [john,mary], Z).
X = john,
Z = [mary] ;
false.

9 ?- phrase( name(X), [mary,john,jack], Z).
X = mary,
Z = [john, jack].

11 ?- phrase( name(jack), [jack,mary,john], Z).
false.
Will Ness
  • 70,110
  • 9
  • 98
  • 181
  • Ok, this is quite more clear for me. I the following doubt: when, in the Prolog shell, you execute the command: phrase(name(X), [john,jack], Z). What exactly rappresent phrase predicate? Looking at it I think that it is a predicate that rappresent a phrase that is composed only by a noun (that have to be in the [john,mary] list. Is it something like if, in my DCG grammar, I have something like: phrase(X) --> name(X) (or something like it) ? – AndreaNobili May 18 '13 at 14:54
  • @AndreaNobili [`phrase/3`](http://www.swi-prolog.org/pldoc/man?predicate=phrase%2F3) is just **a built-in predicate** to call a certain DCG rule on an input. Also, try `1 ?- apropos(phrase).` in your SWI-Prolog console. `name` is exactly the same as your `properName`. Try it: `?- phrase( properName(X), [john,mary,jack],Z).`, or `?- phrase( properName(john), [john,mary,jack],Z).` etc. – Will Ness May 18 '13 at 21:20
  • @AndreaNobili you can try `?- listing(phrase).` to see its definition. – Will Ness May 19 '13 at 06:35
  • mmm I have not phrase predicate definied in my code (I call it in the Prolog shell and if I listing it I obtain: ?- listing(phrase). :- meta_predicate phrase(2,?). phrase(A, B) :- phrase(A, B, []). :- meta_predicate phrase(2,?,?). phrase(A, D, F) :- strip_module(A, C, B), ( var(B) -> throw(error(instantiation_error, _)) ; true ), '$t_body'(B, C:C, E, G, H), D=E, F=G, call(C:H). true. :-/ – AndreaNobili May 19 '13 at 10:49
  • 1
    @AndreaNobili right. it's [**a built-in predicate**.](http://www.swi-prolog.org/pldoc/man?predicate=phrase%2F3). Click that link. :) – Will Ness May 19 '13 at 11:21