swish-0.10.4.0: A semantic web toolkit.

Copyright | (c) 2003 Graham Klyne 2009 Vasili I Galchin 2011 2012 2013 2014 2018 2020 Douglas Burke
License | GPL V2
Maintainer | Douglas Burke
Stability | experimental
Portability | CPP, OverloadedStrings
Safe Haskell | Safe-Inferred
Language | Haskell2010

Swish.RDF.Parser.N3

Contents

- Exports for parsers that embed Notation3 in a bigger syntax

Description

This Module implements a Notation 3 parser, returning a new `RDFGraph` consisting of triples and namespace information parsed from the supplied N3 input string, or an error indication.

REFERENCES:

- "Notation3 (N3): A readable RDF syntax", W3C Team Submission 14 January 2008, http://www.w3.org/TeamSubmission/2008/SUBM-n3-20080114/
- Tim Berners-Lee's design issues series notes and description, http://www.w3.org/DesignIssues/Notation3.html
- Notation 3 Primer by Sean Palmer, http://www.w3.org/2000/10/swap/Primer.html

NOTES:

- The parser needs to be updated to the latest version ("W3C Team Submission 28 March 2011", http://www.w3.org/TeamSubmission/2011/SUBM-n3-20110328/)
- UTF-8 handling is not really tested.
- No performance testing has been applied.
- Not all N3 grammar elements are supported, including:
- `@forSome` (we read it in but ignore the arguments)
- `@forAll` (this causes a parse error)
- formulae are lightly tested
- string support is incomplete (e.g. unrecognized escape characters such as `\q` are probably handled incorrectly)

Synopsis

- type ParseResult = Either String RDFGraph
- parseN3 :: Text -> Maybe QName -> ParseResult
- parseN3fromText :: Text -> ParseResult
- parseAnyfromText :: N3Parser a -> Maybe QName -> Text -> Either String a
- parseTextFromText :: String -> Text -> Either String String
- parseAltFromText :: String -> String -> Text -> Either String String
- parseNameFromText :: Text -> Either String String
- parseAbsURIrefFromText :: Text -> Either String URI
- parseLexURIrefFromText :: Text -> Either String URI
- parseURIref2FromText :: Text -> Either String ScopedName
- type N3Parser a = Parser N3State a
- data N3State = N3State {
  - graphState :: RDFGraph
  - thisNode :: RDFLabel
  - prefixUris :: NamespaceMap
  - syntaxUris :: SpecialMap
  - nodeGen :: Word32
  - keywordsList :: [Text]
  - allowLocalNames :: Bool
  }
- type SpecialMap = Map String ScopedName
- getPrefix :: N3Parser ()
- n3symbol :: N3Parser ScopedName
- quickVariable :: N3Parser RDFLabel
- lexUriRef :: N3Parser URI
- document :: N3Parser RDFGraph
- subgraph :: RDFLabel -> N3Parser RDFGraph
- newBlankNode :: N3Parser RDFLabel

# Documentation

type ParseResult = Either String RDFGraph Source #

The result of a parse, which is either an error message or a graph.

parseN3 Source #

Arguments

:: Text | input in N3 format.
-> Maybe QName | optional base URI
-> ParseResult |

Parse a string with an optional base URI.

See also `parseN3fromString`.

parseN3fromText Source #

Arguments

:: Text | input in N3 format.
-> ParseResult |

Parse a string as N3 (with no real base URI).

See `parseN3` if you need to provide a base URI.

parseAnyfromText Source #

Arguments

:: N3Parser a | parser to apply
-> Maybe QName | base URI of the input, or `Nothing` to use default base value
-> Text | input to be parsed
-> Either String a |

Function to supply initial context and parse supplied term.

parseTextFromText :: String -> Text -> Either String String Source #

Used in testing.

parseAltFromText :: String -> String -> Text -> Either String String Source #

Used in testing.

parseNameFromText :: Text -> Either String String Source #

Used in testing.

parseAbsURIrefFromText :: Text -> Either String URI Source #

Used in testing.

parseLexURIrefFromText :: Text -> Either String URI Source #

Used in testing.

parseURIref2FromText :: Text -> Either String ScopedName Source #

Used in testing.

# Exports for parsers that embed Notation3 in a bigger syntax

type N3Parser a = Parser N3State a Source #

The N3 parser.

data N3State Source #

N3 parser state

Constructors

N3State |

Fields

- graphState :: RDFGraph
- thisNode :: RDFLabel
- prefixUris :: NamespaceMap
- syntaxUris :: SpecialMap
- nodeGen :: Word32
- keywordsList :: [Text]
- allowLocalNames :: Bool

type SpecialMap = Map String ScopedName Source #

Type for special name lookup table

getPrefix :: N3Parser () Source #

Process the remainder of an `@prefix` line (after this has been processed). The prefix value and URI are added to the parser state.

n3symbol :: N3Parser ScopedName Source #

Match a N3 symbol (an explicit URI or a QName) and convert it to a `ScopedName`.

quickVariable :: N3Parser RDFLabel Source #

Match `?name`.

lexUriRef :: N3Parser URI Source #

An explicitly given URI followed by white space.

document :: N3Parser RDFGraph Source #

Process a N3 document, returning a graph.

subgraph :: RDFLabel -> N3Parser RDFGraph Source #

Process a sub graph and assign it to the given label.

newBlankNode :: N3Parser RDFLabel Source #

Create a new blank node.