DCG and ASSERTS in YieldProlog?

2007-05-14
2013-05-28
  • zendynamics
    zendynamics
    2007-05-14

    Hi,

    I was curious if anyone knew how to implement DCG with YieldProlog as well as Prolog assertions?

    Example... given the DCG grammar here....

    sentence -->
      subject,
      verb,
      object.

    subject -->
      modifier,
      noun.

    object -->
      modifier,
      noun.

    modifier --> [the].

    noun --> [cat].
    noun --> [mouse].
    noun --> [polar, bear].

    verb --> [chases].
    verb --> [eats].

    ... which translates to the expanded Prolog terms of...

    sentence(L1, L4) :-
      subject(L1, L2),
      verb(L2, L3),
      object(L3, L4).

    subject(L1, L3) :-
      modifier(L1, L2),
      noun(L2, L3).

    object(L1, L3) :-
      modifier(L1, L2),
      noun(L2, L3).

    modifier([the|X], X).
    noun([cat|X], X).
    noun([mouse|X], X).
    noun([polar,bear|X], X).
    verb([chases|X], X).
    verb([eats|X], X).

    .... One should be able to assert new facts derived by the understanding of the grammar and parts of speach.... such as...

    ?- assert( chases([cat], [mouse]) ).
    ?- assert( eats( [polar, bear], [cat]) ).

    Easy to do in Prolog... can't seem to figure out how to do it in YieldProlog.

    I have an english grammar/symantec analysis system written in Mercury Prolog, which has become bloated and super slow. Yeild prolog could help out alot, if I could figure out how to construct dynamic functors, without having to invoke some .NET reflection methods and/or dynamic .NET CLR compilations.

    Any help/advice/direction would be greatly appreciated.

    Thanks much in advance!

    - iM