Hets - the Heterogeneous Tool Set

Copyright(c) DFKI GmbH 2012
LicenseGPLv2 or higher, see LICENSE.txt
MaintainerEugen Kuksa <eugenk@informatik.uni-bremen.de>
Stabilityprovisional
Portabilityportable
Safe HaskellSafe-Inferred

Common.IRI

Contents

Description

This module defines functions for handling IRIs. It was adopted from the Network.URI module by Graham Klyne, but is extended to IRI support [2] and even Manchester-Syntax-IRI [3], [4] and CURIE [5].

Four methods are provided for parsing different kinds of IRI string (as noted in [1], [2]): parseIRI parseIRIReference

An additional method is provided for parsing an abbreviated IRI according to [3], [4]: parseIRIManchester and according to [5]: parseIRICurie

Additionally, classification of full, abbreviated and simple IRI is provided.

The abbreviated syntaxes [3], [4], [5] provide three different kinds of IRI.

References

  1. http://www.ietf.org/rfc/rfc3986.txt
  2. http://www.ietf.org/rfc/rfc3987.txt
  3. http://www.w3.org/TR/2009/NOTE-owl2-manchester-syntax-20091027/
  4. http://www.w3.org/TR/2008/REC-rdf-sparql-query-20080115/
  5. http://www.w3.org/TR/rdfa-core/#s_curies

Synopsis

Documentation

data IRI

Represents a general universal resource identifier using its component parts.

For example, for the (full) IRI

  foo://anonymous@www.haskell.org:42/ghc?query#frag

or the abbreviated IRI

  prefix:abbrevPath?abbrevQuery#abbrevFragment

or the simple IRI

 abbrevPath

Constructors

IRI 

Fields

iriScheme :: String
foo:
iriAuthority :: Maybe IRIAuth
//anonymous@www.haskell.org:42
iriPath :: String

local part /ghc

iriQuery :: String
?query
iriFragment :: String
#frag
prefixName :: String
prefix
abbrevPath :: String
abbrevPath
abbrevQuery :: String
abbrevQueryh
abbrevFragment :: String
abbrevFragment
hasAngles :: Bool

IRI in angle brackets

iriPos :: Range

position

data IRIAuth

Type for authority value within a IRI

Constructors

IRIAuth String String String 

data PNameLn

Constructors

PNameLn PNameNs PnLocal 

nullIRI :: IRI

Blank IRI

iriToStringUnsecure :: IRI -> String

converts IRI to String of expanded form. if available. Also showing Auth

iriToStringShortUnsecure :: IRI -> String

converts IRI to String of abbreviated form. if available. Also showing Auth info.

hasFullIRI :: IRI -> Bool

do we have a full (possibly expanded) IRI (i.e. for comparisons)

isAbbrev :: IRI -> Bool

do we have an abbreviated IRI (i.e. for pretty printing)

isSimple :: IRI -> Bool

do we have a simple IRI that is a (possibly expanded) abbreviated IRI without prefix

Parsing

iriManchester :: IRIParser st IRI

parseIRIManchester :: String -> Maybe IRI

Turn a string containing an IRI (by Manchester-syntax) into an IRI. Returns Nothing if the string is not a valid IRI; (an absolute IRI enclosed in < and > with optional fragment identifier, an abbreviated IRI or a simple IRI).

iriCurie :: IRIParser st IRI

Parses an absolute IRI enclosed in <, > or a CURIE

parseCurie :: String -> Maybe IRI

Turn a string containing a CURIE into an IRI

parseIRICurie :: String -> Maybe IRI

Turn a string containing an IRI or a CURIE into an IRI. Returns Nothing if the string is not a valid IRI; (an absolute IRI enclosed in < and > with optional fragment identifier or a CURIE).

parseIRIReference :: String -> Maybe IRI

Parse a IRI reference to an IRI value. Returns Nothing if the string is not a valid IRI reference. (an absolute or relative IRI with optional fragment identifier).

parseIRI :: String -> Maybe IRI

Turn a string containing an RFC3987 IRI into an IRI. Returns Nothing if the string is not a valid IRI; (an absolute IRI with optional fragment identifier).

ncname :: GenParser Char st String

Prefix part of CURIE in prefix_part:reference http://www.w3.org/TR/2009/REC-xml-names-20091208/#NT-NCName

expandCurie :: Map String IRI -> IRI -> Maybe IRI

Expands a CURIE to an IRI. Nothing iff there is no IRI i assigned to the prefix of c or the concatenation of i and abbrevPath c is not a valid IRI.

relativeTo :: IRI -> IRI -> Maybe IRI

Returns a new IRI which represents the value of the first IRI interpreted as relative to the second IRI. For example:

"foo" `relativeTo` "http://bar.org/" = "http://bar.org/foo"

relativeFrom :: IRI -> IRI -> IRI

Returns a new IRI which represents the relative location of the first IRI with respect to the second IRI. Thus, the values supplied are expected to be absolute IRIs, and the result returned may be a relative IRI.

Example:

"http://example.com/Root/sub1/name2#frag"
  `relativeFrom` "http://example.com/Root/sub2/name2#frag"
  == "../sub1/name2#frag"

There is no single correct implementation of this function, but any acceptable implementation must satisfy the following:

(uabs `relativeFrom` ubase) `relativeTo` ubase == uabs

For any valid absolute IRI. (cf. http://lists.w3.org/Archives/Public/iri/2003Jan/0008.html http://lists.w3.org/Archives/Public/iri/2003Jan/0005.html)

Conversion

simpleIdToIRI :: SIMPLE_ID -> IRI

Converts a Simple_ID to an IRI