diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-05-04 00:34:53 +1000 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-05-04 00:34:53 +1000 |
commit | 72f82d4c5c3a777e006d7f2718c338aa87cd4060 (patch) | |
tree | 5d7d5a66134006f0d6b2fef02b1ce20a63be99e8 | |
parent | 5a88af610d119baf0e329edeb2bf615f3a63d2b4 (diff) |
Can now look up nodes in a graph that have a specific name
-rw-r--r-- | src/Grasp/Types.hs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/Grasp/Types.hs b/src/Grasp/Types.hs index 0211281..72f835a 100644 --- a/src/Grasp/Types.hs +++ b/src/Grasp/Types.hs @@ -11,6 +11,8 @@ import Data.Graph.Inductive.Graph( Node, LNode, LEdge, (&) ) import qualified Data.Graph.Inductive.Graph as Graph import Data.Graph.Inductive.Tree import Data.List +import Data.Maybe +import qualified Data.Map as Map @@ -27,10 +29,21 @@ instance (Ord a, Ord b) => Eq (Gr a b) where nodesWithName :: GraspProgram -> String -> [LNode String] -nodesWithName g s = [] +nodesWithName g s = + let nodes = Graph.labNodes g + edges = Graph.labEdges g + nodeLabelMap = Map.fromList nodes + nameEdges = filter (\(_,_,z) -> z == "name") edges + specific = filter (\(_,y,_) -> fromJust (Map.lookup y nodeLabelMap) == s) nameEdges + nameNodes = map (\(x,_,_) -> x) specific + in filter (\(x,_) -> x `elem` nameNodes) nodes + + + +-- to-do normalise :: GraspProgram -> GraspProgram normalise g = Graph.mkGraph [] [] |