From 9cb3b65b840f86ce0cf7fdcbe9ae68172a07fcf7 Mon Sep 17 00:00:00 2001 From: aarne Date: Sun, 4 Sep 2005 10:45:37 +0000 Subject: [PATCH] stat; type of imperatives in lib/resource --- doc/gf-history.html | 6 ++++ lib/resource/abstract/Rules.gf | 2 +- lib/resource/english/SyntaxEng.gf | 4 +-- lib/resource/finnish/CategoriesFin.gf | 5 +-- lib/resource/finnish/RulesFin.gf | 9 +++-- lib/resource/finnish/SyntaxFin.gf | 35 ++++++++++--------- lib/resource/romance/SyntaxRomance.gf | 4 +-- lib/resource/scandinavian/SyntaxScand.gf | 4 +-- src/GF/Canon/MkGFC.hs | 6 ++-- src/GF/Grammar/PrGrammar.hs | 5 +-- src/GF/Shell/HelpFile.hs | 5 +-- src/GF/UseGrammar/Custom.hs | 8 +++-- src/GF/UseGrammar/Statistics.hs | 44 ++++++++++++++++++++++++ src/HelpFile | 1 + 14 files changed, 100 insertions(+), 38 deletions(-) create mode 100644 src/GF/UseGrammar/Statistics.hs diff --git a/doc/gf-history.html b/doc/gf-history.html index 362109886..d079c3c2c 100644 --- a/doc/gf-history.html +++ b/doc/gf-history.html @@ -14,6 +14,12 @@ Changes in functionality since May 17, 2005, release of GF Version 2.2

+4/9 (AR) Added the option pg -printer=stat to show +statistics of gfc compilation result. To be extended with new information. +The most important stats now are the top-40 sized definitions. + +

+ 1/7 Release of GF 2.3.

diff --git a/lib/resource/abstract/Rules.gf b/lib/resource/abstract/Rules.gf index d210f42f4..fe44038d5 100644 --- a/lib/resource/abstract/Rules.gf +++ b/lib/resource/abstract/Rules.gf @@ -146,7 +146,7 @@ fun IntSlash : IP -> Slash -> QCl ; -- "whom does John see" QuestAdv : IAdv -> Cl -> QCl ; -- "why do you walk" - PosImpVP, NegImpVP : VPI -> Imp ; -- "(don't) be a man" + PosImpVP, NegImpVP : VCl -> Imp ; -- "(don't) be a man" ----rename these ?? IndicPhrase : S -> Phr ; -- "I walk." diff --git a/lib/resource/english/SyntaxEng.gf b/lib/resource/english/SyntaxEng.gf index 008669c72..758571544 100644 --- a/lib/resource/english/SyntaxEng.gf +++ b/lib/resource/english/SyntaxEng.gf @@ -1278,13 +1278,13 @@ oper Imperative = SS1 Number ; - imperVerbPhrase : Bool -> VerbPhrase -> Imperative = \b,walk -> + imperVerbPhrase : Bool -> VerbClause -> Imperative = \b,walk -> {s = \\n => let a = toAgr n P2 human ; dont = if_then_Str b [] "don't" in - dont ++ walk.s ! VIInfinit ! a + dont ++ walk.s ! b ! Simul ! VIInfinit ! a } ; imperUtterance : Number -> Imperative -> Utterance = \n,I -> diff --git a/lib/resource/finnish/CategoriesFin.gf b/lib/resource/finnish/CategoriesFin.gf index 283bb27f3..0d90e7081 100644 --- a/lib/resource/finnish/CategoriesFin.gf +++ b/lib/resource/finnish/CategoriesFin.gf @@ -47,8 +47,8 @@ lincat V = Verb1 ; -- = {s : VForm => Str} ----- VP = {s,s2 : Bool => SForm => Agr => Str ; isAux : Bool} ; - VPI = {s : Bool => VIForm => Str ; sc : Case} ; + VPI = {s : VIForm => Number => Str ; sc : Case} ; + VCl = {s : Bool => Anteriority => VIForm => Number => Str ; sc : Case} ; ----- VP = Verb ** {s2 : VForm => Str ; c : ComplCase} ; ---- VG = {s,s2 : Bool => VForm => Str ; c : ComplCase} ; V2 = TransVerb ; @@ -67,6 +67,7 @@ lincat TP = {s : Str ; b : Bool ; t : Tense ; a : Anteriority} ; --- the Str field is dummy Tense = {s : Str ; t : Tense} ; + Pol = {s : Str ; p : Bool} ; Ant = {s : Str ; a : Anteriority} ; PP = {s : Str} ; diff --git a/lib/resource/finnish/RulesFin.gf b/lib/resource/finnish/RulesFin.gf index 96a1d8bf1..9793aea8d 100644 --- a/lib/resource/finnish/RulesFin.gf +++ b/lib/resource/finnish/RulesFin.gf @@ -39,7 +39,7 @@ lin DetNP = detNounPhrase ; NDetNP = numDetNounPhrase ; ----- NDetNum = justNumDetNounPhrase ; + NDetNum d n = numDetNounPhrase d n emptyCommNounPhrase ; MassNP = partNounPhrase singular ; AppN2 = appFunComm ; @@ -81,7 +81,7 @@ lin ---- ComplA2S = predAdjSent2 ; ----- AdjPart = adjPastPart ; + AdjPart verb = {s = \\a => verb.s ! PastPartPass a} ; ---- UseV2V x = verb2aux x ** {isAux = False} ; @@ -92,7 +92,7 @@ lin UseCl tp cl = {s = tp.s ++ cl.s ! tp.b ! VFinite SDecl tp.t tp.a} ; UseQCl tp cl = {s = tp.s ++ cl.s ! tp.b ! VFinite SQuest tp.t tp.a} ; ----- UseRCl tp cl = {s = \\a => tp.s ++ cl.s ! tp.b ! VFinite tp.t tp.a ! a} ; + UseRCl tp cl = {s = \\n => tp.s ++ cl.s ! tp.b ! VFinite SDecl tp.t tp.a ! n} ; PosTP t a = {s = t.s ++ a.s ; b = True ; t = t.t ; a = a.a} ; NegTP t a = {s = t.s ++ a.s ; b = False ; t = t.t ; a = a.a} ; @@ -101,6 +101,9 @@ lin TPast = {s = [] ; t = Past} ; TFuture = {s = [] ; t = Future} ; TConditional = {s = [] ; t = Conditional} ; + PPos = {s = [] ; p = True} ; + PNeg = {s = [] ; p = False} ; + ASimul = {s = [] ; a = Simul} ; AAnter = {s = [] ; a = Anter} ; diff --git a/lib/resource/finnish/SyntaxFin.gf b/lib/resource/finnish/SyntaxFin.gf index 360958dec..df6dcb1a6 100644 --- a/lib/resource/finnish/SyntaxFin.gf +++ b/lib/resource/finnish/SyntaxFin.gf @@ -42,6 +42,8 @@ oper CommNounPhrase = {s : Bool => Number => Case => Str ; g : Gender} ; + emptyCommNounPhrase : CommNounPhrase = {s = \\_,_,_ => [] ; g = NonHuman} ; + noun2CommNounPhrase : CommNoun -> CommNounPhrase = \man -> useCN man ** {g = man.g} ; @@ -323,7 +325,6 @@ oper adj2adjPhrase : Adjective -> AdjPhrase = \uusi -> {s = \\_ => uusi.s} ; - --3 Comparison adjectives -- -- Each of the comparison forms has a characteristic use: @@ -503,8 +504,8 @@ oper SType = SDecl | SQuest ; VIForm = - VIInfinit Anteriority - | VIImperat Number + VIInfinit + | VIImperat | VIInf3Iness | VIInf3Elat | VIInf3Illat @@ -517,7 +518,8 @@ oper oper Clause : Type = {s : Bool => SForm => Str} ; - VerbPhraseInf : Type = {s : Bool => VIForm => Str ; sc : Case} ; + VerbPhraseInf : Type = {s : VIForm => Number => Str ; sc : Case} ; + VerbClauseInf : Type = {s : Bool => Anteriority => VIForm => Number => Str ; sc : Case} ; Sats : Type = { subj : Str ; @@ -527,7 +529,7 @@ oper } ; obj : Bool => SVIForm => Str ; comp : Str ; - vpi : VerbPhraseInf + vpi : Bool => VerbPhraseInf } ; sats2clause : Sats -> Clause = \sats -> @@ -546,7 +548,8 @@ oper } } ; - sats2verbPhrase : {s : Str ; a : Anteriority} -> Sats -> VerbPhraseInf = \a,sats -> +{- + sats2verbClause : {s : Str ; a : Anteriority} -> Sats -> VerbPhraseInf = \a,sats -> {s = \\b,vi => let inf = sats.vpi.s ! b ! vi ; @@ -556,7 +559,7 @@ oper a.s ++ inf ++ obj ++ comp ; sc = sats.vpi.sc } ; - +-} questPart : Str -> Str = \s -> glueParticle s "ko" ; --- "kö" mkSats : NounPhrase -> Verb1 -> Sats = \subj,verb -> @@ -572,12 +575,12 @@ oper pred = \\b,sf => vi b (SCl sf) ; obj = \\_,_ => [] ; comp = [] ; - vpi = { - s = \\b,f => let vp = vi b (SVI f) in vp.fin ++ vp.inf ; + vpi = \\b => { + s = \\f,n => let vp = vi b (SVI f) in vp.fin ++ vp.inf ; sc = sc } } ; - +{- ---- progressiveSats : NounPhrase -> VerbPhraseInf -> Sats = \subj,vp -> let np = case vp.sc of { @@ -590,12 +593,12 @@ oper pred = \\b,sf => vi b (SCl sf) ; obj = \\_,_ => [] ; comp = vp.s ! True ! VIInf3Iness ; - vpi = { - s = \\b,f => let vv = vi b (SVI f) in vv.fin ++ vv.inf ; + vpi = \\b => { + s = \\f => let vv = vi b (SVI f) in vv.fin ++ vv.inf ; sc = Nom } } ; - +-} mkSatsObject : NounPhrase -> TransVerb -> NounPhrase -> Sats = \subj,verb,obj -> insertObject (mkSats subj verb) verb.c verb.s3 verb.p obj ; @@ -691,7 +694,7 @@ oper SCl (VFinite _ Conditional a) => ei a (Cond n p) (Cond Sg P3) ; SCl (VFinite _ Present a) => ei a (Pres n p) (Imper Sg) ; SCl (VFinite _ Future a) => fut a (Pres n p) (Imper Sg) ; - SVI (VIImperat n ) => älä n ; + SVI (VIImperat ) => älä n ; SVI i => inf i Simul ---- Anter } ; @@ -1133,8 +1136,8 @@ oper Imperative = SS1 Number ; - imperVerbPhrase : Bool -> VerbPhraseInf -> Imperative = \b,ui -> - {s = \\n => ui.s ! b ! VIImperat n} ; + imperVerbPhrase : Bool -> VerbClauseInf -> Imperative = \b,ui -> + {s = ui.s ! b ! Simul ! VIImperat} ; imperUtterance : Number -> Imperative -> Utterance = \n,I -> ss (I.s ! n ++ exclPunct) ; diff --git a/lib/resource/romance/SyntaxRomance.gf b/lib/resource/romance/SyntaxRomance.gf index 4eb49fa50..17d8e8d80 100644 --- a/lib/resource/romance/SyntaxRomance.gf +++ b/lib/resource/romance/SyntaxRomance.gf @@ -927,8 +927,8 @@ oper Imperative = {s : Gender => Number => Str} ; - imperVerbPhrase : Bool -> VerbPhrase -> Imperative = \b,dormir -> - {s = \\g,n => dormir.s ! VIImperat b n ! g ! n ! P2 + imperVerbPhrase : Bool -> VerbClause -> Imperative = \b,dormir -> + {s = \\g,n => dormir.s ! b ! Simul ! VIImperat b n ! g ! n ! P2 } ; imperUtterance : Number -> Imperative -> Utterance = \n,I -> diff --git a/lib/resource/scandinavian/SyntaxScand.gf b/lib/resource/scandinavian/SyntaxScand.gf index 36eec3a13..1161b3ffb 100644 --- a/lib/resource/scandinavian/SyntaxScand.gf +++ b/lib/resource/scandinavian/SyntaxScand.gf @@ -1427,9 +1427,9 @@ oper Imperative = {s : Number => Str} ; - imperVerbPhrase : Bool -> VerbPhrase -> Imperative = \b,titta -> + imperVerbPhrase : Bool -> VerbClause -> Imperative = \b,titta -> {s = \\n => - titta.s ! VIImperat b ! utrum ! n ! P2 + titta.s ! b ! Simul ! VIImperat b ! utrum ! n ! P2 } ; imperUtterance : Number -> Imperative -> Utterance = \n,I -> diff --git a/src/GF/Canon/MkGFC.hs b/src/GF/Canon/MkGFC.hs index 81706e9b7..69ccc3034 100644 --- a/src/GF/Canon/MkGFC.hs +++ b/src/GF/Canon/MkGFC.hs @@ -5,16 +5,16 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/05/30 21:08:14 $ +-- > CVS $Date: 2005/09/04 11:45:38 $ -- > CVS $Author: aarne $ --- > CVS $Revision: 1.15 $ +-- > CVS $Revision: 1.16 $ -- -- (Description of the module) ----------------------------------------------------------------------------- module GF.Canon.MkGFC (prCanonModInfo, prCanon, prCanonMGr, canon2grammar, grammar2canon, -- buildCanonGrammar, - info2mod, + info2mod,info2def, trExp, rtExp, rtQIdent) where import GF.Canon.GFC diff --git a/src/GF/Grammar/PrGrammar.hs b/src/GF/Grammar/PrGrammar.hs index a5471d6ea..905eb39f4 100644 --- a/src/GF/Grammar/PrGrammar.hs +++ b/src/GF/Grammar/PrGrammar.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/05/30 18:39:44 $ +-- > CVS $Date: 2005/09/04 11:45:38 $ -- > CVS $Author: aarne $ --- > CVS $Revision: 1.15 $ +-- > CVS $Revision: 1.16 $ -- -- AR 7\/12\/1999 - 1\/4\/2000 - 10\/5\/2003 -- @@ -107,6 +107,7 @@ instance Print A.Case where prt = C.printTree instance Print A.CType where prt = C.printTree instance Print A.Label where prt = C.printTree instance Print A.Module where prt = C.printTree +instance Print A.Def where prt = C.printTree instance Print A.Canon where prt = C.printTree instance Print A.Sort where prt = C.printTree diff --git a/src/GF/Shell/HelpFile.hs b/src/GF/Shell/HelpFile.hs index 8d427753a..c530e459f 100644 --- a/src/GF/Shell/HelpFile.hs +++ b/src/GF/Shell/HelpFile.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/07/01 19:54:09 $ +-- > CVS $Date: 2005/09/04 11:45:38 $ -- > CVS $Author: aarne $ --- > CVS $Revision: 1.9 $ +-- > CVS $Revision: 1.10 $ -- -- Help on shell commands. Generated from HelpFile by 'make help'. -- PLEASE DON'T EDIT THIS FILE. @@ -523,6 +523,7 @@ txtHelpFile = "\n -printer=fullform full-form lexicon, short format" ++ "\n *-printer=xml XML: DTD for the pg command, object for st" ++ "\n -printer=old old GF: file readable by GF 1.2" ++ + "\n -printer=stat show some statistics of generated GFC" ++ "\n" ++ "\n-startcat, like -cat, but used in grammars (to avoid clash with keyword cat)" ++ "\n" ++ diff --git a/src/GF/UseGrammar/Custom.hs b/src/GF/UseGrammar/Custom.hs index 2e54bcb18..c952bcd5c 100644 --- a/src/GF/UseGrammar/Custom.hs +++ b/src/GF/UseGrammar/Custom.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/09/01 09:53:19 $ --- > CVS $Author: peb $ --- > CVS $Revision: 1.69 $ +-- > CVS $Date: 2005/09/04 11:45:38 $ +-- > CVS $Author: aarne $ +-- > CVS $Revision: 1.70 $ -- -- A database for customizable GF shell commands. -- @@ -61,6 +61,7 @@ import GF.Speech.PrSLF (slfPrinter) import GF.Data.Zipper +import GF.UseGrammar.Statistics import GF.UseGrammar.Morphology import GF.API.GrammarToHaskell -----import GrammarToCanon (showCanon, showCanonOpt) @@ -249,6 +250,7 @@ customGrammarPrinter = ,(strCI "opts", prOpts . stateOptions) ,(strCI "words", unwords . stateGrammarWords) ,(strCI "printnames", C.prPrintnamesGrammar . stateGrammarST) + ,(strCI "stat", prStatistics . stateGrammarST) {- ---- (strCI "gf", prt . st2grammar . stateGrammarST) -- DEFAULT ,(strCI "canon", showCanon "Lang" . stateGrammarST) diff --git a/src/GF/UseGrammar/Statistics.hs b/src/GF/UseGrammar/Statistics.hs new file mode 100644 index 000000000..46e4fcc3b --- /dev/null +++ b/src/GF/UseGrammar/Statistics.hs @@ -0,0 +1,44 @@ +---------------------------------------------------------------------- +-- | +-- Module : Statistics +-- Maintainer : AR +-- Stability : (stable) +-- Portability : (portable) +-- +-- > CVS $Date: 2005/09/04 11:45:38 $ +-- > CVS $Author: aarne $ +-- > CVS $Revision: 1.1 $ +-- +-- statistics on canonical grammar: amounts of generated code +-- AR 4\/9\/2005. +-- uses canonical grammar +----------------------------------------------------------------------------- + +module GF.UseGrammar.Statistics (prStatistics) where + +import GF.Infra.Modules +import GF.Infra.Option +import GF.Grammar.PrGrammar +import GF.Canon.GFC +import GF.Canon.MkGFC + +import GF.Data.Operations + +import Data.List (sortBy) + +-- | the top level function +prStatistics :: CanonGrammar -> String +prStatistics can = unlines $ [ + show (length mods) ++ "\t\t modules", + show chars ++ "\t\t gfc size", + "", + "Top 40 definitions" + ] ++ + [show d ++ "\t\t " ++ f | (d,f) <- tops] + where + tops = take 40 $ reverse $ sortBy (\ (i,_) (j,_) -> compare i j) defs + defs = [(length (prt (info2def j)), name m j) | (m,j) <- infos] + infos = [(m,j) | (m,ModMod mo) <- mods, j <- tree2list (jments mo)] + name m (f,_) = prt m ++ "." ++ prt f + mods = modules can + chars = length $ prCanon can diff --git a/src/HelpFile b/src/HelpFile index 299655688..edc5bef9c 100644 --- a/src/HelpFile +++ b/src/HelpFile @@ -494,6 +494,7 @@ q, quit: q -printer=fullform full-form lexicon, short format *-printer=xml XML: DTD for the pg command, object for st -printer=old old GF: file readable by GF 1.2 + -printer=stat show some statistics of generated GFC -startcat, like -cat, but used in grammars (to avoid clash with keyword cat)