summaryrefslogtreecommitdiff
path: root/src-2.9/GF/UseGrammar/TreeSelections.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2008-05-21 09:26:44 +0000
committeraarne <aarne@cs.chalmers.se>2008-05-21 09:26:44 +0000
commit055c0d0d5a5bb0dc75904fe53df7f2e4f5732a8f (patch)
tree0e63fb68c69c8f6ad0f78893c63420f0a3600e1c /src-2.9/GF/UseGrammar/TreeSelections.hs
parent915a1de71783ab8446b1af9e72c7ba7dfbc12d3f (diff)
GF/src is now for 2.9, and the new sources are in src-3.0 - keep it this way until the release of GF 3
Diffstat (limited to 'src-2.9/GF/UseGrammar/TreeSelections.hs')
-rw-r--r--src-2.9/GF/UseGrammar/TreeSelections.hs77
1 files changed, 0 insertions, 77 deletions
diff --git a/src-2.9/GF/UseGrammar/TreeSelections.hs b/src-2.9/GF/UseGrammar/TreeSelections.hs
deleted file mode 100644
index 9bf2711be..000000000
--- a/src-2.9/GF/UseGrammar/TreeSelections.hs
+++ /dev/null
@@ -1,77 +0,0 @@
-----------------------------------------------------------------------
--- |
--- Module : TreeSelections
--- Maintainer : AR
--- Stability : (stable)
--- Portability : (portable)
---
--- choose shallowest trees, and remove an overload resolution prefix
------------------------------------------------------------------------------
-
-module GF.UseGrammar.TreeSelections (
-
- getOverloadResults, smallestTrs, sizeTr, depthTr
-
- ) where
-
-import GF.Grammar.Abstract
-import GF.Grammar.Macros
-
-import GF.Data.Operations
-import GF.Data.Zipper
-import Data.List
-
--- AR 2/7/2007
--- The top-level function takes a set of trees (typically parses)
--- and returns the list of those trees that have the minimum size.
--- In addition, the overload prefix "ovrld123_", is removed
--- from each constructor in which it appears. This is used for
--- showing the library API constructors in a parsable grammar.
--- TODO: access the generic functions smallestTrs, sizeTr, depthTr from shell
-
-getOverloadResults :: [Tree] -> [Tree]
-getOverloadResults = smallestTrs sizeTr . map (mkOverload "ovrld")
-
--- NB: this does not always give the desired result, since
--- some genuine alternatives may be deeper: now we will exclude the
--- latter of
---
--- mkCl this_NP love_V2 (mkNP that_NP here_Adv)
--- mkCl this_NP (mkVP (mkVP love_V2 that_NP) here_Adv)
---
--- A perfect method would know the definitional equivalences of constructors.
---
--- Notice also that size is a better measure than depth, because:
--- 1. Global depth does not exclude the latter of
---
--- mkCl (mkNP he_Pron) love_V2 that_NP
--- mkCl (mkNP he_Pron) (mkVP love_V2 that_NP)
---
--- 2. Length is needed to exclude the latter of
---
--- mkS (mkCl (mkNP he_Pron) love_V2 that_NP)
--- mkS presentTense (mkCl (mkNP he_Pron) love_V2 that_NP)
---
-
-smallestTrs :: (Tr a -> Int) -> [Tr a] -> [Tr a]
-smallestTrs size ts = map fst $ filter ((==mx) . snd) tds where
- tds = [(t, size t) | t <- ts]
- mx = minimum $ map snd tds
-
-depthTr :: Tr a -> Int
-depthTr (Tr (_, ts)) = case ts of
- [] -> 1
- _ -> 1 + (maximum $ map depthTr ts)
-
-sizeTr :: Tr a -> Int
-sizeTr (Tr (_, ts)) = 1 + sum (map sizeTr ts)
-
--- remove from each constant a prefix starting with "pref", up to first "_"
--- example format: ovrld123_mkNP
-
-mkOverload :: String -> Tree -> Tree
-mkOverload pref = mapTr (changeAtom overAtom) where
- overAtom a = case a of
- AtC (m, IC f) | isPrefixOf pref f ->
- AtC (m, IC (tail (dropWhile (/='_') f)))
- _ -> a