Safe Haskell | None |
---|---|
Language | Haskell2010 |
The Core module exports all serializers and parsers, types, and query functions of the library.
Synopsis
- class (Generic rdfImpl, NFData rdfImpl) => Rdf rdfImpl where
- baseUrl :: RDF rdfImpl -> Maybe BaseUrl
- prefixMappings :: RDF rdfImpl -> PrefixMappings
- addPrefixMappings :: RDF rdfImpl -> PrefixMappings -> Bool -> RDF rdfImpl
- empty :: RDF rdfImpl
- mkRdf :: Triples -> Maybe BaseUrl -> PrefixMappings -> RDF rdfImpl
- addTriple :: RDF rdfImpl -> Triple -> RDF rdfImpl
- removeTriple :: RDF rdfImpl -> Triple -> RDF rdfImpl
- triplesOf :: RDF rdfImpl -> Triples
- uniqTriplesOf :: RDF rdfImpl -> Triples
- select :: RDF rdfImpl -> NodeSelector -> NodeSelector -> NodeSelector -> Triples
- query :: RDF rdfImpl -> Maybe Node -> Maybe Node -> Maybe Node -> Triples
- showGraph :: RDF rdfImpl -> String
- class RdfSerializer s where
- hWriteRdf :: Rdf a => s -> Handle -> RDF a -> IO ()
- writeRdf :: Rdf a => s -> RDF a -> IO ()
- hWriteH :: Rdf a => s -> Handle -> RDF a -> IO ()
- writeH :: Rdf a => s -> RDF a -> 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 RdfParser p where
- parseString :: Rdf a => p -> Text -> Either ParseFailure (RDF a)
- parseFile :: Rdf a => p -> String -> IO (Either ParseFailure (RDF a))
- parseURL :: Rdf a => p -> String -> IO (Either ParseFailure (RDF a))
- module Data.RDF.IRI
- module Data.RDF.Types
- module Data.RDF.Query
- module Data.RDF.Namespace
- module Data.RDF.Graph.TList
- module Data.RDF.Graph.AdjHashMap
- module Data.RDF.Graph.AlgebraicGraph
- module Text.RDF.RDF4H.NTriplesSerializer
- module Text.RDF.RDF4H.NTriplesParser
- module Text.RDF.RDF4H.TurtleSerializer
- module Text.RDF.RDF4H.TurtleParser
- module Text.RDF.RDF4H.XmlParser
Documentation
class (Generic rdfImpl, NFData rdfImpl) => Rdf rdfImpl where Source #
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.
baseUrl :: RDF rdfImpl -> Maybe BaseUrl Source #
Return the base URL of this RDF, if any.
prefixMappings :: RDF rdfImpl -> PrefixMappings Source #
Return the prefix mappings defined for this RDF, if any.
addPrefixMappings :: RDF rdfImpl -> PrefixMappings -> Bool -> RDF rdfImpl Source #
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.
mkRdf :: Triples -> Maybe BaseUrl -> PrefixMappings -> RDF rdfImpl Source #
Return a RDF containing all the given triples. Handling of duplicates in the input depend on the particular RDF implementation.
addTriple :: RDF rdfImpl -> Triple -> RDF rdfImpl Source #
Adds a triple to an RDF graph.
removeTriple :: RDF rdfImpl -> Triple -> RDF rdfImpl Source #
Removes all occurrences of a triple in an RDF graph.
triplesOf :: RDF rdfImpl -> 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 rdfImpl -> Triples Source #
Return unique triples in the RDF, as a list.
This function performs namespace expansion and removal of duplicates.
select :: RDF rdfImpl -> 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 rdfImpl -> 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.
showGraph :: RDF rdfImpl -> String Source #
pretty prints the RDF graph
Instances
class RdfSerializer s where Source #
An RdfSerializer is a serializer of RDF to some particular output format, such as NTriples or Turtle.
hWriteRdf :: Rdf a => s -> Handle -> RDF a -> IO () Source #
Write the RDF to a file handle using whatever configuration is specified by the first argument.
writeRdf :: Rdf a => s -> RDF a -> IO () Source #
Write the RDF to stdout; equivalent to
.hWriteRdf
stdout
hWriteH :: Rdf a => s -> Handle -> RDF a -> IO () Source #
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 :: Rdf a => s -> RDF a -> IO () Source #
Write header information to stdout; equivalent to
.hWriteRdf
stdout
hWriteTs :: s -> Handle -> Triples -> IO () Source #
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 () Source #
Write some triples to stdout; equivalent to
.hWriteTs
stdout
hWriteT :: s -> Handle -> Triple -> IO () Source #
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 () Source #
Write a single triple to stdout; equivalent to
.hWriteT
stdout
hWriteN :: s -> Handle -> Node -> IO () Source #
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 () Source #
Write a single node to sdout; equivalent to
.hWriteN
stdout
Instances
class RdfParser p where Source #
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.
parseString :: Rdf a => p -> Text -> Either ParseFailure (RDF a) Source #
Parse RDF from the given text, yielding a failure with error message or the resultant RDF.
parseFile :: Rdf a => p -> String -> IO (Either ParseFailure (RDF a)) Source #
Parse RDF from the local file with the given path, yielding a failure with error message or the resultant RDF in the IO monad.
parseURL :: Rdf a => p -> String -> IO (Either ParseFailure (RDF a)) Source #
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.
Instances
RDF types and query functions
module Data.RDF.IRI
module Data.RDF.Types
module Data.RDF.Query
module Data.RDF.Namespace
RDF type class instances
module Data.RDF.Graph.TList
module Data.RDF.Graph.AdjHashMap
RDF parsers and serializers
module Text.RDF.RDF4H.TurtleParser
module Text.RDF.RDF4H.XmlParser