1
0
forked from GitHub/gf-core

morphological analyser in shell state - now reasonably fast

This commit is contained in:
aarne
2008-12-12 08:12:24 +00:00
parent a3328e5abb
commit 6e511e5fbd
2 changed files with 17 additions and 8 deletions

View File

@@ -66,7 +66,7 @@ emptyCommandInfo = CommandInfo {
lookCommand :: String -> Map.Map String CommandInfo -> Maybe CommandInfo lookCommand :: String -> Map.Map String CommandInfo -> Maybe CommandInfo
lookCommand = Map.lookup lookCommand = Map.lookup
commandHelpAll :: String -> PGF -> [Option] -> String commandHelpAll :: String -> PGFEnv -> [Option] -> String
commandHelpAll cod pgf opts = unlines commandHelpAll cod pgf opts = unlines
[commandHelp (isOpt "full" opts) (co,info) [commandHelp (isOpt "full" opts) (co,info)
| (co,info) <- Map.assocs (allCommands cod pgf)] | (co,info) <- Map.assocs (allCommands cod pgf)]
@@ -84,9 +84,12 @@ commandHelp full (co,info) = unlines $ [
"examples:" ++++ unlines [" " ++ s | s <- examples info] "examples:" ++++ unlines [" " ++ s | s <- examples info]
] else [] ] else []
type PGFEnv = (PGF, Map.Map Language Morpho)
-- this list must no more be kept sorted by the command name -- this list must no more be kept sorted by the command name
allCommands :: String -> PGF -> Map.Map String CommandInfo allCommands :: String -> PGFEnv -> Map.Map String CommandInfo
allCommands cod pgf = Map.fromList [ allCommands cod env@(pgf, mos) = Map.fromList [
("!", emptyCommandInfo { ("!", emptyCommandInfo {
synopsis = "system command: escape to system shell", synopsis = "system command: escape to system shell",
syntax = "! SYSTEMCOMMAND", syntax = "! SYSTEMCOMMAND",
@@ -223,10 +226,10 @@ allCommands cod pgf = Map.fromList [
_ | isOpt "coding" opts -> codingMsg _ | isOpt "coding" opts -> codingMsg
_ | isOpt "license" opts -> licenseMsg _ | isOpt "license" opts -> licenseMsg
[t] -> let co = getCommandOp (showTree t) in [t] -> let co = getCommandOp (showTree t) in
case lookCommand co (allCommands cod pgf) of ---- new map ??!! case lookCommand co (allCommands cod env) of ---- new map ??!!
Just info -> commandHelp True (co,info) Just info -> commandHelp True (co,info)
_ -> "command not found" _ -> "command not found"
_ -> commandHelpAll cod pgf opts _ -> commandHelpAll cod env opts
in return (fromString msg) in return (fromString msg)
}), }),
("i", emptyCommandInfo { ("i", emptyCommandInfo {
@@ -614,7 +617,7 @@ allCommands cod pgf = Map.fromList [
prGrammar opts = case opts of prGrammar opts = case opts of
_ | isOpt "cats" opts -> unwords $ map showType $ categories pgf _ | isOpt "cats" opts -> unwords $ map showType $ categories pgf
_ | isOpt "fullform" opts -> concatMap _ | isOpt "fullform" opts -> concatMap
(prFullFormLexicon . buildMorpho pgf) $ optLangs opts (prFullFormLexicon . morpho) $ optLangs opts
_ | isOpt "missing" opts -> _ | isOpt "missing" opts ->
unlines $ [unwords (prCId la:":": map prCId cs) | unlines $ [unwords (prCId la:":": map prCId cs) |
la <- optLangs opts, let cs = missingLins pgf la] la <- optLangs opts, let cs = missingLins pgf la]
@@ -622,7 +625,9 @@ allCommands cod pgf = Map.fromList [
v -> concatMap snd $ exportPGF noOptions (read v) pgf v -> concatMap snd $ exportPGF noOptions (read v) pgf
morphos opts s = morphos opts s =
[lookupMorpho (buildMorpho pgf la) s | la <- optLangs opts] [lookupMorpho (morpho la) s | la <- optLangs opts]
morpho la = maybe Map.empty id $ Map.lookup la mos
-- ps -f -g s returns g (f s) -- ps -f -g s returns g (f s)
stringOps opts s = foldr app s (reverse opts) where stringOps opts s = foldr app s (reverse opts) where

View File

@@ -13,6 +13,7 @@ import GF.Command.Parse
import PGF import PGF
import PGF.Data import PGF.Data
import PGF.Macros import PGF.Macros
import PGF.Morphology
import GF.System.Signal import GF.System.Signal
import GF.Infra.UseIO import GF.Infra.UseIO
@@ -22,13 +23,16 @@ import qualified Data.Map as Map
data CommandEnv = CommandEnv { data CommandEnv = CommandEnv {
multigrammar :: PGF, multigrammar :: PGF,
morphos :: Map.Map Language Morpho,
commands :: Map.Map String CommandInfo, commands :: Map.Map String CommandInfo,
commandmacros :: Map.Map String CommandLine, commandmacros :: Map.Map String CommandLine,
expmacros :: Map.Map String Tree expmacros :: Map.Map String Tree
} }
mkCommandEnv :: String -> PGF -> CommandEnv mkCommandEnv :: String -> PGF -> CommandEnv
mkCommandEnv enc pgf = CommandEnv pgf (allCommands enc pgf) Map.empty Map.empty mkCommandEnv enc pgf =
let mos = Map.fromList [(la,buildMorpho pgf la) | la <- languages pgf] in
CommandEnv pgf mos (allCommands enc (pgf, mos)) Map.empty Map.empty
emptyCommandEnv :: CommandEnv emptyCommandEnv :: CommandEnv
emptyCommandEnv = mkCommandEnv "utf8" emptyPGF emptyCommandEnv = mkCommandEnv "utf8" emptyPGF