rdf4h-0.6.1: A library for RDF processing in Haskell.ContentsIndex
Text.RDF.Core
Synopsis
class Graph gr where
baseUrl :: gr -> Maybe BaseUrl
prefixMappings :: gr -> PrefixMappings
addPrefixMappings :: gr -> PrefixMappings -> Bool -> gr
empty :: gr
mkGraph :: Triples -> Maybe BaseUrl -> PrefixMappings -> gr
triplesOf :: gr -> Triples
select :: gr -> NodeSelector -> NodeSelector -> NodeSelector -> Triples
query :: gr -> Maybe Node -> Maybe Node -> Maybe Node -> Triples
class RdfParser p where
parseString :: forall gr . Graph gr => p -> ByteString -> Either ParseFailure gr
parseFile :: forall gr . Graph gr => p -> String -> IO (Either ParseFailure gr)
parseURL :: forall gr . Graph gr => p -> String -> IO (Either ParseFailure gr)
class RdfSerializer s where
hWriteG :: forall gr . Graph gr => s -> Handle -> gr -> IO ()
writeG :: forall gr . Graph gr => s -> gr -> IO ()
hWriteH :: forall gr . Graph gr => s -> Handle -> gr -> IO ()
writeH :: forall gr . Graph gr => s -> gr -> IO ()
hWriteTs :: s -> Handle -> Triples -> IO ()
writeTs :: s -> Triples -> IO ()
hWriteT :: s -> Handle -> Triple -> IO ()
writeT :: s -> Triple -> IO ()
hWriteN :: s -> Handle -> Node -> IO ()
writeN :: s -> Node -> IO ()
newtype BaseUrl = BaseUrl ByteString
newtype PrefixMappings = PrefixMappings (Map ByteString ByteString)
toPMList :: PrefixMappings -> [(ByteString, ByteString)]
newtype PrefixMapping = PrefixMapping (ByteString, ByteString)
data Triple = Triple !Node !Node !Node
triple :: Subject -> Predicate -> Object -> Triple
type Triples = [Triple]
sortTriples :: Triples -> Triples
data Node
= UNode !FastString
| BNode !FastString
| BNodeGen !Int
| LNode !LValue
data LValue
= PlainL !ByteString
| PlainLL !ByteString !ByteString
| TypedL !ByteString !FastString
type NodeSelector = Maybe (Node -> Bool)
isUNode :: Node -> Bool
isBNode :: Node -> Bool
isLNode :: Node -> Bool
equalSubjects :: Triple -> Triple -> Bool
equalPredicates :: Triple -> Triple -> Bool
equalObjects :: Triple -> Triple -> Bool
subjectOf :: Triple -> Node
predicateOf :: Triple -> Node
objectOf :: Triple -> Node
type Subject = Node
type Predicate = Node
type Object = Node
newtype ParseFailure = ParseFailure String
data FastString
mkFastString :: ByteString -> FastString
s2b :: String -> ByteString
b2s :: ByteString -> String
unode :: ByteString -> Node
bnode :: ByteString -> Node
lnode :: LValue -> Node
plainL :: ByteString -> LValue
plainLL :: ByteString -> ByteString -> LValue
typedL :: ByteString -> FastString -> LValue
class View a b where
view :: a -> b
view :: View a b => a -> b
fromEither :: Graph gr => Either ParseFailure gr -> gr
maybeHead :: [a] -> Maybe a
removeDupes :: Triples -> Triples
Documentation
class Graph gr where

An RDF graph is a set of (unique) RDF triples, together with the operations defined upon the graph.

For information about the efficiency of the functions, see the documentation for the particular graph instance.

For more information about the concept of an RDF graph, see the following: http://www.w3.org/TR/rdf-concepts/#section-rdf-graph.

Methods
baseUrl :: gr -> Maybe BaseUrl
Return the base URL of this graph, if any.
prefixMappings :: gr -> PrefixMappings
Return the prefix mappings defined for this graph, if any.
addPrefixMappings :: gr -> PrefixMappings -> Bool -> gr
Return a graph with the specified prefix mappings merged with the existing mappings. If the Bool arg is True, then a new mapping for an existing prefix will replace the old mapping; otherwise, the new mapping is ignored.
empty :: gr
Return an empty graph.
mkGraph :: 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 :: gr -> Triples
Return all triples in the graph, as a list.
select :: 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 :: 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.

show/hide Instances
class RdfParser p where
An RdfParser is a parser that knows how to parse 1 format of RDF and can parse an RDF document of that type from a string, a file, or a URL. Required configuration options will vary from instance to instance.
Methods
parseString :: forall gr . Graph gr => p -> ByteString -> Either ParseFailure gr
Parse RDF from the given bytestring, yielding a failure with error message or the resultant graph.
parseFile :: forall gr . Graph gr => p -> String -> IO (Either ParseFailure gr)
Parse RDF from the local file with the given path, yielding a failure with error message or the resultant graph in the IO monad.
parseURL :: forall gr . Graph gr => p -> String -> IO (Either ParseFailure gr)
Parse RDF from the remote file with the given HTTP URL (https is not supported), yielding a failure with error message or the resultant graph in the IO monad.
show/hide Instances
class RdfSerializer s where
An RdfSerializer is a serializer of RDF to some particular output format, such as NTriples or Turtle.
Methods
hWriteG :: forall gr . Graph gr => s -> Handle -> gr -> IO ()
Write the graph to a file handle using whatever configuration is specified by the first argument.
writeG :: forall gr . Graph gr => s -> gr -> IO ()
Write the graph to stdout; equivalent to hWriteG stdout.
hWriteH :: forall gr . Graph gr => s -> Handle -> gr -> IO ()
Write to the file handle whatever header information is required based on the output format. For example, if serializing to Turtle, this method would write the necessary @prefix declarations and possibly a @baseUrl declaration, whereas for NTriples, there is no header section at all, so this would be a no-op.
writeH :: forall gr . Graph gr => s -> gr -> IO ()
Write header information to stdout; equivalent to hWriteH stdout.
hWriteTs :: s -> Handle -> Triples -> IO ()

Write some triples to a file handle using whatever configuration is specified by the first argument.

WARNING: if the serialization format has header-level information that should be output (e.g., @prefix declarations for Turtle), then you should use hWriteG instead of this method unless you're sure this is safe to use, since otherwise the resultant document will be missing the header information and will not be valid.

writeTs :: s -> Triples -> IO ()
Write some triples to stdout; equivalent to hWriteTs stdout.
hWriteT :: s -> Handle -> Triple -> IO ()
Write a single triple to the file handle using whatever configuration is specified by the first argument. The same WARNING applies as to hWriteTs.
writeT :: s -> Triple -> IO ()
Write a single triple to stdout; equivalent to hWriteT stdout.
hWriteN :: s -> Handle -> Node -> IO ()
Write a single node to the file handle using whatever configuration is specified by the first argument. The same WARNING applies as to hWriteTs.
writeN :: s -> Node -> IO ()
Write a single node to sdout; equivalent to hWriteN stdout.
show/hide Instances
newtype BaseUrl
The base URL of a graph.
Constructors
BaseUrl ByteString
show/hide Instances
newtype PrefixMappings
An alias for a set of prefix mappings.
Constructors
PrefixMappings (Map ByteString ByteString)
show/hide Instances
toPMList :: PrefixMappings -> [(ByteString, ByteString)]
View the prefix mappings as a list of key-value pairs. The PM in in the name is to reduce name clashes if used without qualifying.
newtype PrefixMapping
A mapping of a prefix to the URI for that prefix.
Constructors
PrefixMapping (ByteString, ByteString)
show/hide Instances
data Triple

An RDF triple is a statement consisting of a subject, predicate, and object, respectively.

To create a Triple, use the triple function.

See http://www.w3.org/TR/rdf-concepts/#section-triples for more information.

Constructors
Triple !Node !Node !Node
show/hide Instances
triple :: Subject -> Predicate -> Object -> Triple
Return aTriple for the given subject, predicate, and object.
type Triples = [Triple]
A list of triples. This is defined for convenience and readability.
sortTriples :: Triples -> Triples
Answer the given list of triples in sorted order.
data Node
An RDF node, which may be either a URIRef node (UNode), a blank node (BNode), or a literal node (LNode).
Constructors
UNode !FastStringAn RDF URI reference. See http://www.w3.org/TR/rdf-concepts/#section-Graph-URIref for more information.
BNode !FastStringAn RDF blank node. See http://www.w3.org/TR/rdf-concepts/#section-blank-nodes for more information.
BNodeGen !IntAn RDF blank node with an auto-generated identifier, as used in Turtle.
LNode !LValueAn RDF literal. See http://www.w3.org/TR/rdf-concepts/#section-Graph-Literal for more information.
show/hide Instances
data LValue
The actual value of an RDF literal, represented as the LValue parameter of an LNode.
Constructors
PlainL !ByteStringA plain (untyped) literal value in an unspecified language.
PlainLL !ByteString !ByteStringA plain (untyped) literal value with a language specifier.
TypedL !ByteString !FastStringA typed literal value consisting of the literal value and the URI of the datatype of the value, respectively.
show/hide Instances
type NodeSelector = Maybe (Node -> Bool)

A NodeSelector is either a function that returns True or False for a node, or Nothing, which indicates that all nodes would return True.

The selector is said to select, or match, the nodes for which it returns True.

When used in conjunction with the select method of Graph, three node selectors are used to match a triple.

isUNode :: Node -> Bool
Answer if given node is a URI Ref node.
isBNode :: Node -> Bool
Answer if given node is a blank node.
isLNode :: Node -> Bool
Answer if given node is a literal node.
equalSubjects :: Triple -> Triple -> Bool
Determine whether two triples have equal subjects.
equalPredicates :: Triple -> Triple -> Bool
Determine whether two triples have equal predicates.
equalObjects :: Triple -> Triple -> Bool
Determine whether two triples have equal objects.
subjectOf :: Triple -> Node
Answer the subject node of the triple.
predicateOf :: Triple -> Node
Answer the predicate node of the triple.
objectOf :: Triple -> Node
Answer the object node of the triple.
type Subject = Node
An alias for Node, defined for convenience and readability purposes.
type Predicate = Node
An alias for Node, defined for convenience and readability purposes.
type Object = Node
An alias for Node, defined for convenience and readability purposes.
newtype ParseFailure
Represents a failure in parsing an N-Triples document, including an error message with information about the cause for the failure.
Constructors
ParseFailure String
show/hide Instances
data FastString

FastString is a bytestring-based string type that provides constant-time equality testing.

A FastString value consists of a unique identifier and a (strict) ByteString value. The unique identifier is used for constant-time equality testing, and all other operations are provided by the ByteString value itself.

FastString values are created by the mkFastString function, which maintains a table of all created values, and reuses old values whenever possible. The ByteString is maintained internally in reverse order of the string passed to mkFastString; this is to provide faster comparison testing for unequal values, since it is very common in RDF to have URIs that are equal apart from the last few characters (localname).

show/hide Instances
mkFastString :: ByteString -> FastString

Return a FastString value for the given ByteString, reusing a FastString if one has been created for equal bytestrings, or creating a new one if necessary. The FastString values created maintain the invariant that two values have the same unique identifier (accessible via uniq) iff their respective bytestring values are equal.

The unique identifier is only for the given session, and equal ByteString values will generally not be assigned the same identifier under different processes and different executions.

s2b :: String -> ByteString
A convenience function for converting from a string to a bytestring.
b2s :: ByteString -> String
A convenience function for converting from a bytestring to a string.
unode :: ByteString -> Node
Return a URIRef node for the given bytetring URI.
bnode :: ByteString -> Node
Return a blank node using the given string identifier.
lnode :: LValue -> Node
Return a literal node using the given LValue.
plainL :: ByteString -> LValue
Return a PlainL LValue for the given string value.
plainLL :: ByteString -> ByteString -> LValue
Return a PlainLL LValue for the given string value and language, respectively.
typedL :: ByteString -> FastString -> LValue
Return a TypedL LValue for the given string value and datatype URI, respectively.
class View a b where
A type class for ADTs that expose views to clients.
Methods
view :: a -> b
view :: View a b => a -> b
fromEither :: Graph gr => Either ParseFailure gr -> gr
Convert a parse result into a graph if it was successful and error and terminate if not.
maybeHead :: [a] -> Maybe a
A safe version of head that returns Nothing for an empty list or 'Just (head lst)' for a non-empty list.
removeDupes :: Triples -> Triples
Remove duplicate triples, returning unique triples. This function may return the triples in a different order than given.
Produced by Haddock version 0.9