rdf-0.1.0.5: Representation and Incremental Processing of RDF Data
CopyrightTravis Whitaker 2016
LicenseMIT
Maintainerpi.boy.travis@gmail.com
StabilityProvisional
PortabilityPortable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.RDF.Parser.NQuads

Description

A parser for RDF 1.1 N-Quads.

Synopsis

Documentation

type Result = Either String RDFGraph Source #

Either an RDFGraph or a parse error.

parseNQuads :: Text -> [Result] Source #

A parser for RDF 1.1 N-Quads. This parser works incrementally by first lazily splitting the input into lines, then parsing each line of the N-Quads document individually. This allows for incremental processing in constant space, as well as extracting any valid data from an N-Quads document that contains some invalid quads. Text is used because the RDF 1.1 specification stipulates that RDF should always be encoded with Unicode.

Due to its incremental nature, this parser will accept some N-Quads documents that are not legal according to the RDF 1.1 specification. Specifically, this parser will provide duplicate Triples if they exist in the input N-Quads document; a proper graph consists of true sets of nodes and edges, i.e. no duplicate nodes or edges. Any downstream program incrementally consuming this parser's output should take care to ignore any supernumerary triples.

Likewise, if a graph's constituent triples are not contiguous in the input N-Quads document, then they will not be folded into contiguous RDFGraphs in this parser's output. Any downstream program incrementally consuming this parser's output and performing graph processing that discriminates based on graph labels will not necessarily be presented each contiguous labeled graph as a single RDFGraph record. For example, something like this could be used to lazily find all RDFGraph records containing a named graph's Triples. Downstream processing must then be able to handle a single named graph spanning multiple RDFGraph records.

filterGraph :: (Maybe IRI) -> [RDFGraph] -> [RDFGraph]
filterGraph gl = filter (\g -> (graphLabel g) == gl)

parseTriple :: Parser Triple Source #

Parse a single N-Quads Triple.

parseQuad :: Parser Quad Source #

Parse a single N-Quads Quad.

parseQuadLine :: Parser Quad Source #

Parse a single N-Quads Quad on its own line. This parser is suitable for using Attoparsec's incremental input mechanism parse/feed instead of a lazy Text.

foldGraphs :: [Quad] -> [RDFGraph] Source #

Fold a list of Quads into a list of RDFGraphs, where adjacent Quads in the input are included in the same RDFGraph.

foldResults :: [Either String Quad] -> [Result] Source #

Fold a list of parsed Quads into a list of parsed RDFGraphs, where adjacent Quads in the input are included in the same RDFGraph.