Catmandu-RDF

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    serialization to another) is possible but probably less performant than
    decent RDF tools. Catmandu::RDF, however, is more conventient to convert
    between RDF and other data formats.

AVAILABLE MODULES
    Catmandu::Exporter::RDF
        Serialize RDF data (as RDF/XML, RDF/JSON, Turtle, NTriples, RDFa...)

    Catmandu::Importer::RDF
        Parse RDF data (RDF/XML, RDF/JSON, Turtle, NTriples...) or import
        from a SPARQL endpoint

    Catmandu::Fix::aref_query
        Copy values of RDF data in aREF format to a new field

SEE ALSO
    This module is based on Catmandu, RDF::aREF, RDF::Trine, and RDF::NS.

COPYRIGHT AND LICENSE
    Copyright Jakob Voß, 2014-

lib/Catmandu/Fix/rdf_ldf_statements.pm  view on Meta::CPAN

          push \@{${var}} , ${st}->subject->uri;
      }
    }
}
EOF
    $perl;
}

=head1 NAME

Catmandu::Fix::rdf_ldf_statements - lookup an object into a LDF endpoint

=head1 SYNOPSIS

    # Replace a name with an array of matching VIAF records
    # name: "\"Einstein, Albert, 1879-1955\""
    rdf_ldf_statements(name,url:"http://data.linkedatafragments.org/viaf",predicate:"http://schema.org/alternateName")

    # name:
    #   - http://viaf.org/viaf/75121530

=head1 DESCRIPTION

This L<Catmandu::Fix> can be used to find at a Linked Data Fragments endpoint
all subject URIs for which the object has a specific value found at a path. E.g.

   rdf_ldf_statements(name,url:"http://data.linkedatafragments.org/viaf")

 means, search at the endpoint http://data.linkedatafragments.org/viaf all the
 subjects for which the object is the value found in 'name', and replace the name value
 with all the found subjects.

=head1 ARGUMENTS

=over

=item subject

Optional subject URI to be used in the LDF query

=item predicate

Optional predicate URI to be used in the LDF query

=item url

Required URL to the Linked Data Fragments endpoint

=back

=head1 SEE ALSO

L<Catmandu::Fix>

=cut

1;

lib/Catmandu/Importer/RDF.pm  view on Meta::CPAN

  catmandu convert RDF --file rdfdump.ttl to JSON

  # Parse the input into on JSON document per triplet. This is the
  # most memory efficient (and fastest) way to parse RDF input.
  catmandu convert RDF --triples 1 --file rdfdump.ttl to JSON

  # Transform back into NTriples (conversions to and from triples is the
  # most efficient way to process RDF)
  catmandu convert RDF --triples 1 --file rdfdump.ttl to RDF --type NTriples

  # Query a SPARQL endpoint
  catmandu convert RDF --url http://dbpedia.org/sparql
                       --sparql "SELECT ?film WHERE { ?film dct:subject <http://dbpedia.org/resource/Category:French_films> }"

  catmandu convert RDF --url http://example.org/sparql --sparql query.rq

  # Query a Linked Data Fragment endpoint
  catmandu convert RDF --url http://fragments.dbpedia.org/2014/en
                       --sparql "SELECT ?film WHERE { ?film dct:subject <http://dbpedia.org/resource/Category:French_films> }"

In Perl code:

    use Catmandu::Importer::RDF;
    my $url = "http://dx.doi.org/10.2474/trol.7.147";
    my $rdf = Catmandu::Importer::RDF->new( url => $url )->first;

=head1 DESCRIPTION

This L<Catmandu::Importer> can be use to import RDF data from URLs, files or
input streams, SPARQL endpoints, and Linked Data Fragment endpoints.

By default an RDF graph is imported as single item in aREF format (see
L<RDF::aREF>).

=head1 CONFIGURATION

=over

=item url

lib/Catmandu/Importer/RDF.pm  view on Meta::CPAN

=item fh

=item encoding

=item fix

Default configuration options of L<Catmandu::Importer>.

=item sparql

The SPARQL query to be executed on the URL endpoint (currectly only SELECT is
supported).  The query can be supplied as string or as filename. The importer
tries to automatically add missing PREFIX statements from the default namespace
prefixes.

=item sparql_result

Encoding of SPARQL result values. With C<aref>, query results are encoded in
aREF format, with URIs in C<E<lt>> and C<E<gt>> (no qNames) and literal nodes
appended by C<@> and optional language code. By default (value C<simple>), all
RDF nodes are simplfied to their literal form.

lib/Catmandu/RDF.pm  view on Meta::CPAN


=over

=item L<Catmandu::Exporter::RDF>

Serialize RDF data (as RDF/XML, RDF/JSON, Turtle, NTriples, RDFa...)

=item L<Catmandu::Importer::RDF>

Parse RDF data (RDF/XML, RDF/JSON, Turtle, NTriples...) or import from a SPARQL
endpoint

=item L<Catmandu::Fix::aref_query>

Copy values of RDF data in aREF format to a new field

=back

=head1 SEE ALSO

This module is based on L<Catmandu>, L<RDF::aREF>, L<RDF::Trine>, and

t/sparql.t  view on Meta::CPAN

use Catmandu::RDF;
use RDF::Trine;
use Encode;
use HTTP::Response;
use Test::LWP::UserAgent;
use utf8;

RDF::Trine->default_useragent(user_agent());

{
    note("importing from sparql endpoint");
    my $sparql   =<<END;
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT * WHERE { ?book dc:title ?title . }
END

    my $url = 'http://sparql.org/books/sparql';

    my $importer = importer('RDF', url => $url, sparql => $sparql);
    is $importer->sparql, $sparql, "SPARQL";

    $importer = importer('RDF', url => $url, 
        sparql => "SELECT * WHERE { ?book dc:title ?title . }\n");
    is $importer->sparql, $sparql, "SPARQL, PREFIX added";

    my $ref = $importer->first;
    ok $ref->{title} , 'got a title';
    ok $ref->{book} , 'got a book';
}

{
     note("importing from ldf endpoint");
     my $sparql =<<EOF;
SELECT ?film WHERE { ?film dct:subject <http://dbpedia.org/resource/Category:French_films> }
EOF
     my $url = 'http://fragments.dbpedia.org/2014/en';

     my $importer = importer('RDF', url => $url, sparql => $sparql);

     my $ref = $importer->first;
     ok $ref->{film} , 'got a film';
}

{
     note("importing from ldf endpoint (utf8)");
     my $url = 'http://fragments.dbpedia.org/2014/en';

     my $importer = importer('RDF', url => $url, sparql => 't/query.sparql');

     my $ref = $importer->first;
     ok $ref->{name} , 'got a name (file sparql)';
     like $ref->{name} , qr/François Schuiten/ , 'utf8 test';
}

done_testing;



( run in 0.697 second using v1.01-cache-2.11-cpan-b61123c0432 )