Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

This is just a little follow-up note to those who wondered what ever happened to my work with AI in Perl. This is part of it. (And it's cross-posted from my use.perl journal.)

OK, I finally got off my butt and checked Language::Prolog::Yaswi. The docs need some work and it helps if you know Prolog, and if you use a 5.1 or 5.2 version SWI-Prolog (compiled with thread support: ./configure --enable-mt) and a version of Perl compiled with ithreads. However, if you jump through all of those hoops, you can figure out Who's a thief?.

steals(PERP, STUFF) :- thief(PERP), valuable(STUFF), owns(VICTIM,STUFF), not(knows(PERP,VICTIM)). thief(badguy). valuable(gold). valuable(rubies). owns(merlyn,gold). owns(ovid,rubies). knows(badguy,merlyn).

In short, I finally admitted defeat and have stopped trying to do predicate logic in pure Perl. Implementing a predicate logic engine in pure Perl that is easy to use and extensible involves understanding streams, patterns, a pattern matcher and generating arbitrary streams from complex data structure and handling unification without the benefit of tail call recursion optimizations. In short, to fully enjoy the First Order Predicate Calculus in pure Perl involves writing an NFA regex engine that operates on data structures instead of strings.

I am not that smart.

I went ahead and used the SWI-Prolog version. And it works :)

#!/usr/local/bin/perl use strict; use warnings; use Language::Prolog::Yaswi qw/:query :assert/; use Language::Prolog::Types::overload; use Language::Prolog::Sugar functors => [qw/steals thief valuable owns knows/], functors => { NOT => 'not' }, # BUGFIX: this was in chains vars => [qw/PERP STUFF VICTIM/], chains => { AND => ',', }; swi_assert( steals(PERP, STUFF) => AND( valuable(STUFF), thief(PERP), owns(VICTIM, STUFF), NOT(knows(PERP, VICTIM)), )); swi_facts( thief('badguy'), valuable('gold'), valuable('rubies'), owns(qw/merlyn gold/), owns(qw/ovid rubies/), knows(qw/badguy merlyn/), ); swi_set_query(steals('badguy', STUFF)); while(swi_next) { print swi_var(STUFF), $/; }

Regrettably, this does not work with the latest version of SWI-Prolog, so be warned. I just emailed the author and hope to hear back soon on whether or not he plans an update.


New address of my CGI Course.

In reply to Who's a thief? -- the follow up by Ovid

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (4)
    As of 2019-10-19 01:43 GMT
    Find Nodes?
      Voting Booth?