The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

RDF::Notation3 - RDF Notation3 parser

SYNOPSIS

 $rdf = new RDF::Notation3::Triples;
 $rdf->parse_file($path);
 $triples = $rdf->get_triples;

DESCRIPTION

This module is an RDF/N3 parser; it can parse N3 files or strings and provide results in whatever format (as far as there are subclasses supporting your desired format available).

RDF::Notation3 is a base class providing the parsing logic only. This class is never used directly. Instead, derived classes such as RDF::Notation3::Triples are used. The subclasses control how results of parsing are processed and can provide additional methods to access the results then. RDF::Notation3 doesn't tend to create sophisticated in-memory or persistent RDF structures of its own; it should more likely serve as a parser for other Perl RDF modules focused on how to store and access RDF triples.

METHODS COMMON TO ALL CLASSES

parse_file and parse_string methods are actually common to all subclasses, but as they may have completely different behavior for various classes, see their description for each particular class.

anonymous_ns_uri
 $ns_uri = $rdf->anonymous_ns_uri;
 $rdf->anonymous_ns_uri('http://gingerall.org/anonymous#');

Gets or sets anonymous namespace URI. The default value is '#', which results in anonymous nodes URIs like this: <#g_1>. If set as above, it will be changed to <http://gingerall.org/anonymous#g_1>.

CLASSES

RDF::Notation3::Triples

This class parses a RDF/N3 file and stores triples in memory. Qualified names with prefixes are expanded using a prefix-URI mapping for given context during the parse time.

methods:

parse_file
 $rdf->parse_file($path);

Parses an N3 file specified by $path. Triples are stored to the $rdf->{triples} array.

parse_string
 $rdf->parse_file($string);

Similar to parse_file, just parses N3 data from string.

get_triples
 $triples = $rdf->get_triples($subject, $property, $object, $context);

Returns a reference to array of triples created by the parse method. Arguments are optional. The result set can be filtered for particular subject, property, object or context. The array has the same structure as the $rdf->{triples} property.

For example:

 $triples = $rdf->get_triples;

returns all triples, while

 $triples = $rdf->get_triples($subject);

returns only triples containing subject $subject and

 $triples = $rdf->get_triples(undef, $property, $object);

returns only triples containing property $property and object $object.

 $triples = $rdf->get_triples(undef, undef, undef, '<>');

returns all triples from the document (top-level) context.

properties:

triples
 $rdf->{triples}

A reference to array of triples created by the parse method. Each triple is represented as an array with 4 elements: subject, predicate, object, and context. All nodes are stored as <URI> or "literal". To filter triples use get_triples method.

ns
 $rdf->{ns}

A reference to hash created by the parse method. The hash keys are context URIs (<> for document context and <#c_n> for anonymous contexts). The hash values are again hashes keyed with prefixes with ns URIs as values.

RDF::Notation3::PrefTriples

This class parses a RDF/N3 file and stores triples in memory. Qualified names with prefixes are NOT expanded. The expansion can be done later using the {ns} hash. However, if a prefix-URI binding changes within a context, the result of parsing may be incorrect. Use this class as a faster way to get QNames with prefixes if you are SURE the binding doesn't change! Otherwise use RDF::Notation3::Triples for correct results.

methods:

parse_file

See RDF::Notation3::Triples.

parse_string

See RDF::Notation3::Triples.

get_triples

See RDF::Notation3::Triples.

properties:

triples
 $rdf->{triples}

A reference to array of triples created by the parse method. Each triple is represented as an array with 4 elements: subject, predicate, object, and context. All nodes are stored as <URI>, prefix:local or "literal". To filter triples use get_triples method.

ns

See RDF::Notation3::Triples.

VERSION

Current version is 0.30.

LICENSING

Copyright (c) 2001 Ginger Alliance. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Petr Cimprich, petr@gingerall.cz

SEE ALSO

perl(1).