swish-0.10.4.0: A semantic web toolkit.

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

Swish.Monad

Contents

- Create and modify the Swish state
- Error handling

Description

Composed state and IO monad for Swish

Synopsis

- type SwishStateIO a = StateT SwishState IO a
- data SwishState = SwishState {
  - format :: SwishFormat
  - base :: Maybe QName
  - graph :: RDFGraph
  - graphs :: NamedGraphMap
  - rules :: RDFRuleMap
  - rulesets :: RDFRulesetMap
  - infomsg :: Maybe String
  - errormsg :: Maybe String
  - exitcode :: SwishStatus
  }
- data SwishStatus
  - = SwishSuccess
  - | SwishGraphCompareError
  - | SwishDataInputError
  - | SwishDataAccessError
  - | SwishArgumentError
  - | SwishExecutionError
- data SwishFormat
  - = Turtle
  - | N3
  - | NT
- type NamedGraphMap = Map ScopedName [RDFGraph]
- emptyState :: SwishState
- setFormat :: SwishFormat -> SwishState -> SwishState
- setBase :: Maybe QName -> SwishState -> SwishState
- setGraph :: RDFGraph -> SwishState -> SwishState
- modGraphs :: (NamedGraphMap -> NamedGraphMap) -> SwishState -> SwishState
- findGraph :: ScopedName -> SwishState -> Maybe [RDFGraph]
- findFormula :: ScopedName -> SwishState -> Maybe RDFFormula
- modRules :: (RDFRuleMap -> RDFRuleMap) -> SwishState -> SwishState
- findRule :: ScopedName -> SwishState -> Maybe RDFRule
- modRulesets :: (RDFRulesetMap -> RDFRulesetMap) -> SwishState -> SwishState
- findRuleset :: ScopedName -> SwishState -> Maybe RDFRuleset
- findOpenVarModify :: ScopedName -> SwishState -> Maybe RDFOpenVarBindingModify
- findDatatype :: ScopedName -> SwishState -> Maybe RDFDatatype
- setInfo :: String -> SwishState -> SwishState
- resetInfo :: SwishState -> SwishState
- setError :: String -> SwishState -> SwishState
- resetError :: SwishState -> SwishState
- setStatus :: SwishStatus -> SwishState -> SwishState
- swishError :: String -> SwishStatus -> SwishStateIO ()
- reportLine :: String -> SwishStateIO ()

# Documentation

type SwishStateIO a = StateT SwishState IO a Source #

The state monad used in executing Swish programs.

data SwishState Source #

The State for a Swish "program".

Constructors

SwishState |

Fields

- format :: SwishFormat

  format to use for I/O

- base :: Maybe QName

  base to use rather than file name

- graph :: RDFGraph

  current graph

- graphs :: NamedGraphMap

  script processor named graphs

- rules :: RDFRuleMap

  script processor named rules

- rulesets :: RDFRulesetMap

  script processor rulesets

- infomsg :: Maybe String

  information message, or Nothing

- errormsg :: Maybe String

  error message, or Nothing

- exitcode :: SwishStatus

  current status

data SwishStatus Source #

Status of the processor

Constructors

SwishSuccess | successful run
SwishGraphCompareError | graphs do not compare
SwishDataInputError | input data problem (ie format/syntax)
SwishDataAccessError | data access error
SwishArgumentError | command-line argument error
SwishExecutionError | error executing a Swish script

#### Instances

Instances details

Enum SwishStatus Source # |

Instance details

Defined in Swish.Monad

Methods

succ :: SwishStatus -> SwishStatus Source #

pred :: SwishStatus -> SwishStatus Source #

toEnum :: Int -> SwishStatus Source #

fromEnum :: SwishStatus -> Int Source #

enumFrom :: SwishStatus -> [SwishStatus] Source #

enumFromThen :: SwishStatus -> SwishStatus -> [SwishStatus] Source #

enumFromTo :: SwishStatus -> SwishStatus -> [SwishStatus] Source #

enumFromThenTo :: SwishStatus -> SwishStatus -> SwishStatus -> [SwishStatus] Source #

Show SwishStatus Source # |
Instance details Defined in Swish.Monad Methods showsPrec :: Int -> SwishStatus -> ShowS Source # show :: SwishStatus -> String Source # showList :: [SwishStatus] -> ShowS Source #
Eq SwishStatus Source # |
Instance details Defined in Swish.Monad Methods (==) :: SwishStatus -> SwishStatus -> Bool Source # (/=) :: SwishStatus -> SwishStatus -> Bool Source #

data SwishFormat Source #

The supported input and output formats.

Constructors

Turtle | Turtle format
N3 | N3 format
NT | NTriples format

#### Instances

Instances details

Show SwishFormat Source # |
Instance details Defined in Swish.Monad Methods showsPrec :: Int -> SwishFormat -> ShowS Source # show :: SwishFormat -> String Source # showList :: [SwishFormat] -> ShowS Source #
Eq SwishFormat Source # |
Instance details Defined in Swish.Monad Methods (==) :: SwishFormat -> SwishFormat -> Bool Source # (/=) :: SwishFormat -> SwishFormat -> Bool Source #

type NamedGraphMap = Map ScopedName [RDFGraph] Source #

A LookupMap for the graphs dictionary.

# Create and modify the Swish state

emptyState :: SwishState Source #

The default state for Swish: no loaded graphs or rules, and format set to `N3`.

setFormat :: SwishFormat -> SwishState -> SwishState Source #

Change the format.

setBase :: Maybe QName -> SwishState -> SwishState Source #

Change (or remove) the base URI.

setGraph :: RDFGraph -> SwishState -> SwishState Source #

Change the current graph.

modGraphs :: (NamedGraphMap -> NamedGraphMap) -> SwishState -> SwishState Source #

Modify the named graphs.

findGraph :: ScopedName -> SwishState -> Maybe [RDFGraph] Source #

Find a named graph.

findFormula :: ScopedName -> SwishState -> Maybe RDFFormula Source #

Find a formula. The search is first made in the named graphs and then, if not found, the rulesets.

modRules :: (RDFRuleMap -> RDFRuleMap) -> SwishState -> SwishState Source #

Modify the named rules.

findRule :: ScopedName -> SwishState -> Maybe RDFRule Source #

Find a named rule.

modRulesets :: (RDFRulesetMap -> RDFRulesetMap) -> SwishState -> SwishState Source #

Modify the rule sets.

findRuleset :: ScopedName -> SwishState -> Maybe RDFRuleset Source #

Find a rule set.

findOpenVarModify :: ScopedName -> SwishState -> Maybe RDFOpenVarBindingModify Source #

Find a modify rule.

findDatatype :: ScopedName -> SwishState -> Maybe RDFDatatype Source #

Find a data type declaration.

setInfo :: String -> SwishState -> SwishState Source #

Set the information message.

resetInfo :: SwishState -> SwishState Source #

Clear the information message.

setError :: String -> SwishState -> SwishState Source #

Set the error message.

resetError :: SwishState -> SwishState Source #

Clear the error message.

setStatus :: SwishStatus -> SwishState -> SwishState Source #

Set the status.

# Error handling

swishError :: String -> SwishStatus -> SwishStateIO () Source #

Report error and set exit status code

reportLine :: String -> SwishStateIO () Source #

Output the text to the standard error stream (a new line is added to the output).