rdf4h-1.3.6: A library for RDF processing in Haskell

Safe HaskellNone
LanguageHaskell98

Data.RDF.MGraph

Description

A simple graph implementation backed by HashMap.

Synopsis

Documentation

data MGraph Source

A map-based graph implementation.

This instance of RDF is an adjacency map with each subject mapping to a mapping from a predicate node to to the adjacent nodes via that predicate.

Given the following triples graph::

  (http://example.com/s1,http://example.com/p1,http://example.com/o1)
  (http://example.com/s1,http://example.com/p1,http://example.com/o2)
  (http://example.com/s1,http://example.com/p2,http://example.com/o1)
  (http://example.com/s2,http://example.com/p3,http://example.com/o3)

where

hash "http://example.com/s1" = 1600134414
hash "http://example.com/s2" = 1600134413
hash "http://example.com/p1" = 1616912099
hash "http://example.com/p2" = 1616912096
hash "http://example.com/p3" = 1616912097
hash "http://example.com/o1" = 1935686794
hash "http://example.com/o2" = 1935686793
hash "http://example.com/o3" = 1935686792

the in-memory hashmap representation of the triples graph is:

key:1600134414, value:(key:1616912099, value:[1935686794    -- (../s1,../p1,../o1)
                                             ,1935686793];  -- (../s1,../p1,../o2)
                       key:1616912096, value:[1935686794]); -- (../s1,../p2,../o1)
key:1600134413, value:(key:1616912097, value:[1935686792])  -- (../s1,../p3,../o3)

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

empty :: RDF rdf => rdf Source

Return an empty RDF.

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

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

triplesOf :: RDF rdf => rdf -> Triples Source

Return all triples in the RDF, as a list.

Note that this function returns a list of triples in the RDF as they were added, without removing duplicates and without expanding namespaces.

uniqTriplesOf :: RDF rdf => rdf -> Triples Source

Return unique triples in the RDF, as a list.

This function performs namespace expansion and removal of duplicates.

select :: RDF rdf => rdf -> NodeSelector -> NodeSelector -> NodeSelector -> Triples Source

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 -> Triples Source

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.