Accessing dictionary

Hi guys,

I’m new and playing with Prolog and dcg. I have the following question though. Hope you can help.

I have the following:

word(book,_{grammar:noun, number:singular}) --> [book].
noun(X) :- word(X,Dict,[X|R],[R]), get_dict(grammar,Dict,noun).

?- noun(X).
X = book 

works fine, but I can’t really ‘access’ the dictionary. Here is an example:

?- noun(X), writeln(Dict).
X = book

How can I get _{grammar:noun, number:singular} ?

Thank you!

Add predicate

noun(X,Dict) :- word(X,Dict,[X|R],[R]), get_dict(grammar,Dict,noun).

Example run

?- noun(Noun,Dict).
Noun = book,
Dict = _60932{grammar:noun, number:singular}.


One common idiom is to separate the noun DCG rule from the noun facts. You can also make multiple versions of the predicates, depending on whether you want the extra information or not:

noun(X) --> noun(X, _).
noun(X, Dict) --> { noun_lookup(X, Dict) }.
noun_lookup(X, Dict) :- word(X, Dict), get_dict(grammar, Dict, noun).
word(book, word{grammar:noun, number:singular}).
word(books, word{grammar:noun, number:plural}).
word(read, word{grammar:verb, tense:present, person:first, number:singular}).
word(read, word{grammar:verb, tense:simple_past, person:any, number:any}).

Thanks a lot guys!
@peter.ludemann - that’s very helpful, thank you!