| RDF-AllegroGraph-Easy documentation | Contained in the RDF-AllegroGraph-Easy distribution. |
RDF::AllegroGraph::Session4 - AllegroGraph session handle for AGv4
$pong = $session->ping
This method will keep the "connection" with the HTTP server alive (it probably resets the
timeout). In the regular case it should return pong, in the error case it will time out.
$session->rules (" .... prolog rules encoded in LISP, brr ...")
This method parks additional ontological knowledge as rules onto the server. If they can be parsed correctly, they will be used with the onboard PROLOG reasoner. See the Franz Prolog tutorial (./doc/prolog-tutorial.html) for details.
This method creates one generator, in the AGv4 sense. As parameter you have to pass in
A symbol, just a simple string, probably better without any fancy characters.
Here you name various predicates (full URIs, no namespaces seem to work) and also whether these edges should be followed
forward direction, orreverse direction (inverseOf in the OWL sense), orbidirectionalExample:
$session->generator ('associates',
{ '<http://www.franz.com/lesmis#knows_well>' => 'bidirectional',
'<http://www.franz.com/lesmis#knows>' => 'bidirectional' }
);
While all of the following can be (and actually are) emulated via generator and prolog
invocations, you might find the following handy:
@members = $session->SNA_members ($start_node, { generator specification })
This method returns the member nodes which can be reached when starting at a particular node and
when particular edges are followed. That edge specification is the same as for the method
generator.
NOTE: Internally an SNA generator is created and - using this method - it will be always overwritten. So, if you need to query this heavily, it is better to fall back to the low-level generator method and use that instead of a full specification:
$session->generator ('intimates',
{ '<http://www.franz.com/lesmis#knows_well>' => 'bidirectional' });
@ms = $session->SNA_members ('<where-to-start>', 'intimates');
@cliques = $session->SNA_cliques ($node, $generator)
This method returns a list of list references to the cliques the node is part of. The generator can
again be one predefined (see generator), or an adhoc one (see SNA_members).
Robert Barta, <rho at devc.at>
Copyright 2011 Robert Barta, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| RDF-AllegroGraph-Easy documentation | Contained in the RDF-AllegroGraph-Easy distribution. |
package RDF::AllegroGraph::Session4; use strict; use warnings; use base qw(RDF::AllegroGraph::Repository4); use Data::Dumper; use feature "switch"; use JSON; use URI::Escape qw/uri_escape_utf8/; use HTTP::Request::Common;
sub new { my $class = shift; return bless { @_ }, $class; }
sub ping { my $self = shift; my $resp = $self->{CATALOG}->{SERVER}->{ua}->get ($self->{path} . '/session/ping'); die "protocol error: ".$resp->status_line.' ('.$resp->content.')' unless $resp->is_success; my $result = $resp->content; $result =~ s/^\"//; $result =~ s/\"$//; return $result; }
sub rules { my $self = shift; my $lisp = shift; my $resp = $self->{CATALOG}->{SERVER}->{ua}->post ($self->{path} . '/functor', 'Content-Type' => 'text/plain', 'Content' => $lisp); die "protocol error: ".$resp->status_line.' ('.$resp->content.')' unless $resp->is_success; }
sub generator { my $self = shift; my $symbol = shift; my $spec = shift; my @bidirectional; my @forward; my @reverse; foreach my $pred (keys %$spec) { given ($spec->{$pred}) { when ('bidirectional') { push @bidirectional, $pred; } when ('forward') { push @forward, $pred; } when ('reverse') { push @reverse, $pred; } } } # warn Dumper \@undirected; my $url = new URI ($self->{path} . '/snaGenerators/' . $symbol); $url->query_form ( (@bidirectional ? (undirected => \@bidirectional) : ()), (@forward ? (objectOf => \@forward) : ()), (@reverse ? (subjectOf => \@reverse) : ()), ); my $resp = $self->{CATALOG}->{SERVER}->{ua}->request (PUT $url); die "protocol error: ".$resp->status_line.' ('.$resp->content.')' unless $resp->is_success; }
our $adhoc = 'zwumpelfax'; # you may change it, but under what circumstances, really? sub _linkage { my $self = shift; my $spec = shift; if (ref ($spec) eq 'HASH') { my $linkage = $adhoc; $self->generator ($linkage, $spec); return $linkage; } else { return $spec; # it is already a string } } sub SNA_members { my $self = shift; my $start = shift; my $spec = shift; my $linkage = _linkage ($self, $spec); my @ss = $self->prolog (qq{ (select (?member) (ego-group-member !$start 1 $linkage ?member) ) }); # warn Dumper \@ss; return map {$_->[0] } @ss; } sub SNA_ego_group { my $self = shift; my $start = shift; my $spec = shift; my $depth = shift; return (); } sub SNA_path { my $self = shift; my $start = shift; my $stop = shift; my $spec = shift; my $depth = shift; my $linkage = _linkage ($self, $spec); my @ss = $self->prolog (qq{ (select (?path) (breadth-first-search-path !$start !$stop $linkage $depth ?path)) }); warn "ss ". Dumper \@ss; return map { $_->[0] } @ss; } # strategy : breadth_first, depth_first, bidirectional sub SNA_nodal_degree { my $self = shift; my $node = shift; my $spec = shift; } sub SNA_nodal_neighbors { my $self = shift; my $node = shift; my $spec = shift; }
sub SNA_cliques { my $self = shift; my $node = shift; my $spec = shift; my $linkage = _linkage ($self, $spec); my @ss = $self->prolog (qq{ (select (?clique) (clique !$node $linkage ?clique)) }); # warn Dumper \@ss; return map { $_->[0] } @ss; } sub SNA_actor_degree_centrality { } sub SNA_actor_closeness_centrality { } sub SNA_actor_betweeness_centrality { } sub SNA_group_degree_centrality { } sub SNA_group_closeness_centrality { } sub SNA_group_betweeness_centrality { }
our $VERSION = '0.03'; 1; __END__