The Core module provides the fundamental types, type classes, and functions of the library.
- class RdfParser p where
- class RdfSerializer s where
- hWriteRdf :: forall rdf. RDF rdf => s -> Handle -> rdf -> IO ()
- writeRdf :: forall rdf. RDF rdf => s -> rdf -> IO ()
- hWriteH :: forall rdf. RDF rdf => s -> Handle -> rdf -> IO ()
- writeH :: forall rdf. RDF rdf => s -> rdf -> 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 ()
- class RDF rdf where
- baseUrl :: rdf -> Maybe BaseUrl
- prefixMappings :: rdf -> PrefixMappings
- addPrefixMappings :: rdf -> PrefixMappings -> Bool -> rdf
- empty :: rdf
- mkRdf :: Triples -> Maybe BaseUrl -> PrefixMappings -> rdf
- triplesOf :: rdf -> Triples
- select :: rdf -> NodeSelector -> NodeSelector -> NodeSelector -> Triples
- query :: rdf -> Maybe Node -> Maybe Node -> Maybe Node -> Triples
- data Triple = Triple !Node !Node !Node
- triple :: Subject -> Predicate -> Object -> Triple
- type Triples = [Triple]
- sortTriples :: Triples -> Triples
- data Node
- data LValue
- newtype BaseUrl = BaseUrl ByteString
- newtype PrefixMappings = PrefixMappings (Map ByteString ByteString)
- toPMList :: PrefixMappings -> [(ByteString, ByteString)]
- newtype PrefixMapping = PrefixMapping (ByteString, ByteString)
- 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
- isIsomorphic :: forall rdf1 rdf2. (RDF rdf1, RDF rdf2) => rdf1 -> rdf2 -> Bool
- subjectOf :: Triple -> Node
- predicateOf :: Triple -> Node
- objectOf :: Triple -> Node
- isEmpty :: RDF rdf => rdf -> Bool
- rdfContainsNode :: forall rdf. RDF rdf => rdf -> Node -> Bool
- tripleContainsNode :: Node -> Triple -> Bool
- listSubjectsWithPredicate :: RDF rdf => rdf -> Predicate -> [Subject]
- listObjectsOfPredicate :: RDF rdf => rdf -> Predicate -> [Object]
- 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
- fromEither :: RDF rdf => Either ParseFailure rdf -> rdf
- maybeHead :: [a] -> Maybe a
- removeDupes :: Triples -> Triples
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.
Parse RDF from the given bytestring, yielding a failure with error message or the resultant RDF.
Parse RDF from the local file with the given path, yielding a failure with error message or the resultant RDF in the IO monad.
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.
An RdfSerializer is a serializer of RDF to some particular output format, such as NTriples or Turtle.
Write the RDF to a file handle using whatever configuration is specified by the first argument.
Write the RDF to stdout; equivalent to
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.
Write header information to stdout; equivalent to
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
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.
Write some triples to stdout; equivalent to
Write a single triple to the file handle using whatever configuration is
specified by the first argument. The same WARNING applies as to
Write a single triple to stdout; equivalent to
Write a single node to the file handle using whatever configuration is
specified by the first argument. The same WARNING applies as to
Write a single node to sdout; equivalent to
An RDF value is a set of (unique) RDF triples, together with the operations defined upon them.
For information about the efficiency of the functions, see the documentation for the particular RDF instance.
For more information about the concept of an RDF graph, see the following: http://www.w3.org/TR/rdf-concepts/#section-rdf-graph.
Return the base URL of this RDF, if any.
Return the prefix mappings defined for this RDF, if any.
Return an RDF 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.
Return an empty RDF.
Return a RDF containing all the given triples. Handling of duplicates in the input depend on the particular RDF implementation.
Return all triples in the RDF, as a list.
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.
Return the triples in the RDF that match the given pattern, where the pattern (3 Maybe Node parameters) is interpreted as a triple pattern.
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.
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.
RDF triples, nodes, and literals
An RDF triple is a statement consisting of a subject, predicate, and object, respectively.
See http://www.w3.org/TR/rdf-concepts/#section-triples for more information.
An RDF URI reference. See http://www.w3.org/TR/rdf-concepts/#section-Graph-URIref for more information.
An RDF blank node. See http://www.w3.org/TR/rdf-concepts/#section-blank-nodes for more information.
An RDF blank node with an auto-generated identifier, as used in Turtle.
An RDF literal. See http://www.w3.org/TR/rdf-concepts/#section-Graph-Literal for more information.
A node is equal to another node if they are both the same type of node and if the field values are equal.
Node ordering is defined first by type, with Unode < BNode < BNodeGen < LNode PlainL < LNode PlainLL < LNode TypedL, and secondly by the natural ordering of the node value.
E.g., a '(UNode _)' is LT any other type of node, and a '(LNode (TypedL _ _))' is GT any other type of node, and the ordering of '(BNodeGen 44)' and '(BNodeGen 3)' is that of the values, or 'compare 44 3', GT.
A plain (untyped) literal value in an unspecified language.
|PlainLL !ByteString !ByteString|
A plain (untyped) literal value with a language specifier.
|TypedL !ByteString !FastString|
A typed literal value consisting of the literal value and the URI of the datatype of the value, respectively.
Supporting types and functions
The base URL of an RDF.
An alias for a map from prefix to namespace URI.
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.
A mapping of a prefix to the URI for that prefix.
The selector is said to select, or match, the nodes for
which it returns
When used in conjunction with the
select method of
node selectors are used to match a triple.
Determine whether two triples have equal predicates.
This determines if two RDF representations are equal regardless of blank nodc names, triple order and prefixes. In math terms, this is the simeq latex operator, or ~=
Lists of all subjects of triples with the given predicate.
Lists of all objects of triples with the given predicate.
Represents a failure in parsing an N-Triples document, including an error message with information about the cause for the failure.
FastString is a bytestring-based string type that provides constant-time equality
FastString value consists of a unique identifier and a (strict)
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
maintained internally in reverse order of the string passed to
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).
FastString value for the given
ByteString, reusing a
if one has been created for equal bytestrings, or creating a new one if necessary.
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
will generally not be assigned the same identifier under different processes and
A convenience function for converting from a string to a bytestring.
A convenience function for converting from a bytestring to a string.
Return a PlainLL LValue for the given string value and language, respectively.
Return a TypedL LValue for the given string value and datatype URI, respectively.
Convert a parse result into an RDF if it was successful and error and terminate if not.
A safe version of head that returns
Nothing for an empty list or 'Just (head lst)' for
a non-empty list.