forked from GitHub/gf-core
Added --output-format=nolr. Minor makeRegular refactoring.
This commit is contained in:
@@ -37,6 +37,7 @@ exportPGF opts fmt pgf =
|
|||||||
FmtProlog -> multi "pl" grammar2prolog
|
FmtProlog -> multi "pl" grammar2prolog
|
||||||
FmtProlog_Abs -> multi "pl" grammar2prolog_abs
|
FmtProlog_Abs -> multi "pl" grammar2prolog_abs
|
||||||
FmtBNF -> single "bnf" bnfPrinter
|
FmtBNF -> single "bnf" bnfPrinter
|
||||||
|
FmtNoLR -> single "bnf" nonLeftRecursivePrinter
|
||||||
FmtRegular -> single "bnf" regularPrinter
|
FmtRegular -> single "bnf" regularPrinter
|
||||||
FmtFCFG -> single "fcfg" fcfgPrinter
|
FmtFCFG -> single "fcfg" fcfgPrinter
|
||||||
FmtSRGS_XML -> single "grxml" (srgsXmlPrinter sisr)
|
FmtSRGS_XML -> single "grxml" (srgsXmlPrinter sisr)
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ data OutputFormat = FmtPGF
|
|||||||
| FmtProlog_Abs
|
| FmtProlog_Abs
|
||||||
| FmtBNF
|
| FmtBNF
|
||||||
| FmtRegular
|
| FmtRegular
|
||||||
|
| FmtNoLR
|
||||||
| FmtFCFG
|
| FmtFCFG
|
||||||
| FmtSRGS_XML
|
| FmtSRGS_XML
|
||||||
| FmtSRGS_XML_NonRec
|
| FmtSRGS_XML_NonRec
|
||||||
@@ -458,6 +459,7 @@ outputFormats =
|
|||||||
("prolog_abs", FmtProlog_Abs),
|
("prolog_abs", FmtProlog_Abs),
|
||||||
("bnf", FmtBNF),
|
("bnf", FmtBNF),
|
||||||
("regular", FmtRegular),
|
("regular", FmtRegular),
|
||||||
|
("nolr", FmtNoLR),
|
||||||
("fcfg", FmtFCFG),
|
("fcfg", FmtFCFG),
|
||||||
("srgs_xml", FmtSRGS_XML),
|
("srgs_xml", FmtSRGS_XML),
|
||||||
("srgs_xml_nonrec", FmtSRGS_XML_NonRec),
|
("srgs_xml_nonrec", FmtSRGS_XML_NonRec),
|
||||||
|
|||||||
@@ -190,14 +190,13 @@ makeSimpleRegular = makeRegular . topDownFilter . bottomUpFilter . removeCycles
|
|||||||
|
|
||||||
-- Use the transformation algorithm from \"Regular Approximation of Context-free
|
-- Use the transformation algorithm from \"Regular Approximation of Context-free
|
||||||
-- Grammars through Approximation\", Mohri and Nederhof, 2000
|
-- Grammars through Approximation\", Mohri and Nederhof, 2000
|
||||||
-- to create an over-generating regular frammar for a context-free
|
-- to create an over-generating regular grammar for a context-free
|
||||||
-- grammar
|
-- grammar
|
||||||
makeRegular :: CFG -> CFG
|
makeRegular :: CFG -> CFG
|
||||||
makeRegular g = g { cfgRules = groupProds $ concatMap trSet (mutRecCats True g) }
|
makeRegular g = g { cfgRules = groupProds $ concatMap trSet (mutRecCats True g) }
|
||||||
where trSet cs | allXLinear cs rs = rs
|
where trSet cs | allXLinear cs rs = rs
|
||||||
| otherwise = concatMap handleCat csl
|
| otherwise = concatMap handleCat (Set.toList cs)
|
||||||
where csl = Set.toList cs
|
where rs = catSetRules g cs
|
||||||
rs = catSetRules g cs
|
|
||||||
handleCat c = [CFRule c' [] (mkCFTerm (c++"-empty"))] -- introduce A' -> e
|
handleCat c = [CFRule c' [] (mkCFTerm (c++"-empty"))] -- introduce A' -> e
|
||||||
++ concatMap (makeRightLinearRules c) (catRules g c)
|
++ concatMap (makeRightLinearRules c) (catRules g c)
|
||||||
where c' = newCat c
|
where c' = newCat c
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
--
|
--
|
||||||
-- Approximates PGF grammars with context-free grammars.
|
-- Approximates PGF grammars with context-free grammars.
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
module GF.Speech.PGFToCFG (bnfPrinter, regularPrinter, fcfgPrinter, pgfToCFG) where
|
module GF.Speech.PGFToCFG (bnfPrinter, nonLeftRecursivePrinter, regularPrinter,
|
||||||
|
fcfgPrinter, pgfToCFG) where
|
||||||
|
|
||||||
import PGF.CId
|
import PGF.CId
|
||||||
import PGF.Data as PGF
|
import PGF.Data as PGF
|
||||||
@@ -21,10 +22,16 @@ import Data.Set (Set)
|
|||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
|
|
||||||
bnfPrinter :: PGF -> CId -> String
|
bnfPrinter :: PGF -> CId -> String
|
||||||
bnfPrinter pgf cnc = prCFG $ pgfToCFG pgf cnc
|
bnfPrinter = toBNF id
|
||||||
|
|
||||||
|
nonLeftRecursivePrinter :: PGF -> CId -> String
|
||||||
|
nonLeftRecursivePrinter = toBNF removeLeftRecursion
|
||||||
|
|
||||||
regularPrinter :: PGF -> CId -> String
|
regularPrinter :: PGF -> CId -> String
|
||||||
regularPrinter pgf cnc = prCFG $ makeSimpleRegular $ pgfToCFG pgf cnc
|
regularPrinter = toBNF makeRegular
|
||||||
|
|
||||||
|
toBNF :: (CFG -> CFG) -> PGF -> CId -> String
|
||||||
|
toBNF f pgf cnc = prCFG $ f $ pgfToCFG pgf cnc
|
||||||
|
|
||||||
-- FIXME: move this somewhere else
|
-- FIXME: move this somewhere else
|
||||||
fcfgPrinter :: PGF -> CId -> String
|
fcfgPrinter :: PGF -> CId -> String
|
||||||
|
|||||||
Reference in New Issue
Block a user