NAME

RDF::Trine::Model - Model class

VERSION

This document describes RDF::Trine::Model version 0.125_02

METHODS

new ( @stores )

Returns a new model over the supplied rdf store.

temporary_model

Returns a new temporary (non-persistent) model.

dataset_model ( default => \@graphs, named => \@graphs )
add_statement ( $statement [, $context] )

Adds the specified $statement to the rdf store.

add_hashref ( $hashref [, $context] )

Add triples represented in an RDF/JSON-like manner to the model.

See as_hashref for full documentation of the hashref format.

remove_statement ( $statement [, $context])

Removes the specified $statement from the rdf store.

remove_statements ( $subject, $predicate, $object [, $context] )

Removes all statements matching the supplied $statement pattern from the rdf store.

size

Returns the number of statements in the model.

count_statements ( $subject, $predicate, $object )

Returns a count of all the statements matching the specified subject, predicate and objects. Any of the arguments may be undef to match any value.

get_statements ($subject, $predicate, $object [, $context] )

Returns an iterator of all statements matching the specified subject, predicate and objects from the rdf store. Any of the arguments may be undef to match any value.

If three or fewer arguments are given, the statements returned will be matched based on triple semantics (the graph union of triples from all the named graphs). If four arguments are given (even if $context is undef), statements will be matched based on quad semantics (the union of all quads in the underlying store).

get_pattern ( $bgp [, $context] [, %args ] )

Returns a stream object of all bindings matching the specified graph pattern.

If $context is given, restricts BGP matching to only quads with the $context value.

%args may contain an 'orderby' key-value pair to request a specific ordering based on variable name. The value for the 'orderby' key should be an ARRAY reference containing variable name and direction ('ASC' or 'DESC') tuples. A valid %args hash, therefore, might look like orderby => [qw(name ASC)] (corresponding to a SPARQL-like request to 'ORDER BY ASC(?name)').

get_contexts

Returns an iterator containing the nodes representing the named graphs in the model.

as_stream

Returns an iterator object containing every statement in the model.

as_hashref

Returns a hashref representing the model in an RDF/JSON-like manner.

A graph like this (in Turtle):

@prefix ex: <http://example.com/> .

ex:subject1
  ex:predicate1
    "Foo"@en ,
    "Bar"^^ex:datatype1 .

_:bnode1
  ex:predicate2
    ex:object2 ;
  ex:predicate3 ;
    _:bnode3 .

Is represented like this as a hashref:

{
  "http://example.com/subject1" => {
    "http://example.com/predicate1" => [
      { 'type'=>'literal', 'value'=>"Foo", 'lang'=>"en" },
      { 'type'=>'literal', 'value'=>"Bar", 'datatype'=>"http://example.com/datatype1" },
    ],
  },
  "_:bnode1" => {
    "http://example.com/predicate2" => [
      { 'type'=>'uri', 'value'=>"http://example.com/object2" },
    ],
    "http://example.com/predicate2" => [
      { 'type'=>'bnode', 'value'=>"_:bnode3" },
    ],
  },
}

Note that the type of subjects (resource or blank node) is indicated entirely by the convention of starting blank nodes with "_:".

This hashref structure is compatible with RDF/JSON and with the ARC2 library for PHP.

Node-Centric Graph API

subjects ( $predicate, $object )

Returns a list of the nodes that appear as the subject of statements with the specified $predicate and $object. Either of the two arguments may be undef to signify a wildcard.

predicates ( $subject, $object )

Returns a list of the nodes that appear as the predicate of statements with the specified $subject and $object. Either of the two arguments may be undef to signify a wildcard.

objects ( $subject, $predicate )

Returns a list of the nodes that appear as the object of statements with the specified $subject and $predicate. Either of the two arguments may be undef to signify a wildcard.

objects_for_predicate_list ( $subject, @predicates )

Given the RDF::Trine::Node objects $subject and @predicates, finds all matching triples in the model with the specified subject and any of the given predicates, and returns a list of object values (in the partial order given by the ordering of @predicates).

bounded_description ( $node )

Returns an RDF::Trine::Iterator::Graph object over the bounded description triples for $node (all triples resulting from a graph traversal starting with node and stopping at non-blank nodes).

as_string

AUTHOR

Gregory Todd Williams <gwilliams@cpan.org>

COPYRIGHT

Copyright (c) 2006-2010 Gregory Todd Williams. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.