rdf4h-0.6.1: A library for RDF processing in Haskell.ContentsIndex
Text.RDF.TriplesGraph
Description
TriplesGraph contains a list-backed graph implementation suitable for smallish graphs or for temporary graphs that will not be queried. It maintains the triples in the order that they are given in, and is especially useful for holding N-Triples, where it is often desirable to preserve the order of the triples when they were originally parsed. Duplicate triples are not filtered. If you might have duplicate triples, use MGraph instead, which is also more efficient. However, the query functions of this graph (select, query) remove duplicates from their result triples (but triplesOf does not) since it is usually cheap to do so.
Synopsis
data TriplesGraph
empty :: Graph gr => gr
mkGraph :: Graph gr => Triples -> Maybe BaseUrl -> PrefixMappings -> gr
triplesOf :: Graph gr => gr -> Triples
select :: Graph gr => gr -> NodeSelector -> NodeSelector -> NodeSelector -> Triples
query :: Graph gr => gr -> Maybe Node -> Maybe Node -> Maybe Node -> Triples
Documentation
data TriplesGraph

A simple implementation of the Graph type class that represents the graph internally as a list of triples.

Note that this type of graph is fine for interactive experimentation and querying of smallish (<10,000 triples) graphs, but there are better options for larger graphs or graphs that you will do many queries against (e.g., MGraph is faster for queries).

The time complexity of the functions (where n == num_triples) are:

show/hide Instances
empty :: Graph gr => gr
Return an empty graph.
mkGraph :: Graph gr => Triples -> Maybe BaseUrl -> PrefixMappings -> gr
Return a graph containing all the given triples. Handling of duplicates in the input depend on the particular graph implementation.
triplesOf :: Graph gr => gr -> Triples
Return all triples in the graph, as a list.
select :: Graph gr => gr -> NodeSelector -> NodeSelector -> NodeSelector -> Triples

Select the triples in the graph that match the given selectors.

The three NodeSelector parameters are optional functions that match the respective subject, predicate, and object of a triple. The triples returned are those in the given graph for which the first selector returns true when called on the subject, the second selector returns true when called on the predicate, and the third selector returns true when called on the ojbect. A Nothing parameter is equivalent to a function that always returns true for the appropriate node; but implementations may be able to much more efficiently answer a select that involves a Nothing parameter rather than an (id True) parameter.

The following call illustrates the use of select, and would result in the selection of all and only the triples that have a blank node as subject and a literal node as object:

 select gr (Just isBNode) Nothing (Just isLNode)

Note: this function may be very slow; see the documentation for the particular graph implementation for more information.

query :: Graph gr => gr -> Maybe Node -> Maybe Node -> Maybe Node -> Triples

Return the triples in the graph that match the given pattern, where the pattern (3 Maybe Node parameters) is interpreted as a triple pattern.

The Maybe Node params are interpreted as the subject, predicate, and object of a triple, respectively. Just n is true iff the triple has a node equal to n in the appropriate location; Nothing is always true, regardless of the node in the appropriate location.

For example, query gr (Just n1) Nothing (Just n2) would return all and only the triples that have n1 as subject and n2 as object, regardless of the predicate of the triple.

Produced by Haddock version 0.9