| 1 | package RDF::Redland::DIG; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 0 | ▶ | use RDF::Redland::DIG::KB; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 7 | |||
| 8 | use constant GETID_REQ => q|<?xml version="1.0"?> | ||
| 9 | <getIdentifier xmlns="http://dl.kr.org/dig/2003/02/lang" | ||
| 10 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" /> | ||
| 11 | |; | ||
| 12 | |||
| 13 | =pod | ||
| 14 | |||
| 15 | =head1 NAME | ||
| 16 | |||
| 17 | RDF::Redland::DIG - DIG extension for Redland RDF (Reasoner) | ||
| 18 | |||
| 19 | =head1 SYNOPSIS | ||
| 20 | |||
| 21 | my $model = new RDF::Redland::Model .... | ||
| 22 | |||
| 23 | use RDF::Redland::DIG; | ||
| 24 | my $r = new RDF::Redland::DIG (url => http://localhost:8081/); | ||
| 25 | |||
| 26 | use RDF::Redland::DIG::KB; | ||
| 27 | my $kb = $r->kb; # create an empty knowledge base there | ||
| 28 | eval { | ||
| 29 | $kb->tell ($model); | ||
| 30 | }; die $@ if $@; | ||
| 31 | |||
| 32 | my %children = $kb->children ('urn:pizza', 'urn:topping'); | ||
| 33 | # see RDF::Redland::DIG::KB | ||
| 34 | |||
| 35 | =head1 DESCRIPTION | ||
| 36 | |||
| 37 | Instances of this class represent a handle to a remote instance of a DIG reasoner. | ||
| 38 | |||
| 39 | DIG is a protocol which applications can use to use reasoning services provided by such a reasoner. | ||
| 40 | |||
| 41 | http://dl-web.man.ac.uk/dig/ | ||
| 42 | |||
| 43 | =head1 INTERFACE | ||
| 44 | |||
| 45 | =head2 Constructor | ||
| 46 | |||
| 47 | The constructor connects an in-memory object with a remote instance of a DIG reasoner. The only | ||
| 48 | mandatory parameter is the URL to address the reasoner. | ||
| 49 | |||
| 50 | Optionally the following fields are processed: | ||
| 51 | |||
| 52 | =over | ||
| 53 | |||
| 54 | =item C<ua> (default: L<LWP::UserAgent>) | ||
| 55 | |||
| 56 | Here you can pass in your custom made HTTP client. Must subclass L<LWP::UserAgent>. | ||
| 57 | |||
| 58 | =back | ||
| 59 | |||
| 60 | =cut | ||
| 61 | |||
| 62 | sub new { | ||
| 63 | my $class = shift; | ||
| 64 | my $url = shift; | ||
| 65 | my %options = @_; | ||
| 66 | $options{url} = $url or die "no URL provided to contact DIG reasoner"; | ||
| 67 | |||
| 68 | unless ($options{ua}) { | ||
| 69 | use LWP::UserAgent; | ||
| 70 | $options{ua} = LWP::UserAgent->new; | ||
| 71 | $options{ua}->agent ('Redland DIG Client'); | ||
| 72 | } | ||
| 73 | |||
| 74 | my $req = HTTP::Request->new(POST => $options{url}); | ||
| 75 | $req->content_type('text/xml'); | ||
| 76 | $req->content(GETID_REQ); | ||
| 77 | |||
| 78 | # Pass request to the user agent and get a response back | ||
| 79 | my $res = $options{ua}->request ($req); | ||
| 80 | |||
| 81 | # Check the outcome of the response | ||
| 82 | die "reasoner could not be contacted at $options{url}" unless $res->is_success; | ||
| 83 | |||
| 84 | return bless \ %options, $class; | ||
| 85 | } | ||
| 86 | |||
| 87 | =pod | ||
| 88 | |||
| 89 | =head2 Methods | ||
| 90 | |||
| 91 | =over | ||
| 92 | |||
| 93 | =item B<kb> | ||
| 94 | |||
| 95 | This method clones one knowledge base from the reasoner. You can have any number of these. | ||
| 96 | |||
| 97 | =cut | ||
| 98 | |||
| 99 | sub kb { | ||
| 100 | my $self = shift; | ||
| 101 | return new RDF::Redland::DIG::KB ($self); | ||
| 102 | } | ||
| 103 | |||
| 104 | =pod | ||
| 105 | |||
| 106 | =back | ||
| 107 | |||
| 108 | =head1 COPYRIGHT AND LICENCE | ||
| 109 | |||
| 110 | Copyright 2008 by Lara Spendier and Robert Barta | ||
| 111 | |||
| 112 | This library is free software; you can redistribute it and/or modify it under the same terms as Perl | ||
| 113 | itself. | ||
| 114 | |||
| 115 | Work supported by the Austrian Research Centers Seibersdorf (Smart Systems). | ||
| 116 | |||
| 117 | =cut | ||
| 118 | |||
| 119 | our $VERSION = 0.04; | ||
| 120 | |||
| 121 | 1; | ||
| 122 | |||