diff --git a/src/compiler/GF/Command/Commands.hs b/src/compiler/GF/Command/Commands.hs index a05b3cf20..5b3737553 100644 --- a/src/compiler/GF/Command/Commands.hs +++ b/src/compiler/GF/Command/Commands.hs @@ -516,9 +516,9 @@ allCommands = Map.fromList [ ], exec = \env@(pgf, mos) opts -> return . fromStrings . optLins pgf opts, options = [ - ("all","show all forms and variants, one by line (cf. l -list)"), + ("all", "show all forms and variants, one by line (cf. l -list)"), ("bracket","show tree structure with brackets and paths to nodes"), - ("groups","all languages, grouped by lang, remove duplicate strings"), + ("groups", "all languages, grouped by lang, remove duplicate strings"), ("list","show all forms and variants, comma-separated on one line (cf. l -all)"), ("multi","linearize to all languages (default)"), ("table","show all forms labelled by parameters"), @@ -529,6 +529,24 @@ allCommands = Map.fromList [ ("unlexer","set unlexers separately to each language (space-separated)") ] }), + ("lc", emptyCommandInfo { + longname = "linearize_chunks", + synopsis = "linearize a tree that has metavariables in maximal chunks without them", + explanation = unlines [ + "A hopefully temporary command, intended to work around the type checker that fails", + "trees where a function node is a metavariable." + ], + examples = [ + mkEx "l -lang=LangSwe,LangNor -chunks ? a b (? c d)" + ], + exec = \env@(pgf, mos) opts -> return . fromStrings . optLins pgf (opts ++ [OOpt "chunks"]), + options = [ + ] ++ stringOpOptions, + flags = [ + ("lang","the languages of linearization (comma-separated, no spaces)") + ], + needsTypeCheck = False + }), ("ma", emptyCommandInfo { longname = "morpho_analyse", synopsis = "print the morphological analyses of all words in the string", @@ -1155,6 +1173,8 @@ allCommands = Map.fromList [ _ | isOpt "treebank" opts -> (showCId (abstractName pgf) ++ ": " ++ showExpr [] t) : [showCId lang ++ ": " ++ linear pgf opts lang t | lang <- optLangs pgf opts] + _ | isOpt "chunks" opts -> + [unwords (intersperse "<+>" (map (linear pgf opts lang) (treeChunks t))) | lang <- optLangs pgf opts] _ -> [linear pgf opts lang t | lang <- optLangs pgf opts] linear :: PGF -> [Option] -> CId -> Expr -> String diff --git a/src/compiler/GF/Command/TreeOperations.hs b/src/compiler/GF/Command/TreeOperations.hs index bf8882802..220c8f561 100644 --- a/src/compiler/GF/Command/TreeOperations.hs +++ b/src/compiler/GF/Command/TreeOperations.hs @@ -1,6 +1,7 @@ module GF.Command.TreeOperations ( treeOp, - allTreeOps + allTreeOps, + treeChunks ) where import PGF @@ -30,6 +31,8 @@ allTreeOps pgf = [ Left $ concatMap subtrees)), ("funs",("return all fun functions appearing in the tree, with duplications", Left $ concatMap funNodes)) +--- ("chunks",("return all chunks, i.e. maximal subtrees where the top node is not a metavariable", +--- Left $ concatMap treeChunks)) --- a tree with ? head does not type check anyway AR 5/11/2013 ] largest :: [Expr] -> [Expr] @@ -42,6 +45,15 @@ smallest = sortBy (\t u -> compare (size t) (size u)) where EApp e1 e2 -> size e1 + size e2 + 1 _ -> 1 +treeChunks :: Expr -> [Expr] +treeChunks = snd . cks where + cks t = case unAppForm t of + (EFun f, ts) -> case unzip (map cks ts) of + (bs,_) | and bs -> (True, [t]) + (_,cts) -> (False,concat cts) + (EMeta _, ts) -> (False,concatMap (snd . cks) ts) + _ -> (True, [t]) + subtrees :: Expr -> [Expr] subtrees t = t : case unApp t of Just (f,ts) -> concatMap subtrees ts diff --git a/src/runtime/haskell/PGF/Expr.hs b/src/runtime/haskell/PGF/Expr.hs index 01b791847..264be4aaa 100644 --- a/src/runtime/haskell/PGF/Expr.hs +++ b/src/runtime/haskell/PGF/Expr.hs @@ -2,7 +2,7 @@ module PGF.Expr(Tree, BindType(..), Expr(..), Literal(..), Patt(..), Equation(.. readExpr, showExpr, pExpr, pBinds, ppExpr, ppPatt, pattScope, mkAbs, unAbs, - mkApp, unApp, + mkApp, unApp, unAppForm, mkStr, unStr, mkInt, unInt, mkDouble, unDouble, @@ -112,13 +112,19 @@ mkApp f es = foldl EApp (EFun f) es -- | Decomposes an expression into application of function unApp :: Expr -> Maybe (CId,[Expr]) -unApp = extract [] +unApp e = case unAppForm e of + (EFun f,es) -> Just (f,es) + _ -> Nothing + +-- | Decomposes an expression into an application of a constructor such as a constant or a metavariable +unAppForm :: Expr -> (Expr,[Expr]) +unAppForm = extract [] where - extract es (EFun f) = Just (f,es) + extract es f@(EFun _) = (f,es) extract es (EApp e1 e2) = extract (e2:es) e1 extract es (ETyped e ty)= extract es e extract es (EImplArg e) = extract es e - extract es _ = Nothing + extract es h = (h,es) -- | Constructs an expression from string literal mkStr :: String -> Expr diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java b/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java index 1e63a57fb..65b311611 100644 --- a/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java +++ b/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java @@ -22,18 +22,18 @@ public class Translator { private static final String TAG = "Translator"; // TODO: allow changing - private String mGrammar = "ParseEngAbs.pgf"; - ///private String mGrammar = "TranslateEngChiFinSwe.pgf"; // AR + /// private String mGrammar = "ParseEngAbs.pgf"; + private String mGrammar = "TranslateEngChiFinSwe.pgf"; // AR // TODO: build dynamically? private Language[] mLanguages = { - ///new Language("en-US", "English", "TranslateEng", R.xml.inflection_en), // AR - ///new Language("cmn-Hans-CN", "Chinese", "TranslateChi", 0), - /// new Language("fi-FI", "Finnish", "TranslateFin", 0), - /// new Language("sv-SE", "Swedish", "TranslateSwe", 0), + new Language("en-US", "English", "TranslateEng", R.xml.inflection_en), // AR + new Language("cmn-Hans-CN", "Chinese", "TranslateChi", 0), + new Language("fi-FI", "Finnish", "TranslateFin", 0), + new Language("sv-SE", "Swedish", "TranslateSwe", 0), - new Language("en-US", "English", "ParseEng", R.xml.inflection_en), - new Language("bg-BG", "Bulgarian", "ParseBul", R.xml.inflection_bg), + /// new Language("en-US", "English", "ParseEng", R.xml.inflection_en), + /// new Language("bg-BG", "Bulgarian", "ParseBul", R.xml.inflection_bg), }; private Language mSourceLanguage;