mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
Cleaned up some stuff while trying to find a bug. Turned out I just had not set the startcat in the grammar file. Time to go home I think.
This commit is contained in:
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/09/12 21:54:32 $
|
-- > CVS $Date: 2005/09/12 22:32:24 $
|
||||||
-- > CVS $Author: bringert $
|
-- > CVS $Author: bringert $
|
||||||
-- > CVS $Revision: 1.5 $
|
-- > CVS $Revision: 1.6 $
|
||||||
--
|
--
|
||||||
-- A simple finite state network module.
|
-- A simple finite state network module.
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
@@ -17,8 +17,9 @@ module GF.Speech.FiniteState (FA, State,
|
|||||||
newFA,
|
newFA,
|
||||||
addFinalState,
|
addFinalState,
|
||||||
newState, newTransition,
|
newState, newTransition,
|
||||||
moveLabelsToNodes, minimize, asGraph,
|
mapStates, mapTransitions,
|
||||||
Graph, prGraphGraphviz, nmap, emap) where
|
moveLabelsToNodes, minimize,
|
||||||
|
prGraphGraphviz) where
|
||||||
|
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Maybe (fromJust)
|
import Data.Maybe (fromJust)
|
||||||
@@ -57,7 +58,10 @@ newTransition :: Node -> Node -> b -> FA a b -> FA a b
|
|||||||
newTransition f t l = onGraph (newEdge f t l)
|
newTransition f t l = onGraph (newEdge f t l)
|
||||||
|
|
||||||
mapStates :: (a -> c) -> FA a b -> FA c b
|
mapStates :: (a -> c) -> FA a b -> FA c b
|
||||||
mapStates f (FA g s ss) = FA (nmap f g) s ss
|
mapStates f = onGraph (nmap f)
|
||||||
|
|
||||||
|
mapTransitions :: (b -> c) -> FA a b -> FA a c
|
||||||
|
mapTransitions f = onGraph (emap f)
|
||||||
|
|
||||||
asGraph :: FA a b -> Graph a b
|
asGraph :: FA a b -> Graph a b
|
||||||
asGraph (FA g _ _) = g
|
asGraph (FA g _ _) = g
|
||||||
@@ -71,6 +75,15 @@ minimize = onGraph mimimizeGr1
|
|||||||
moveLabelsToNodes :: Eq a => FA () (Maybe a) -> FA (Maybe a) ()
|
moveLabelsToNodes :: Eq a => FA () (Maybe a) -> FA (Maybe a) ()
|
||||||
moveLabelsToNodes = onGraph moveLabelsToNodes_
|
moveLabelsToNodes = onGraph moveLabelsToNodes_
|
||||||
|
|
||||||
|
prGraphGraphviz :: FA String String -> String
|
||||||
|
prGraphGraphviz (FA (Graph _ ns es) _ _) =
|
||||||
|
"digraph {\n" ++ unlines (map prNode ns)
|
||||||
|
++ "\n"
|
||||||
|
++ unlines (map prEdge es)
|
||||||
|
++ "\n}\n"
|
||||||
|
where prNode (n,l) = show n ++ " [label = " ++ show l ++ "]"
|
||||||
|
prEdge (f,t,l) = show f ++ " -> " ++ show t ++ " [label = " ++ show l ++ "]"
|
||||||
|
|
||||||
--
|
--
|
||||||
-- * Graphs
|
-- * Graphs
|
||||||
--
|
--
|
||||||
@@ -152,14 +165,7 @@ mimimizeGr2 = id
|
|||||||
removeDuplicateEdges :: Ord b => Graph a b -> Graph a b
|
removeDuplicateEdges :: Ord b => Graph a b -> Graph a b
|
||||||
removeDuplicateEdges (Graph c ns es) = Graph c ns (sortNub es)
|
removeDuplicateEdges (Graph c ns es) = Graph c ns (sortNub es)
|
||||||
|
|
||||||
prGraphGraphviz :: Graph String String -> String
|
|
||||||
prGraphGraphviz (Graph _ ss ts) =
|
|
||||||
"digraph {\n" ++ unlines (map prNode ss)
|
|
||||||
++ "\n"
|
|
||||||
++ unlines (map prEdge ts)
|
|
||||||
++ "\n}\n"
|
|
||||||
where prNode (n,l) = show n ++ " [label = " ++ show l ++ "]"
|
|
||||||
prEdge (f,t,l) = show f ++ " -> " ++ show t ++ " [label = " ++ show l ++ "]"
|
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/09/12 21:41:19 $
|
-- > CVS $Date: 2005/09/12 22:32:24 $
|
||||||
-- > CVS $Author: bringert $
|
-- > CVS $Author: bringert $
|
||||||
-- > CVS $Revision: 1.6 $
|
-- > CVS $Revision: 1.7 $
|
||||||
--
|
--
|
||||||
-- This module converts a CFG to an SLF finite-state network
|
-- This module converts a CFG to an SLF finite-state network
|
||||||
-- for use with the ATK recognizer. The SLF format is described
|
-- for use with the ATK recognizer. The SLF format is described
|
||||||
@@ -53,12 +53,12 @@ slfPrinter name opts cfg = prSLF (automatonToSLF $ moveLabelsToNodes $ cfgToFA n
|
|||||||
slfGraphvizPrinter :: Ident -- ^ Grammar name
|
slfGraphvizPrinter :: Ident -- ^ Grammar name
|
||||||
-> Options -> CGrammar -> String
|
-> Options -> CGrammar -> String
|
||||||
slfGraphvizPrinter name opts cfg =
|
slfGraphvizPrinter name opts cfg =
|
||||||
prGraphGraphviz (nmap (fromMaybe "") $ emap (const "") $ asGraph $ moveLabelsToNodes $ cfgToFA name opts cfg)
|
prGraphGraphviz (mapStates (fromMaybe "") $ makeTransitions (const "") $ moveLabelsToNodes $ cfgToFA name opts cfg)
|
||||||
|
|
||||||
faGraphvizPrinter :: Ident -- ^ Grammar name
|
faGraphvizPrinter :: Ident -- ^ Grammar name
|
||||||
-> Options -> CGrammar -> String
|
-> Options -> CGrammar -> String
|
||||||
faGraphvizPrinter name opts cfg =
|
faGraphvizPrinter name opts cfg =
|
||||||
prGraphGraphviz (nmap (const "") $ emap (fromMaybe "") $ asGraph $ cfgToFA name opts cfg)
|
prGraphGraphviz (mapStates (const "") $ makeTransitions (fromMaybe "") $ cfgToFA name opts cfg)
|
||||||
|
|
||||||
-- | Convert the grammar to a regular grammar and print it in BNF
|
-- | Convert the grammar to a regular grammar and print it in BNF
|
||||||
regularPrinter :: CGrammar -> String
|
regularPrinter :: CGrammar -> String
|
||||||
|
|||||||
Reference in New Issue
Block a user