Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

trapper(1p) [debian man page]

TRAPPER(1p)						User Contributed Perl Documentation					       TRAPPER(1p)

NAME
trapper - command-line RDF parsing and serialising tool SYNOPSIS
trapper [options] INPUT-URI [INPUT-BASE-URI] Options: --input F, -i F Set the input format to F --input-uri U, -I U Alternative to INPUT-BASE-URI --output F, -o F Set the output format to F --count, -c Count triples only --quiet, -q No extra information messages --help, -h Show this help --version, -v Show module versions Input formats: rdfxml, n3, turtle, rdfa, nquads, trig, rdfjson, atom, xrd. Output formats: rdfxml, n3, turtle, ntriples, rdfa, nquads, rdfjson, canonical. OPTIONS
--input, -i Specify the input format. The synopsis of this manual page shows a list of input formats. Using media types should work too. In summary, it accepts any type that the "rdf_parse" function from RDF::TrineShortcuts accepts. If an input type is not specified, trapper will try to guess the input type (and will almost always get it right). --input-uri, -I, INPUT-BASE-URI Any of these three methods can be used to specify a base URI for the parser to resolve relative URI references. --output, -o Specifies the output format. The synopsis of this manual page shows a list of input formats. Using media types should work too. In summary, it accepts any type that the "rdf_string" function from RDF::TrineShortcuts accepts. If an input type is not specified, 'ntriples' is assumed. --count, -c Suppresses the output of the data, and just shows a count of triples instead. --quiet, -q Hides useless debugging messages. --help, -h Shows a short help message. --version, -v Shows the version of various Perl modules used by trapper. trapper itself doesn't have a version number, but is distributed along with RDF::TrineShortcuts, so could be considered to have the same version number as that. SHEBANG!! trapper can be used as a shebang line of a Turtle or N-Triples file. e.g.: #!/usr/local/bin/trapper OPTS: -i turtle -o rdfxml @prefix foaf: <http://xmlns.com/foaf/0.1/> . [] a foaf:Person ; foaf:name "Toby Inkster" . Note that you need the "OPTS:" bit to pass command-line options. This is a workaround for a limitation in Linux's shebang handling. NOTE
When possible, trapper attempts to use the same command-line options as the 'rapper' tool that is distributed with libraptor. However, full compatibility with rapper is not a goal, and is certainly not guaranteed. A trapper is a person who catches animals, usually for fur. AUTHOR
Toby Inkster, <tobyink@cpan.org> COPYRIGHT AND LICENCE
Copyright (C) 2010 by Toby Inkster This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8 or, at your option, any later version of Perl 5 you may have available. perl v5.10.1 2010-12-08 TRAPPER(1p)

Check Out this Related Man Page

RDF::TrineShortcuts(3pm)				User Contributed Perl Documentation				  RDF::TrineShortcuts(3pm)

NAME
RDF::TrineShortcuts - totally unauthorised module for cheats and charlatans SYNOPSIS
use RDF::TrineShortcuts; my $model = rdf_parse('http://example.com/data.rdf'); my $query = 'ASK { ?person a <http://xmlns.com/foaf/0.1/Person> . }'; if (rdf_query($query, $model)) { print "Document describes a person. "; } else { print "Document doesn't describe a person. "; print "What does it describe? Let's see... "; print rdf_string($model); } DESCRIPTION
This module exports three functions which simplify frequently performed tasks using RDF::Trine and RDF::Query. (A number of other functions are also available but not exported by default.) o "rdf_parse($data)" o "rdf_string($model, $format)" o "rdf_query($sparql, $endpoint_or_model)" In addition, because it calls "use RDF::Trine", "use RDF::Query", and "use RDF::Query::Client", your code doesn't need to. Main Functions "rdf_parse($data)" $data can be some serialised RDF (in RDF/XML, Turtle, RDF/JSON, or any other format that RDF::Trine::Parser supports); or a URI (string or URI object); or an HTTP::Message object; or a hashref (as per RDF::Trine::Model's add_hashref method); or a file name or an open file handle; or an RDF::Trine::Iterator::Graph. Essentially it could be anything you could reasonably expect to grab RDF from. It can be undef. If $input is a blessed object that rdf_parse is unable to natively deal with, it will attempt to call "$input->TO_RDF" and deal with the result instead. (This is similar in spirit to the JSON module's convert_blessed functionality.) The function returns an RDF::Trine::Model. There are additional optional named arguments, of which the two most useful are probably 'base', which sets the base URI for any relative URI references; and 'type', which indicates the media type of the input (though the function can usually guess this quite reliably). $model = rdf_parse($input, 'base' => 'http://example.com/', 'type' => 'application/rdf+xml'); Other named arguments include 'model' to provide an existing RDF::Trine::Model to add statements to; and 'context' for providing a context/graph URI (which may be a string, URI object or RDF::Trine::Node). "rdf_string($model, $format)" Serialises an RDF::Trine::Model to a string. $model is the model to serialise. If $model is not an RDF::Trine::Model object, then it's automatically passed through rdf_parse first. $format is the format to use. One of 'RDFXML' (the default), 'RDFJSON', 'Turtle', 'Canonical NTriples' or 'NTriples'. If $format is not one of the above, then the function will try to guess what you meant. Preferred namespace names can be provided as a named argument: print rdf_string($model, 'turtle', namespaces => { foo=>'http://example.com/vocabs/foo#' }); You can find the relevant Internet media type like this: my $type; my $string = rdf_string($model, 'rdfxml', media_type=>$type); print $cgi->header($type), $string and exit; "rdf_query($sparql, $endpoint)" $sparql is a SPARQL query to be run at $endpoint. $endpoint may be either an endpoint URI (string or URI object) or a model supported by RDF::Query (e.g. an RDF::Trine::Model.) Query languages other than SPARQL may be used (see <RDF::Query> for a list of supported languages). e.g. rdf_query("SELECT ?s, ?p, ?o WHERE (?s, ?p, ?o)" $model, query_lang=>'rdql'); Options query_base, query_update and query_load_data correspond to the base, update and load_data options passed to RDF::Query's constructor. If the SPARQL query returns a boolean (i.e. an ASK query), then this function returns a boolean. If the query returns a graph (i.e. CONSTRUCT or DESCRIBE), then this function returns an RDF::Trine::Model corresponding to the graph. Otherwise (i.e. SELECT) it returns an RDF::Trine::Iterator object. For queries which return a graph, an optional $model parameter can be passed containing an existing RDF::Trine::Model to add statements to: rdf_query("CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}", 'http://example.com/sparql', model => $model); This function can expand a small set of commonly used prefixes. For example: $result = rdf_query('SELECT ?id ?name {?id foaf:name ?name}', $model); The hashref $RDF::TrineShortcuts::Namespaces is consulted for expansions. Additional Functions These are not exported by default, so need to be imported explicitly, e.g. use RDF::TrineShortcuts qw(:default rdf_node rdf_statement); "rdf_node($value, %args)" Creates an RDF::Trine::Node object. Will attempt to automatically determine whether $value is a blank node, resource, literal or variable, but an optional named argument 'type' can be used to explicitly indicate this. For literals, named arguments 'datatype' and 'lang' are allowed. If 'datatype' is not a URI, then it's assumed to be an XSD datatype. $node = rdf_node("Hello", type=>'literal', lang=>'en'); For resources, the named argument 'base' is allowed. If $value is undef, then it would normally be treated like a zero-length string. By setting the argument 'passthrough_undef' to 1, you can allow it to pass thorugh and return undef. This function can expand a small set of commonly used prefixes. For example: $node = rdf_node('foaf:primaryTopic'); The hashref $RDF::TrineShortcuts::Namespaces is consulted for expansions. This function is not exported by default, but can be exported using the tag ':nodes' or ':all'. use RDF::TrineShortcuts qw(:default :nodes); "rdf_literal($value, %args)", "rdf_blank($value, %args)", "rdf_resource($value, %args)", "rdf_variable($value, %args)" Shortcuts for rdf_node($value, type=>'literal', %args) and so on. The rdf_resource function will create a blank node resource if $value begins '_:'. These functions are not exported by default, but can be exported using the tag ':nodes' or ':all'. use RDF::TrineShortcuts qw(:all); "rdf_statement($s, $p, $o, [$g])", "rdf_statement($ntriple, [$g])" Returns an RDF::Trine::Statement. Parameters $s, $p, $o and $g can each be either a plain string that could be passed to rdf_node, or an arrayref of rdf_node parameters, or an RDF::Trine::Node. $ntriple is a single N-Triples statement. This function is not exported by default, but can be exported using the tag ':all'. use RDF::TrineShortcuts qw(:all); "flatten_node($node)" Converts a node back to a string. By default, blank nodes and variables are stringified to their N-Triples and SPARQL representations; URIs are stringified without angled bracket delimiters; and literals to their literal values. Various options are available: 'resource_as', 'blank_as', 'variable_as' and 'literal_as' can each be set to 'ntriples', 'value' or 'default'. print flatten_node($my_resource, resource_as=>'ntriples'); This function is not exported by default, but can be exported using the tag ':flatten' or ':all'. use RDF::TrineShortcuts qw(:default :flatten); "flatten_iterator($iter)" Converts an iterator to a Perl list. In list context returns a list; in scalar context returns an arrayref instead. Each item in the list is, in the case of a bindings iterator, a hashref; or, in the case of a triple/quad iterator, an arrayref [s, p, o, g]. For boolean iterators, $iter->get_boolean is returned. The nodes which are values in the hashref/arrayref are flattened with flatten_node, unless flatten_iterator is called with 'keep_nodes'=>1. my @results = flatten_iterator($iter, keep_nodes=>1); You can pass additional options for flatten_node too: my @results = flatten_iterator($iter, resource_as=>'ntriples'); This function is not exported by default, but can be exported using the tag ':flatten' or ':all'. use RDF::TrineShortcuts qw(:default :flatten); Object-Oriented Interface RDF::TrineShortcuts has an alternative, object-oriented interface, not enabled by default. use RDF::TrineShortcuts -methods; my $model = RDF::Trine::Model->temporary_model; # Alias for rdf_parse($some_turtle, model=>$model) $model->parse($some_turtle); # Alias for rdf_string($model, 'rdfxml'); my $rdfxml = $model->parse('rdfxml'); print $rdfxml; my $query = 'SELECT ?name WHERE { ?id foaf:name ?name . } '; # Alias for rdf_query($query, $model); my $result = $model->sparql($query); # Alias for flatten_iterator(); my @result = $result->flatten; And so on. The following methods are set up: o RDF::Trine::Model: "parse", "string", "sparql". o RDF::Trine::Node: "flatten". o RDF::Trine::Iterator: "flatten". o URI::http: "sparql". o URI: "resource". Future versions of the RDF::Trine and URI packages may break this. It's a pretty dodgy feature. You can load the normal RDF::TrineShortcuts function-based interface in addition to the object-oriented interface like this: use RDF::TrineShortcuts qw(:default -methods); Or everything: use RDF::TrineShortcuts qw(:all -methods); BUGS
Please report any bugs to <http://rt.cpan.org/>. SEE ALSO
RDF::Trine, RDF::Query, RDF::Query::Client. <http://www.perlrdf.org/>. This module is distributed with three command-line RDF tools. trapper is an RDF fetcher/parser/serialiser; toquet is a SPARQL query tool; trist is an RDF statistics tool. AUTHOR
Toby Inkster <tobyink@cpan.org>. COPYRIGHT
Copyright 2010 Toby Inkster This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2011-01-08 RDF::TrineShortcuts(3pm)
Man Page