From 136728e336d66349723f882fcd87a2eb8d42903c Mon Sep 17 00:00:00 2001 From: bringert Date: Thu, 10 Nov 2005 15:43:44 +0000 Subject: Prepared for generation of finite automata in C. --- src/GF/Speech/Graph.hs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/GF/Speech/Graph.hs') diff --git a/src/GF/Speech/Graph.hs b/src/GF/Speech/Graph.hs index 64b73a70a..2f80ef0ca 100644 --- a/src/GF/Speech/Graph.hs +++ b/src/GF/Speech/Graph.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/10/26 17:13:13 $ +-- > CVS $Date: 2005/11/10 16:43:44 $ -- > CVS $Author: bringert $ --- > CVS $Revision: 1.1 $ +-- > CVS $Revision: 1.2 $ -- -- A simple graph module. ----------------------------------------------------------------------------- @@ -16,7 +16,7 @@ module GF.Speech.Graph ( Graph(..), Node, Edge, Incoming, Outgoing , nmap, emap, newNode, newEdge, newEdges , incoming, outgoing, getOutgoing , getFrom, getTo, getLabel - , reverseGraph + , reverseGraph, renameNodes ) where import GF.Data.Utilities @@ -41,9 +41,11 @@ nodes (Graph _ ns _) = ns edges :: Graph n a b -> [Edge n b] edges (Graph _ _ es) = es +-- | Map a function over the node label.s nmap :: (a -> c) -> Graph n a b -> Graph n c b nmap f (Graph c ns es) = Graph c [(n,f l) | (n,l) <- ns] es +-- | Map a function over the edge labels. emap :: (b -> c) -> Graph n a b -> Graph n a c emap f (Graph c ns es) = Graph c ns [(x,y,f l) | (x,y,l) <- es] @@ -86,3 +88,12 @@ getLabel (_,_,l) = l reverseGraph :: Graph n a b -> Graph n a b reverseGraph (Graph c ns es) = Graph c ns [ (t,f,l) | (f,t,l) <- es ] + +-- | Re-name the nodes in the graph. +renameNodes :: (n -> m) -- ^ renaming function + -> [m] -- ^ infinite supply of fresh node names, to + -- use when adding nodes in the future. + -> Graph n a b -> Graph m a b +renameNodes newName c (Graph _ ns es) = Graph c ns' es' + where ns' = [ (newName n,x) | (n,x) <- ns ] + es' = [ (newName f, newName t, l) | (f,t,l) <- es] -- cgit v1.2.3