-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Data types for named entities -- -- Please see the README on GitHub at -- https://github.com/kawu/data-named#readme @package data-named @version 0.6.2 -- | Implementation of a DAG with each node identified by a unique key. module Data.Named.DAG -- | A directed acyclic graph. data DAG k v DAG :: Graph -> (Vertex -> (v, k, [k])) -> (k -> Maybe Vertex) -> DAG k v -- | The underlying graph. [graph] :: DAG k v -> Graph -- | Map vertex identifier to a node description. [nodeDesc] :: DAG k v -> Vertex -> (v, k, [k]) -- | Map key to a vertex identifier. Return Nothing if the key is not a -- member of the graph. [maybeVertex] :: DAG k v -> k -> Maybe Vertex -- | Smart constructur which verifies that the graph is actually a DAG. -- Return Nothing if the input list constitutes a graph with cycles. mkDAG :: (Show k, Ord k) => [(v, k, [k])] -> Maybe (DAG k v) unDAG :: DAG k v -> [(v, k, [k])] -- | Map key to a vertex identifier. Report error if the key is not a -- member of the graph. vertex :: Show k => DAG k v -> k -> Vertex -- | The node for the given key. Report error if the key is not a member of -- the graph. node :: Show k => DAG k v -> k -> v -- | The edge list for the given key. Report error if the key is not a -- member of the graph. edges :: Show k => DAG k v -> k -> [k] -- | The node for the given key. Return Nothing if the key is not a member -- of the graph. maybeNode :: DAG k v -> k -> Maybe v -- | The edge list for the given key. Return Nothing if the key is not a -- member of the graph. maybeEdges :: DAG k v -> k -> Maybe [k] nodeV :: DAG k v -> Vertex -> v keyV :: DAG k v -> Vertex -> k edgesV :: DAG k v -> Vertex -> [k] -- | Spanning forest of the DAG using the standard compare function -- to compare keys kept in DAG leaves. Overloaded version of the -- toForestBy function. toForest :: (Show k, Ord k) => DAG k v -> Forest k -- | Spanning forest of the DAG. Non-overloaded version of the -- toForest function. The comparison function is used to sort the -- list of leaves and the spanning tree is computed with respect to the -- resulting order. toForestBy :: (Show k, Ord k) => (k -> k -> Ordering) -> DAG k v -> Forest k roots :: Ord k => DAG k v -> [k] leaves :: DAG k v -> [k] -- | Working with NE trees and forests. module Data.Named.Tree -- | A tree with a values in internal nodes and b values in leaves. type NeTree a b = Tree (Either a b) -- | A forest with a values in internal nodes and b values in leaves. type NeForest a b = Forest (Either a b) -- | Spanning of a tree. data Span w Span :: w -> w -> Span w [beg] :: Span w -> w [end] :: Span w -> w -- | Make span for a leaf node. leafSpan :: w -> Span w -- | Minimum span overlapping both input spans. (<>) :: Ord w => Span w -> Span w -> Span w -- | Set of positions covered by the span. spanSet :: Ix w => Span w -> Set w -- | Get span of the span-annotated tree. span :: Tree (a, Span w) -> Span w -- | Annotate tree nodes with spanning info given the function which -- assignes indices to leaf nodes. spanTree :: Ord w => Tree (Either n w) -> Tree (Either n w, Span w) -- | Annotate forest nodes with spanning info. spanForest :: Ord w => Forest (Either n w) -> Forest (Either n w, Span w) -- | Remove span annotations from the tree. unSpanTree :: Tree (k, Span w) -> Tree k -- | Remove span annotations from the forest. unSpanForest :: Forest (k, Span w) -> Forest k -- | Sort the tree with respect to spanning info. sortTree :: Ord w => Tree (k, Span w) -> Tree (k, Span w) -- | Sort the forest with respect to spanning info. sortForest :: Ord w => Forest (k, Span w) -> Forest (k, Span w) -- | Map function over each tree from the forest. mapForest :: (a -> b) -> Forest a -> Forest b -- | Map function over the tree. mapTree :: (a -> b) -> Tree a -> Tree b -- | Map function over the leaf value. onLeaf :: (a -> b) -> Either c a -> Either c b -- | Map function over the internal node value. onNode :: (a -> b) -> Either a c -> Either b c -- | Map the first function over internal node value and the second one -- over leaf value. onEither :: (a -> c) -> (b -> d) -> Either a b -> Either c d -- | Map one function over both node and leaf values. onBoth :: (a -> b) -> Either a a -> Either b b -- | Group leaves with respect to the given equality function. groupForestLeaves :: (b -> b -> Bool) -> NeForest a b -> NeForest a [b] -- | Group leaves with respect to the given equality function. groupTreeLeaves :: (b -> b -> Bool) -> NeTree a b -> NeTree a [b] -- | Group leaves with respect to the given equality function. concatForestLeaves :: NeForest a [b] -> NeForest a b -- | Group leaves with respect to the given equality function. concatTreeLeaves :: NeTree a [b] -> NeForest a b instance GHC.Classes.Ord w => GHC.Classes.Ord (Data.Named.Tree.Span w) instance GHC.Classes.Eq w => GHC.Classes.Eq (Data.Named.Tree.Span w) instance GHC.Show.Show w => GHC.Show.Show (Data.Named.Tree.Span w) -- | IOB encoding method extended to forests. -- -- Example: -- --
--   >>> :m Data.Named.IOB Data.Named.Tree Text.Named.Enamex Data.Text.Lazy
--   
--   >>> let enamex = pack "<x>w1.1\\ w1.2</x> w2 <y><z>w3</z> w4</y>"
--   
-- --
--   >>> putStr . drawForest . mapForest show . parseForest $ enamex
--   Left "x"
--   |
--   `- Right "w1.1 w1.2"
--   ,
--   Right "w2"
--   ,
--   Left "y"
--   |
--   +- Left "z"
--   |  |
--   |  `- Right "w3"
--   |
--   `- Right "w4"
--   
-- --
--   >>> mapM_ print . encodeForest . parseForest $ enamex
--   IOB {word = "w1.1 w1.2", label = [B "x"]}
--   IOB {word = "w2", label = []}
--   IOB {word = "w3", label = [B "y",B "z"]}
--   IOB {word = "w4", label = [I "y"]}
--   
module Data.Named.IOB -- | An IOB data structure consists of a word with a corresponding -- compound label. data IOB w a IOB :: w -> Label a -> IOB w a [word] :: IOB w a -> w [label] :: IOB w a -> Label a -- | A Label consists of a list of atomic Atom labels. type Label a = [Atom a] -- | An Atom is the atomic label with additional marker. data Atom a -- | Beginning marker B :: a -> Atom a -- | Inside marker I :: a -> Atom a -- | Encode the forest with the IOB method. encodeForest :: NeForest a w -> [IOB w a] -- | Decode the forest using the IOB method. decodeForest :: Eq a => [IOB w a] -> NeForest a w instance (GHC.Show.Show w, GHC.Show.Show a) => GHC.Show.Show (Data.Named.IOB.IOB w a) instance GHC.Base.Functor Data.Named.IOB.Atom instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Named.IOB.Atom a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Named.IOB.Atom a) instance GHC.Show.Show a => GHC.Show.Show (Data.Named.IOB.Atom a) instance Data.Binary.Class.Binary a => Data.Binary.Class.Binary (Data.Named.IOB.Atom a) -- | Implementation of a graph with each internal node identified by a -- unique key and each leaf represented by a position in the sentence. module Data.Named.Graph -- | A graph over a sentence. data Graph n w Graph :: (w, w) -> Map n [Either n w] -> Graph n w [bounds] :: Graph n w -> (w, w) [edgeMap] :: Graph n w -> Map n [Either n w] -- | Make a graph given the bounds and list of edges. mkGraph :: (Ord n, Ix w) => (w, w) -> [(n, [Either n w])] -> Graph n w -- | Get keys of adjacent nodes for the given node key. edges :: Ord n => Graph n w -> n -> [Either n w] -- | Return all graph roots (i.e. nodes with no parents). roots :: Ord n => Graph n w -> [n] -- | Transform a graph into a disjoint forest, i.e. a forest with no -- mutually overlapping trees. The process is lossy, discontinuity and -- overlapping cannot be represented with the NeForest data type. toForest :: (Ord n, Ix w) => Graph n w -> NeForest n w instance GHC.Base.Functor (Data.Named.Graph.RanM w) instance GHC.Base.Applicative (Data.Named.Graph.RanM w) instance GHC.Base.Monad (Data.Named.Graph.RanM w) -- | Parsing text in the Enamex data format. Each node is enclosed between -- opening and closing tags with tag name representing the label and -- contents representing children of the node. Both leaf and label values -- should be escaped by prepending the \ character before special >, -- <, \ and space characters. -- -- Example: -- --
--   >>> :m Text.Named.Enamex Data.Named.Tree Data.Text.Lazy
--   
--   >>> let drawIt = putStr . drawForest . mapForest show . parseForest
--   
--   >>> drawIt $ pack "<x>w1.1\\ w1.2</x> <y><z>w2</z> w3</y>"
--   Left "x"
--   |
--   `- Right "w1.1 w1.2"
--   ,
--   Left "y"
--   |
--   +- Left "z"
--   |  |
--   |  `- Right "w2"
--   |
--   `- Right "w3"
--   
module Text.Named.Enamex -- | Parse the enamex forest. parseForest :: Text -> NeForest Text Text -- | Parse the enamex file. parseEnamex :: Text -> [NeForest Text Text] -- | Show the forest. showForest :: NeForest Text Text -> Text -- | Show the enamex file. showEnamex :: [NeForest Text Text] -> Text