rdf4h-1.2.0: A library for RDF processing in Haskell

Safe HaskellNone

Data.RDF.MGraph

Description

A simple graph implementation backed by Map.

Synopsis

Documentation

data MGraph Source

A map-based graph implementation.

Worst-case time complexity of the graph functions, with respect to the number of triples, are:

Instances

empty :: RDF rdf => rdfSource

Return an empty RDF.

mkRdf :: RDF rdf => Triples -> Maybe BaseUrl -> PrefixMappings -> rdfSource

Return a RDF containing all the given triples. Handling of duplicates in the input depend on the particular RDF implementation.

triplesOf :: RDF rdf => rdf -> TriplesSource

Return all triples in the RDF, as a list.

select :: RDF rdf => rdf -> NodeSelector -> NodeSelector -> NodeSelector -> TriplesSource

Select the triples in the RDF 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 RDF implementation for more information.

query :: RDF rdf => rdf -> Maybe Node -> Maybe Node -> Maybe Node -> TriplesSource

Return the triples in the RDF 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 rdf (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.