swish-0.10.1.0: A semantic web toolkit.

Copyright | (c) 2003 Graham Klyne 2009 Vasili I Galchin 2011 2012 2016 2020 Douglas Burke
License | GPL V2
Maintainer | Douglas Burke
Stability | experimental
Portability | CPP, DeriveFunctor, DeriveFoldable, DeriveTraversable, MultiParamTypeClasses
Safe Haskell | Safe
Language | Haskell2010

Swish.GraphClass

Description

This module defines a Labelled Directed Graph and Label classes, and the Arc datatype.

Synopsis

- class LDGraph lg lb where
  - emptyGraph :: lg lb
  - setArcs :: lg lb -> ArcSet lb -> lg lb
  - getArcs :: lg lb -> ArcSet lb
  - extract :: Ord lb => Selector lb -> lg lb -> lg lb
  - addGraphs :: Ord lb => lg lb -> lg lb -> lg lb
  - delete :: Ord lb => lg lb -> lg lb -> lg lb
  - labels :: Ord lb => lg lb -> Set lb
  - nodes :: Ord lb => lg lb -> Set lb
  - update :: (ArcSet lb -> ArcSet lb) -> lg lb -> lg lb
- class (Ord lb, Show lb) => Label lb where
  - labelIsVar :: lb -> Bool
  - labelHash :: Int -> lb -> Int
  - getLocal :: lb -> String
  - makeLabel :: String -> lb
- data Arc lb = Arc {
  - arcSubj :: lb
  - arcPred :: lb
  - arcObj :: lb
  }
- type ArcSet lb = Set (Arc lb)
- type Selector lb = Arc lb -> Bool
- arc :: lb -> lb -> lb -> Arc lb
- arcToTriple :: Arc lb -> (lb, lb, lb)
- arcFromTriple :: (lb, lb, lb) -> Arc lb
- hasLabel :: Eq lb => lb -> Arc lb -> Bool
- arcLabels :: Arc lb -> [lb]
- getComponents :: Ord b => (a -> [b]) -> Set a -> Set b

# Documentation

class LDGraph lg lb where Source #

Labelled Directed Graph class.

Minimum required implementation: `emptyGraph`, `setArcs`, and `getArcs`.

Minimal complete definition

emptyGraph, setArcs, getArcs

Methods

emptyGraph :: lg lb Source #

Create the empty graph.

setArcs :: lg lb -> ArcSet lb -> lg lb Source #

Replace the existing arcs in the graph.

getArcs :: lg lb -> ArcSet lb Source #

Extract all the arcs from a graph

extract :: Ord lb => Selector lb -> lg lb -> lg lb Source #

Extract those arcs that match the given `Selector`.

addGraphs :: Ord lb => lg lb -> lg lb -> lg lb Source #

Add the two graphs

delete Source #

Arguments

:: Ord lb |
=> lg lb | g1
-> lg lb | g2
-> lg lb | g2 - g1 -> g3

Remove those arcs in the first graph from the second graph

labels :: Ord lb => lg lb -> Set lb Source #

Enumerate the distinct labels contained in a graph; that is, any label that appears in the subject, predicate or object position of an `Arc`.

nodes :: Ord lb => lg lb -> Set lb Source #

Enumerate the distinct nodes contained in a graph; that is, any label that appears in the subject or object position of an `Arc`.

update :: (ArcSet lb -> ArcSet lb) -> lg lb -> lg lb Source #

Update the arcs in a graph using a supplied function.

#### Instances

Instances details

LDGraph GraphMem lb Source # |

Instance details

Defined in Swish.GraphMem

Methods

emptyGraph :: GraphMem lb Source #

setArcs :: GraphMem lb -> ArcSet lb -> GraphMem lb Source #

getArcs :: GraphMem lb -> ArcSet lb Source #

extract :: Selector lb -> GraphMem lb -> GraphMem lb Source #

addGraphs :: GraphMem lb -> GraphMem lb -> GraphMem lb Source #

delete :: GraphMem lb -> GraphMem lb -> GraphMem lb Source #

labels :: GraphMem lb -> Set lb Source #

nodes :: GraphMem lb -> Set lb Source #

update :: (ArcSet lb -> ArcSet lb) -> GraphMem lb -> GraphMem lb Source #

LDGraph NSGraph lb Source # |

Instance details

Defined in Swish.RDF.Graph

Methods

emptyGraph :: NSGraph lb Source #

setArcs :: NSGraph lb -> ArcSet lb -> NSGraph lb Source #

getArcs :: NSGraph lb -> ArcSet lb Source #

extract :: Selector lb -> NSGraph lb -> NSGraph lb Source #

addGraphs :: NSGraph lb -> NSGraph lb -> NSGraph lb Source #

delete :: NSGraph lb -> NSGraph lb -> NSGraph lb Source #

labels :: NSGraph lb -> Set lb Source #

nodes :: NSGraph lb -> Set lb Source #

update :: (ArcSet lb -> ArcSet lb) -> NSGraph lb -> NSGraph lb Source #

class (Ord lb, Show lb) => Label lb where Source #

Label class.

A label may have a fixed binding, which means that the label identifies (is) a particular graph node, and different such labels are always distinct nodes. Alternatively, a label may be unbound (variable), which means that it is a placeholder for an unknown node label. Unbound node labels are used as graph-local identifiers for indicating when the same node appears in several arcs.

For the purposes of graph-isomorphism testing, fixed labels are matched when they are the same. Variable labels may be matched with any other variable label. Our definition of isomorphism (for RDF graphs) does not match variable labels with fixed labels.

Methods

labelIsVar :: lb -> Bool Source #

Does this node have a variable binding?

labelHash :: Int -> lb -> Int Source #

Calculate the hash of the label using the supplied seed.

getLocal :: lb -> String Source #

Extract the local id from a variable node.

makeLabel :: String -> lb Source #

Make a label value from a local id.

#### Instances

Instances details

Label LabelMem Source # |
Instance details Defined in Swish.GraphMem Methods labelIsVar :: LabelMem -> Bool Source # labelHash :: Int -> LabelMem -> Int Source # getLocal :: LabelMem -> String Source # makeLabel :: String -> LabelMem Source #
Label RDFLabel Source # |
Instance details Defined in Swish.RDF.Graph Methods labelIsVar :: RDFLabel -> Bool Source # labelHash :: Int -> RDFLabel -> Int Source # getLocal :: RDFLabel -> String Source # makeLabel :: String -> RDFLabel Source #
Label lb => Label (ScopedLabel lb) Source # |
Instance details Defined in Swish.GraphMatch Methods labelIsVar :: ScopedLabel lb -> Bool Source # labelHash :: Int -> ScopedLabel lb -> Int Source # getLocal :: ScopedLabel lb -> String Source # makeLabel :: String -> ScopedLabel lb Source #

data Arc lb Source #

Arc type.

Prior to `0.7.0.0` you could also use `asubj`, `apred` and `aobj` to access the elements of the arc.

Constructors

Arc |

Fields

- arcSubj :: lb

  The subject of the arc.

- arcPred :: lb

  The predicate (property) of the arc.

- arcObj :: lb

  The object of the arc.

#### Instances

Instances details

Functor Arc Source # |
Instance details Defined in Swish.GraphClass Methods fmap :: (a -> b) -> Arc a -> Arc b Source # (<$) :: a -> Arc b -> Arc a Source #
Foldable Arc Source # |

Instance details

Defined in Swish.GraphClass

Methods

fold :: Monoid m => Arc m -> m Source #

foldMap :: Monoid m => (a -> m) -> Arc a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Arc a -> m Source #

foldr :: (a -> b -> b) -> b -> Arc a -> b Source #

foldr' :: (a -> b -> b) -> b -> Arc a -> b Source #

foldl :: (b -> a -> b) -> b -> Arc a -> b Source #

foldl' :: (b -> a -> b) -> b -> Arc a -> b Source #

foldr1 :: (a -> a -> a) -> Arc a -> a Source #

foldl1 :: (a -> a -> a) -> Arc a -> a Source #

toList :: Arc a -> [a] Source #

null :: Arc a -> Bool Source #

length :: Arc a -> Int Source #

elem :: Eq a => a -> Arc a -> Bool Source #

maximum :: Ord a => Arc a -> a Source #

minimum :: Ord a => Arc a -> a Source #

sum :: Num a => Arc a -> a Source #

product :: Num a => Arc a -> a Source #

Traversable Arc Source # |
Instance details Defined in Swish.GraphClass Methods traverse :: Applicative f => (a -> f b) -> Arc a -> f (Arc b) Source # sequenceA :: Applicative f => Arc (f a) -> f (Arc a) Source # mapM :: Monad m => (a -> m b) -> Arc a -> m (Arc b) Source # sequence :: Monad m => Arc (m a) -> m (Arc a) Source #
Eq lb => Eq (Arc lb) Source # |
Instance details Defined in Swish.GraphClass Methods (==) :: Arc lb -> Arc lb -> Bool Source # (/=) :: Arc lb -> Arc lb -> Bool Source #
Ord lb => Ord (Arc lb) Source # |
Instance details Defined in Swish.GraphClass Methods compare :: Arc lb -> Arc lb -> Ordering Source # (<) :: Arc lb -> Arc lb -> Bool Source # (<=) :: Arc lb -> Arc lb -> Bool Source # (>) :: Arc lb -> Arc lb -> Bool Source # (>=) :: Arc lb -> Arc lb -> Bool Source # max :: Arc lb -> Arc lb -> Arc lb Source # min :: Arc lb -> Arc lb -> Arc lb Source #
Show lb => Show (Arc lb) Source # |
Instance details Defined in Swish.GraphClass Methods showsPrec :: Int -> Arc lb -> ShowS Source # show :: Arc lb -> String Source # showList :: [Arc lb] -> ShowS Source #
Hashable lb => Hashable (Arc lb) Source # |
Instance details Defined in Swish.GraphClass Methods hashWithSalt :: Int -> Arc lb -> Int Source # hash :: Arc lb -> Int Source #

type ArcSet lb = Set (Arc lb) Source #

A set - or graph - of arcs.

type Selector lb = Arc lb -> Bool Source #

Identify arcs.

arc Source #

Arguments

:: lb | The subject of the arc.
-> lb | The predicate of the arc.
-> lb | The object of the arc.
-> Arc lb |

Create an arc.

arcToTriple :: Arc lb -> (lb, lb, lb) Source #

Convert an Arc into a tuple.

arcFromTriple :: (lb, lb, lb) -> Arc lb Source #

Create an Arc from a tuple.

hasLabel :: Eq lb => lb -> Arc lb -> Bool Source #

Does the arc contain the label in any position (subject, predicate, or object)?

arcLabels :: Arc lb -> [lb] Source #

Return all the labels in an arc.

getComponents :: Ord b => (a -> [b]) -> Set a -> Set b Source #

Extract components from a set.