diff options
| author | aarne <aarne@cs.chalmers.se> | 2008-10-14 11:19:30 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2008-10-14 11:19:30 +0000 |
| commit | a11f1b14370883b903da5b93de88984a3cfb9344 (patch) | |
| tree | a067b0505df5e755f07dc16a5405b5d48838d6c1 /src | |
| parent | 3fe0cccaf7bcf3dc85edd597f15ff468cae957ef (diff) | |
paraphrase works a little better now ; added examples/paraphrase for testing
Diffstat (limited to 'src')
| -rw-r--r-- | src/GF/Command/TreeOperations.hs | 2 | ||||
| -rw-r--r-- | src/PGF/Paraphrase.hs | 21 |
2 files changed, 15 insertions, 8 deletions
diff --git a/src/GF/Command/TreeOperations.hs b/src/GF/Command/TreeOperations.hs index da7399615..d4b5d175a 100644 --- a/src/GF/Command/TreeOperations.hs +++ b/src/GF/Command/TreeOperations.hs @@ -25,7 +25,7 @@ allTreeOps pgf = [ ("compute",("compute by using semantic definitions (def)", map (compute pgf))), ("paraphrase",("paraphrase by using semantic definitions (def)", - concatMap (paraphrase pgf))), + nub . concatMap (paraphrase pgf))), ("smallest",("sort trees from smallest to largest, in number of nodes", smallest)), ("typecheck",("type check and solve metavariables; reject if incorrect", diff --git a/src/PGF/Paraphrase.hs b/src/PGF/Paraphrase.hs index 6e20e1e18..9e0123605 100644 --- a/src/PGF/Paraphrase.hs +++ b/src/PGF/Paraphrase.hs @@ -5,9 +5,7 @@ -- Stability : (stable) -- Portability : (portable) -- --- generate parapharases with def definitions. --- --- modified from src GF computation +-- Generate parapharases with def definitions. ----------------------------------------------------------------------------- module PGF.Paraphrase ( @@ -20,9 +18,11 @@ import PGF.Macros (lookDef,isData) import PGF.Expr import PGF.CId -import Data.List +import Data.List (nub,sort,group) import qualified Data.Map as Map +import Debug.Trace ---- + paraphrase :: PGF -> Tree -> [Tree] paraphrase pgf = nub . paraphraseN 2 pgf @@ -38,8 +38,8 @@ paraphraseN i pgf t = fromDef :: PGF -> Tree -> [Tree] fromDef pgf t@(Fun f ts) = defDown t ++ defUp t where - defDown t = [subst g u | let equ = equsFrom f, (u,g) <- match equ ts] - defUp t = [subst g u | equ <- equsTo f, (u,g) <- match [equ] ts] + defDown t = [subst g u | let equ = equsFrom f, (u,g) <- match equ ts, trequ "U" f equ] + defUp t = [subst g u | equ <- equsTo f, (u,g) <- match [equ] ts, trequ "D" f equ] equsFrom f = [(ps,d) | Just equs <- [lookup f equss], (Fun _ ps,d) <- equs] @@ -50,7 +50,14 @@ fromDef pgf t@(Fun f ts) = defDown t ++ defUp t where isClosed d || (length equs == 1 && isLinear d)] equss = [(f,[(Fun f (map expr2tree ps), expr2tree d) | (Equ ps d) <- eqs]) | - (f,(_,EEq eqs)) <- Map.assocs (funs (abstract pgf))] + (f,(_,d)) <- Map.assocs (funs (abstract pgf)), eqs <- defs d] + + defs d = case d of + EEq eqs -> [eqs] + EMeta _ -> [] + _ -> [[Equ [] d]] + + trequ s f e = True ----trace (s ++ ": " ++ show f ++ " " ++ show e) True subst :: Subst -> Tree -> Tree subst g e = case e of |
