forked from GitHub/gf-core
Set xml:lang in SRGS grammars to the value of the language flag.
This commit is contained in:
@@ -43,12 +43,13 @@ srgsXmlPrinter name opts probs cfg = prSrgsXml srg ""
|
||||
where srg = makeSRG name opts probs cfg
|
||||
|
||||
prSrgsXml :: SRG -> ShowS
|
||||
prSrgsXml (SRG{grammarName=name,startCat=start,origStartCat=origStart,rules=rs})
|
||||
prSrgsXml (SRG{grammarName=name,startCat=start,
|
||||
origStartCat=origStart,grammarLanguage=l,rules=rs})
|
||||
= header . showsXML xmlGr
|
||||
where
|
||||
header = showString "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
|
||||
root = prCat start
|
||||
xmlGr = grammar root (comments
|
||||
xmlGr = grammar root l (comments
|
||||
["SRGS XML speech recognition grammar for " ++ name,
|
||||
"Generated by GF",
|
||||
"Original start category: " ++ origStart]
|
||||
@@ -78,16 +79,14 @@ oneOf :: [XML] -> XML
|
||||
oneOf [x] = x
|
||||
oneOf xs = Tag "one-of" [] xs
|
||||
|
||||
-- FIXME: what about xml:lang?
|
||||
grammar :: String -- ^ root
|
||||
-> String -- ^languageq
|
||||
-> [XML] -> XML
|
||||
grammar root = Tag "grammar" [("xmlns","http://www.w3.org/2001/06/grammar"),
|
||||
("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance"),
|
||||
("xsi:schemaLocation",
|
||||
"http://www.w3.org/2001/06/grammar http://www.w3.org/TR/speech-grammar/grammar.xsd"),
|
||||
("version","1.0"),
|
||||
("mode","voice"),
|
||||
("root",root)]
|
||||
grammar root l = Tag "grammar" [("xml:lang", l),
|
||||
("xmlns","http://www.w3.org/2001/06/grammar"),
|
||||
("version","1.0"),
|
||||
("mode","voice"),
|
||||
("root",root)]
|
||||
|
||||
comments :: [String] -> [XML]
|
||||
comments = map Comment
|
||||
|
||||
@@ -38,6 +38,8 @@ import Data.FiniteMap
|
||||
data SRG = SRG { grammarName :: String -- ^ grammar name
|
||||
, startCat :: String -- ^ start category name
|
||||
, origStartCat :: String -- ^ original start category name
|
||||
, grammarLanguage :: String -- ^ The language for which the grammar
|
||||
-- is intended, e.g. en_UK
|
||||
, rules :: [SRGRule]
|
||||
}
|
||||
deriving (Eq,Show)
|
||||
@@ -64,10 +66,12 @@ makeSRG i opts probs gr
|
||||
= SRG { grammarName = name,
|
||||
startCat = lookupFM_ names origStart,
|
||||
origStartCat = origStart,
|
||||
grammarLanguage = l,
|
||||
rules = rs }
|
||||
where
|
||||
name = prIdent i
|
||||
origStart = getStartCat opts
|
||||
l = fromMaybe "en_UK" (getOptVal opts speechLanguage)
|
||||
gr' = removeLeftRecursion $ removeIdenticalRules $ removeEmptyCats $ cfgToCFRules gr
|
||||
(cats,cfgRules) = unzip gr'
|
||||
names = mkCatNames name cats
|
||||
|
||||
Reference in New Issue
Block a user