I decided to work on my logic programming module again today. I've eradicated lots of bugs (and probably found lots more). Here's a basic demo:
use AI::Perlog ':all'; my $data = AI::Perlog->new( { predicates => [qw/beautiful likes shiny/] } ); $data->add_facts( [qw/ beautiful people /], [qw/ shiny Firefly /], [qw/ shiny Kaylee /], [qw/ likes ovid whiskey /], [qw/ likes andy whiskey /], ); # declare a logic variable var my $stuff; $data->add_rules( rule( 'likes', 'ovid', $stuff ) ->if( [ 'shiny', $stuff ] ), ); var my $what; my $results = $data->query( 'likes', 'ovid', $what ); while ($results->next) { print 'Ovid likes ', $what->value, "\n"; } __END__ Ovid likes whiskey Ovid likes Firefly Ovid likes Kaylee
Note how we're pulling data not just from the fact that 'ovid likes whiskey', but also from the rule 'ovid likes shiny stuff' and both 'Firefly' and 'Kaylee' are shiny stuff. Making logical inferences like this is what logic programming is all about!
It's not even close to being releasable due to lots of bugs and no documentation, though. For example, the append/3 predicate is horribly broken and there are lots of problems with undefined variables. There also appear to be problems in the backtracking engine.
Re:RDF?
Ovid on 2008-05-19T06:35:53
Well, I've provided assert/1 and retract/1 predicates for AI::Prolog, so it I don't think that should be too difficult, so yeah, an iterator sounds pretty simple. But I'd only do that if you really need RDF. As cool as it is, being limited to triples and having no interesting data structures seems pretty limiting (though it does seem appropriate for the problem space).