-
Notifications
You must be signed in to change notification settings - Fork 1
swh/Perl-SPARQL-client-library
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About This module is an implementation of the SPARQL protocol and result format with minimal dependencies. Specifically it should be possible to run this module using only packages provided by your distribution, making it suitable for corporate environments. The dependencies are: LWP::UserAgent LWP::ConnCache URI::Escape XML::Simple This module will also use Keepalive HTTP Connections where possible. Usage use sparql; my $sparql = sparql->new(); my $res = $sparql->query('http://dbpedia.org/sparql', 'SELECT * WHERE { ?s ?p ?o } LIMIT 10'); for my $row (@{$res}) { for my $col (keys %{$row}) { print('?'.$col.' = '.$row->{$col}."\n"); } print("\n"); } Methods new() Returns a SPARQL client object. query(endpoint, query string) Takes and endpoint URI, and a query, and returns a reference to an array of hashes, for SELECT, and a string for CONSTRUCT etc. Each element in the array (a hash) is a solution, the keys of the hash are the variable name (without the ? or $), and the value is a Turtle literal representing the result value. update(endpoint, update string) Takes an endpoint URI, and a query, and returns a string of the returned message. put(endpoint, graph uri, mime type, RDF text) Takes an endpoint URI, and graph to write to, a MIME type and some RDF data, and writes the data into the graph at the endpoint. Example: $sparql->put('http://host.example/data', 'http://mygraph.example/data.rdf', 'text/turtle', "<s> <p> <o> .\n"); Returns whatever text the endpoint returns as a result. chomp(turtle literal) Removes any Turtle-style gubbins from around a returned value, e.g. '"foo"' -> 'foo', '<http://example.com/>' -> 'http://example.com/'. print(result) Formats query a result object and prints it to STDOUT. Licence The sparql.pm module itsself is licenced under the Lesser GPL, version 3+, and the example code is 2-clause BSD.
About
A simple Perl library for accessing SPARQL endpoints.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published