dawg-0.8: Directed acyclic word graphs

Data.DAWG

Description

The module implements directed acyclic word graphs (DAWGs) internaly represented as minimal acyclic deterministic finite-state automata. The implementation provides fast insert and delete operations which can be used to build the DAWG structure incrementaly.

Transition backend has to be specified by a type signature. You can import the desired transition type and define your own dictionary construction function.

``` import Data.DAWG
import Data.DAWG.Trans.Map (Trans)

mkDict :: (Enum a, Ord b) => [([a], b)] -> DAWG Trans a b
mkDict = fromList
```

Synopsis

DAWG type

data DAWG t a b Source

A directed acyclic word graph with phantom type `a` representing type of alphabet elements.

Instances

 (Show t, Show b) => Show (DAWG t a b) (MkNode t b, Binary t, Binary b) => Binary (DAWG t a b)

class (Ord (Node t a), Trans t) => MkNode t a Source

Is t a valid transition map within the context of a-valued automata nodes? All transition implementations provided by the library are instances of this class.

Instances

 (Ord (Node t a), Trans t) => MkNode t a

Query

numStates :: DAWG t a b -> IntSource

Number of states in the underlying graph.

lookup :: (Enum a, MkNode t b) => [a] -> DAWG t a b -> Maybe bSource

Find value associated with the key.

Construction

empty :: MkNode t b => DAWG t a bSource

Empty DAWG.

fromList :: (Enum a, MkNode t b) => [([a], b)] -> DAWG t a bSource

Construct DAWG from the list of (word, value) pairs.

fromListWith :: (Enum a, MkNode t b) => (b -> b -> b) -> [([a], b)] -> DAWG t a bSource

Construct DAWG from the list of (word, value) pairs with a combining function. The combining function is applied strictly.

fromLang :: (Enum a, MkNode t ()) => [[a]] -> DAWG t a ()Source

Make DAWG from the list of words. Annotate each word with the `()` value.

Insertion

insert :: (Enum a, MkNode t b) => [a] -> b -> DAWG t a b -> DAWG t a bSource

Insert the (key, value) pair into the DAWG.

insertWith :: (Enum a, MkNode t b) => (b -> b -> b) -> [a] -> b -> DAWG t a b -> DAWG t a bSource

Insert with a function, combining new value and old value. `insertWith` f key value d will insert the pair (key, value) into d if key does not exist in the DAWG. If the key does exist, the function will insert the pair (key, f new_value old_value).

Deletion

delete :: (Enum a, MkNode t b) => [a] -> DAWG t a b -> DAWG t a bSource

Delete the key from the DAWG.

Conversion

assocs :: (Enum a, MkNode t b) => DAWG t a b -> [([a], b)]Source

Return all key/value pairs in the DAWG in ascending key order.

keys :: (Enum a, MkNode t b) => DAWG t a b -> [[a]]Source

Return all keys of the DAWG in ascending order.

elems :: MkNode t b => DAWG t a b -> [b]Source

Return all elements of the DAWG in the ascending order of their keys.