nlp in prolog - Blackburn & Bos 1999
Author Message nlp in prolog - Blackburn & Bos 1999

I'm studying Blackburn & Bos (1999) Representation and Inference for
Natural Language (www.comsem.org) and having trouble w/exercise 1.2.3 on
page 17. I'm learning prolog at the same time. I'd be grateful for a
critique of my inelegant solution to the first half of the question, and a
hint for the second half!

Let a vocabulary be defined by the predicates relation/2 - relation(rel,
arity) means 'rel' is a two-place relation in our vocabulary - and
constant/1 - constant(c) means 'c' is a constant in our vocabulary.

Let a model be represented by a list of relations over the vocabulary.
(I omit the proper set-theoretic definition of model and exact model here.
Doesn't affect the exercise.)

From B&B - "Write a prolog program which when given a vocabulary and a
list, determines whether or not the list represents an (exact) model over
that vocabulary. Can your program be used to generate all the exact models
over that vocabulary? If not, write a program that can."

Example Vocabulary (from B&B)

relation(loves,2).       constant(mia).
relation(hates,2).       constant(vincent).
relation(customer,1).    constant(honey-bunny).
relation(robber,1).      constant(pumpkin).

Example of a model

[customer(mia), loves(mia, vincent)]

My solution to the first half:

exact_model([]).
exact_model([H|T]) :-
exact_model_term(H),
exact_model(T).

exact_model_term(Term) :-
functor(Term, F, Arity),
Arity > 0,
relation(F, Arity),
Term =.. [F|Args],
exact_model(Args).
% cheat, args aren't a model, but have the
% same form, a list of terms over vocab

exact_model_term(Term) :-
functor(Term, F, Arity),
Arity == 0,
constant(F).

But of course, the univ operator (=..) at least means this program won't
work as a generator. Any hints? I don't think I'm supposed to consider
other representations of the vocabulary or model.

Thanks!!

dhf

Wed, 26 May 2004 00:49:14 GMT  nlp in prolog - Blackburn & Bos 1999

Quote:
> Let a model be represented by a list of relations over the vocabulary.

OK, depends how you want to represent those relations.

Quote:
> Example of a model

>     [customer(mia), loves(mia, vincent)]

Yes, but that gets you into (minor) trouble, as you realized.

Quote:
>     exact_model_term(Term) :-
>       functor(Term, F, Arity),
>       Arity > 0,
cut!
>       relation(F, Arity),
>       Term =.. [F|Args],
>       exact_model(Args).
>       % cheat, args aren't a model, but have the
>       % same form, a list of terms over vocab

>     exact_model_term(Term) :-
>       functor(Term, F, Arity),
>       Arity == 0,
>       constant(F).

> But of course, the univ operator (=..) at least means this program won't
> work as a generator. Any hints? I don't think I'm supposed to consider
> other representations of the vocabulary or model.

If you represent relations as pairs consisting of (the name of) a relation
followed by a list of constants, then everything becomes very simple.
Here's how you might do it in SWI-Prolog (which has a higher-order
predicate checklist/2):

exact_model(L) :-
checklist(exact_model_term, L).

exact_model_term(Fun-Args) :-
relation(Fun, Arity),
length(Args, Arity),
checklist(constant, Args).

Now you can enumerate lots of models by saying

:- length(M,_), exact_model(M).

The representation of the model can contain repeated occurrences of the
same term, e.g., [robbber-[vincent], robber-[vincent]].  Don't know if
you'd consider that a problem.

- martin

Sun, 30 May 2004 06:43:18 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages

Powered by phpBB® Forum Software