diff options
| author | aarne <aarne@cs.chalmers.se> | 2008-06-25 16:43:48 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2008-06-25 16:43:48 +0000 |
| commit | b96b36f43de3e2f8b58d5f539daa6f6d47f25870 (patch) | |
| tree | 0992334be13cec6538a1dea22fbbf26ad6bdf224 /src/GF/Data/Trie2.hs | |
| parent | fe367412e0aeb4ad5c02de68e6eca382e0f96984 (diff) | |
removed src for 2.9
Diffstat (limited to 'src/GF/Data/Trie2.hs')
| -rw-r--r-- | src/GF/Data/Trie2.hs | 120 |
1 files changed, 0 insertions, 120 deletions
diff --git a/src/GF/Data/Trie2.hs b/src/GF/Data/Trie2.hs deleted file mode 100644 index 36fcc3221..000000000 --- a/src/GF/Data/Trie2.hs +++ /dev/null @@ -1,120 +0,0 @@ ----------------------------------------------------------------------- --- | --- Module : Trie2 --- Maintainer : Markus Forsberg --- Stability : Stable --- Portability : Haskell 98 --- --- > CVS $Date: 2005/04/21 16:22:10 $ --- > CVS $Author: bringert $ --- > CVS $Revision: 1.7 $ --- --- (Description of the module) ------------------------------------------------------------------------------ - -module GF.Data.Trie2 ( - tcompile, - collapse, - Trie, - trieLookup, - decompose, - --- Attr, atW, atP, atWP, - emptyTrie - ) where - -import GF.Data.Map -import Data.List - -newtype TrieT a b = TrieT ([(a,TrieT a b)],[b]) - -newtype Trie a b = Trie (Map a (Trie a b), [b]) - -emptyTrieT = TrieT ([],[]) - -emptyTrie :: Trie a b -emptyTrie = Trie (empty,[]) - -optimize :: (Ord a,Eq b) => TrieT a b -> Trie a b -optimize (TrieT (xs,res)) = Trie ([(c,optimize t) | (c,t) <- xs] |->+ empty, - nub res) --- nub by AR - -collapse :: Ord a => Trie a b -> [([a],[b])] -collapse trie = collapse' trie [] - where collapse' (Trie (map,(x:xs))) s = if (isEmpty map) then [(reverse s,(x:xs))] - else (reverse s,(x:xs)): - concat [ collapse' trie (c:s) | (c,trie) <- flatten map] - collapse' (Trie (map,[])) s - = concat [ collapse' trie (c:s) | (c,trie) <- flatten map] - -tcompile :: (Ord a,Eq b) => [([a],[b])] -> Trie a b -tcompile xs = optimize $ build xs emptyTrieT - -build :: Ord a => [([a],[b])] -> TrieT a b -> TrieT a b -build [] trie = trie -build (x:xs) trie = build xs (insert x trie) - where - insert ([],ys) (TrieT (xs,res)) = TrieT (xs,ys ++ res) - insert ((s:ss),ys) (TrieT (xs,res)) - = case (span (\(s',_) -> s' /= s) xs) of - (xs,[]) -> TrieT (((s,(insert (ss,ys) emptyTrieT)):xs),res) - (xs,(y,trie):zs) -> TrieT (xs ++ ((y,insert (ss,ys) trie):zs),res) - -trieLookup :: Ord a => Trie a b -> [a] -> ([a],[b]) -trieLookup trie s = apply trie s s - -apply :: Ord a => Trie a b -> [a] -> [a] -> ([a],[b]) -apply (Trie (_,res)) [] inp = (inp,res) -apply (Trie (map,_)) (s:ss) inp - = case map ! s of - Just trie -> apply trie ss inp - Nothing -> (inp,[]) - ------------------------------ --- from Trie for strings; simplified for GF by making binding always possible (AR) - -decompose :: Ord a => Trie a b -> [a] -> [[a]] -decompose trie sentence = backtrack [(sentence,[])] trie - -react :: Ord a => [a] -> [[a]] -> [([a],[[a]])] -> - [a] -> Trie a b -> Trie a b -> [[a]] --- String -> [String] -> [(String,[String])] -> String -> Trie -> Trie -> [String] -react input output back occ (Trie (arcs,res)) init = - case res of -- Accept = non-empty res. - [] -> continue back - _ -> let pushout = (occ:output) - in case input of - [] -> reverse $ map reverse pushout - _ -> let pushback = ((input,pushout):back) - in continue pushback - where continue cont = case input of - [] -> backtrack cont init - (l:rest) -> case arcs ! l of - Just trie -> - react rest output cont (l:occ) trie init - Nothing -> backtrack cont init - -backtrack :: Ord a => [([a],[[a]])] -> Trie a b -> [[a]] -backtrack [] _ = [] -backtrack ((input,output):back) trie - = react input output back [] trie trie - - -{- so this is not needed from the original -type Attr = Int - -atW, atP, atWP :: Attr -(atW,atP,atWP) = (0,1,2) - -decompose :: Ord a => Trie a (Int,b) -> [a] -> [[a]] -decompose trie sentence = legal trie $ backtrack [(sentence,[])] trie - --- The function legal checks if the decomposition is in fact a possible one. - -legal :: Ord a => Trie a (Int,b) -> [[a]] -> [[a]] -legal _ [] = [] -legal trie input = if (test (map ((map fst).snd.(trieLookup trie)) input)) then input else [] - where - test [] = False - test [xs] = elem atW xs || elem atWP xs - test (xs:xss) = (elem atP xs || elem atWP xs) && test xss --} |
