| RDF-YAML documentation | Contained in the RDF-YAML distribution. |
RDF::Simple::Parser::YAML - Simple RDF/YAML parser
This module is a simple RDF/XML parser. It reads a string containing RDF in YAML, and returns an array of RDF triples.
my $uri = 'http://www.w3.org/2000/08/w3c-synd/home.rss';
my $rdf = LWP::Simple::get($uri);
my $parser = RDF::Simple::Parser::YAML->new(base => $uri)
my @triples = $parser->parse_rdf($rdf);
# returns an array of array references which are triples
Create a new RDF::Simple::Parser::YAML object.
The optional parameter base supplies a base URI for relative URIs found
in the document. (This function is currently unimplemented.)
Accepts a string which is an RDF/YAML document.
Returns an array of array references which are RDF triples.
Autrijus Tang <autrijus@autrijus.org>
Copyright 2003 by Autrijus Tang <autrijus@autrijus.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| RDF-YAML documentation | Contained in the RDF-YAML distribution. |
# $File: //member/autrijus/RDF-YAML/lib/RDF/Simple/Parser/YAML.pm $ $Author: autrijus $ # $Revision: #2 $ $Change: 8524 $ $DateTime: 2003/10/22 05:20:04 $ package RDF::Simple::Parser::YAML; $RDF::Simple::Parser::YAML::VERSION = '0.01'; use strict; use YAML; use Class::MethodMaker new_hash_init => 'new', get_set => [ qw(base ns)];
sub parse_rdf { my ($self, $rdf) = @_; my $hash = YAML::Load($rdf) or return []; my $ns = $self->ns($hash->{''}); $ns->{''} = 'urn:empty' unless exists $ns->{''}; my @rv; foreach my $subject (sort grep length, keys %$hash) { my $node = $hash->{$subject} or next; foreach my $predicate (sort grep length, keys %$node) { my $object = $node->{$predicate}; $predicate =~ s/^(\w[^:]*):/$ns->{$1}/g or $predicate =~ /:/ or $predicate = $ns->{''} . $predicate; push @rv, [ $subject, $predicate, $object ]; } } return @rv; } 1;