belkajm sent me a great bit of code to handle the unification problem in AI::Perlog, of which you can download the latest copy at this link. Unfortunately, belkajm didn't make his post a root node, which I think it should have been because it was a very well-explained solution to the problem. Go vote for it :)

To show how interesting this is (to me, at least), consider the problem listed in Who's a thief?. The code I have below solves the listed problem. You can compare this to code in AI in Perl - proof of concept. That code is much clumsier, less scalable, and not as easy to modify.

Also, I want to take a closer look at the code that arhuman put together in AI::Perlog(2) unification proposition and an explanatory follow-up. It has some interesting features that I hadn't considered, but also haven't had the time to delve into. All in all, I have to say "thanks" to both arhuman and belkajm for their help and am looking forward to seeing more.

Enjoy!

#!/usr/bin/perl -w use strict; use AI::Perlog; my $pg = AI::Perlog->new; load_data(); my $acts_of_horror = who_steals_from_whom(); unless ( @$acts_of_horror ) { print "Looks like everybody's safe\n"; } else { foreach my $crime ( @$acts_of_horror ) { my ( $thief, $victim ) = @$crime; print "$thief will steal from $victim.\n"; } } exit; sub who_steals_from_whom { my $thieves = $pg->thief( '$person' ); my $victims = $pg->owns( qw/ $person _ / ); my @crimes; foreach my $victim ( @$victims ) { my $curr_victim = $victim->{person}; foreach my $thief ( @$thieves ) { my $curr_thief = $thief->{person}; if (rich($curr_victim) and ! $pg->knows($curr_thief,$curr_ +victim)){ push @crimes => [$curr_thief, $curr_victim]; } } } return \@crimes; } sub rich { my $person = shift; my $items = $pg->owns( $person, '$item' ); local $_; foreach ( @$items ) { return 1 if $pg->valuable( $_->{ item } ); } return; } sub load_data { while ( <DATA> ) { chomp; next if ( ! $_ or substr( $_, 0, 1 ) eq '#' ); my @fact = split /\t/; $pg->add_fact( @fact ); } } __DATA__ owns merlyn gold owns Ovid pocket lint owns Ovid cheap whiskey owns kudra domination fund valuable gold valuable domination fund thief badguy thief badgirl # :) knows badgirl merlyn

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to AI::Perlog - more thieves by Ovid

Title:
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, details, 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, summary, 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.