mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
unpar
This commit is contained in:
@@ -12,6 +12,20 @@ Changes in functionality since May 17, 2005, release of GF Version 2.2
|
|||||||
|
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
|
14/9 (AR) Added printing of grammars to a format without parameters, in
|
||||||
|
the spirit of Peanos "Latino sine flexione". The command <tt>pg -unpar</tt>
|
||||||
|
does the trick, and the result can be saved in a <tt>gfcm</tt> file. The generated
|
||||||
|
concrete syntax modules get the prefix <tt>UP_</tt>. The translation is briefly:
|
||||||
|
<pre>
|
||||||
|
(P => T)* = T*
|
||||||
|
(t ! p)* = t*
|
||||||
|
(table {p => t ; ...})* = t*
|
||||||
|
</pre>
|
||||||
|
In order for this to be maximally useful, the grammar should be written in such
|
||||||
|
a way that the first value of every parameter type is the desired one. For
|
||||||
|
instance, in Peano's case it would be the ablative for noun cases, the singular for
|
||||||
|
numbers, and the 2nd person singular imperative for verb forms.
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
14/9 (BB) Added finite state approximation of grammars.
|
14/9 (BB) Added finite state approximation of grammars.
|
||||||
|
|||||||
63
src/GF/Canon/Unparametrize.hs
Normal file
63
src/GF/Canon/Unparametrize.hs
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
----------------------------------------------------------------------
|
||||||
|
-- |
|
||||||
|
-- Module : Unparametrize
|
||||||
|
-- Maintainer : AR
|
||||||
|
-- Stability : (stable)
|
||||||
|
-- Portability : (portable)
|
||||||
|
--
|
||||||
|
-- > CVS $Date: 2005/09/14 16:26:21 $
|
||||||
|
-- > CVS $Author: aarne $
|
||||||
|
-- > CVS $Revision: 1.1 $
|
||||||
|
--
|
||||||
|
-- Taking away parameters from a canonical grammar. All param
|
||||||
|
-- types are replaced by {}, and only one branch is left in
|
||||||
|
-- all tables. AR 14\/9\/2005.
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
module GF.Canon.Unparametrize (unparametrizeCanon) where
|
||||||
|
|
||||||
|
import GF.Canon.AbsGFC
|
||||||
|
import GF.Infra.Ident
|
||||||
|
import GF.Canon.GFC
|
||||||
|
import qualified GF.Canon.CMacros as C
|
||||||
|
import GF.Data.Operations
|
||||||
|
import qualified GF.Infra.Modules as M
|
||||||
|
|
||||||
|
unparametrizeCanon :: CanonGrammar -> CanonGrammar
|
||||||
|
unparametrizeCanon (M.MGrammar modules) =
|
||||||
|
M.MGrammar $ map unparModule modules where
|
||||||
|
|
||||||
|
unparModule (i,m) = case m of
|
||||||
|
M.ModMod (M.Module mt@(M.MTConcrete _) st fs me ops js) ->
|
||||||
|
let me' = [(unparIdent j,incl) | (j,incl) <- me] in
|
||||||
|
(unparIdent i, M.ModMod (M.Module mt st fs me' ops (mapTree unparInfo js)))
|
||||||
|
_ -> (i,m)
|
||||||
|
|
||||||
|
unparInfo (c,info) = case info of
|
||||||
|
CncCat ty t m -> (c, CncCat (unparCType ty) (unparTerm t) m)
|
||||||
|
CncFun k xs t m -> (c, CncFun k xs (unparTerm t) m)
|
||||||
|
AnyInd b i -> (c, AnyInd b (unparIdent i))
|
||||||
|
_ -> (c,info)
|
||||||
|
|
||||||
|
unparCType ty = case ty of
|
||||||
|
RecType ls -> RecType [Lbg lab (unparCType t) | Lbg lab t <- ls]
|
||||||
|
Table _ v -> unparCType v --- Table unitType (unparCType v)
|
||||||
|
Cn _ -> unitType
|
||||||
|
_ -> ty
|
||||||
|
|
||||||
|
unparTerm t = case t of
|
||||||
|
Par _ _ -> unitTerm
|
||||||
|
T _ cs -> unparTerm (head [t | Cas _ t <- cs])
|
||||||
|
V _ ts -> unparTerm (head ts)
|
||||||
|
S t _ -> unparTerm t
|
||||||
|
{-
|
||||||
|
T _ cs -> V unitType [unparTerm (head [t | Cas _ t <- cs])]
|
||||||
|
V _ ts -> V unitType [unparTerm (head ts)]
|
||||||
|
S t _ -> S (unparTerm t) unitTerm
|
||||||
|
-}
|
||||||
|
_ -> C.composSafeOp unparTerm t
|
||||||
|
|
||||||
|
unitType = RecType []
|
||||||
|
unitTerm = R []
|
||||||
|
|
||||||
|
unparIdent (IC s) = IC $ "UP_" ++ s
|
||||||
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/09/13 08:33:58 $
|
-- > CVS $Date: 2005/09/14 16:26:22 $
|
||||||
-- > CVS $Author: bringert $
|
-- > CVS $Author: aarne $
|
||||||
-- > CVS $Revision: 1.11 $
|
-- > CVS $Revision: 1.12 $
|
||||||
--
|
--
|
||||||
-- Help on shell commands. Generated from HelpFile by 'make help'.
|
-- Help on shell commands. Generated from HelpFile by 'make help'.
|
||||||
-- PLEASE DON'T EDIT THIS FILE.
|
-- PLEASE DON'T EDIT THIS FILE.
|
||||||
@@ -530,6 +530,7 @@ txtHelpFile =
|
|||||||
"\n -printer=slf_graphviz the same automaton as in SLF, but in Graphviz format" ++
|
"\n -printer=slf_graphviz the same automaton as in SLF, but in Graphviz format" ++
|
||||||
"\n -printer=fa_graphviz a finite automaton with labelled edges" ++
|
"\n -printer=fa_graphviz a finite automaton with labelled edges" ++
|
||||||
"\n -printer=regular a regular grammar in a simple BNF" ++
|
"\n -printer=regular a regular grammar in a simple BNF" ++
|
||||||
|
"\n -printer=unpar a gfc grammar with parameters eliminated" ++
|
||||||
"\n" ++
|
"\n" ++
|
||||||
"\n-startcat, like -cat, but used in grammars (to avoid clash with keyword cat)" ++
|
"\n-startcat, like -cat, but used in grammars (to avoid clash with keyword cat)" ++
|
||||||
"\n" ++
|
"\n" ++
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/09/12 16:10:24 $
|
-- > CVS $Date: 2005/09/14 16:26:22 $
|
||||||
-- > CVS $Author: bringert $
|
-- > CVS $Author: aarne $
|
||||||
-- > CVS $Revision: 1.72 $
|
-- > CVS $Revision: 1.73 $
|
||||||
--
|
--
|
||||||
-- A database for customizable GF shell commands.
|
-- A database for customizable GF shell commands.
|
||||||
--
|
--
|
||||||
@@ -81,6 +81,7 @@ import qualified GF.Conversion.GFC as Cnv
|
|||||||
import qualified GF.Conversion.Types as CnvTypes
|
import qualified GF.Conversion.Types as CnvTypes
|
||||||
import qualified GF.Conversion.Haskell as CnvHaskell
|
import qualified GF.Conversion.Haskell as CnvHaskell
|
||||||
import qualified GF.Conversion.Prolog as CnvProlog
|
import qualified GF.Conversion.Prolog as CnvProlog
|
||||||
|
import GF.Canon.Unparametrize
|
||||||
|
|
||||||
import GF.Canon.GFC
|
import GF.Canon.GFC
|
||||||
import qualified GF.Canon.MkGFC as MC
|
import qualified GF.Canon.MkGFC as MC
|
||||||
@@ -258,6 +259,8 @@ customGrammarPrinter =
|
|||||||
,(strCI "words", unwords . stateGrammarWords)
|
,(strCI "words", unwords . stateGrammarWords)
|
||||||
,(strCI "printnames", C.prPrintnamesGrammar . stateGrammarST)
|
,(strCI "printnames", C.prPrintnamesGrammar . stateGrammarST)
|
||||||
,(strCI "stat", prStatistics . stateGrammarST)
|
,(strCI "stat", prStatistics . stateGrammarST)
|
||||||
|
,(strCI "unpar", prCanon . unparametrizeCanon . stateGrammarST)
|
||||||
|
|
||||||
{- ----
|
{- ----
|
||||||
(strCI "gf", prt . st2grammar . stateGrammarST) -- DEFAULT
|
(strCI "gf", prt . st2grammar . stateGrammarST) -- DEFAULT
|
||||||
,(strCI "canon", showCanon "Lang" . stateGrammarST)
|
,(strCI "canon", showCanon "Lang" . stateGrammarST)
|
||||||
|
|||||||
@@ -501,6 +501,7 @@ q, quit: q
|
|||||||
-printer=slf_graphviz the same automaton as in SLF, but in Graphviz format
|
-printer=slf_graphviz the same automaton as in SLF, but in Graphviz format
|
||||||
-printer=fa_graphviz a finite automaton with labelled edges
|
-printer=fa_graphviz a finite automaton with labelled edges
|
||||||
-printer=regular a regular grammar in a simple BNF
|
-printer=regular a regular grammar in a simple BNF
|
||||||
|
-printer=unpar a gfc grammar with parameters eliminated
|
||||||
|
|
||||||
-startcat, like -cat, but used in grammars (to avoid clash with keyword cat)
|
-startcat, like -cat, but used in grammars (to avoid clash with keyword cat)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user