Skip to content

Commit

Permalink
Removed dependency of MissingH library
Browse files Browse the repository at this point in the history
  • Loading branch information
andreicosta committed May 19, 2017
1 parent 1b1e55e commit 70dd324
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/library/Graph/GraphMorphism.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ import Control.Arrow
import Abstract.Morphism
import qualified Abstract.Relation as R
import Abstract.Valid
import Data.List
import Data.Maybe (fromMaybe, isNothing, mapMaybe)
import Data.Maybe (fromMaybe, isNothing)
import Graph.Graph as G

data GraphMorphism a b = GraphMorphism {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ createSatisfyingNacsDisjointUnion (g,injG) (n,injN) = disjointUnionGraphs left r
(right,_) = graphMorphismToPartitionGraph injectiveN (M.codomain n) False id
disjointUnionGraphs a b = (nodes a ++ nodes b, edges a ++ edges b)

countIncidentMap :: Eq a => (a -> Maybe a) -> [a] -> a -> Int
countIncidentMap f l y = length $ filter (\x -> f x == Just y) l

graphMorphismToPartitionGraph :: ([NodeId],[EdgeId]) -> GraphMorphism (Maybe a) (Maybe b) -> Bool -> Int -> (GP.Graph,Int)
graphMorphismToPartitionGraph inj@(injNodes,_) morfL side id = ((nodes',edges'), nextId)
where
Expand Down
29 changes: 29 additions & 0 deletions src/library/Util/List.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ module Util.List
, listKeys
, replace
, repeated
, split
)

where

import Data.List (isPrefixOf)

-- TODO: Verify suitability for the use of Data.Sequence
-- | Replaces the @idx@-th element by @new@ in the list @l@
replace :: Int -> a -> [a] -> [a]
Expand Down Expand Up @@ -37,3 +40,29 @@ deleteByKey l k = filter (\a -> fst a /= k) l
{- | Given an element @e@ and a list @l@, it returns the number of times that @e@ appears in @l@ -}
countElement :: Eq a => a -> [a] -> Int
countElement i = length . filter (i==)

{- | Similar to Data.List.span, but performs the test on the entire remaining list instead of just one element.@-}
spanList :: ([a] -> Bool) -> [a] -> ([a], [a])
spanList _ [] = ([],[])
spanList func list@(x:xs) =
if func list
then (x:ys,zs)
else ([],list)
where (ys,zs) = spanList func xs

{- | Similar to Data.List.break, but performs the test on the entire remaining list instead of just one element.-}
breakList :: ([a] -> Bool) -> [a] -> ([a], [a])
breakList func = spanList (not . func)

{- | Given a delimiter and a list (or string), split into components.-}
split :: Eq a => [a] -> [a] -> [[a]]
split _ [] = []
split delim str =
let (firstline, remainder) = breakList (isPrefixOf delim) str
in
firstline : case remainder of
[] -> []
x -> if x == delim
then [[]]
else split delim
(drop (length delim) x)
5 changes: 2 additions & 3 deletions src/library/XML/GGXReader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Abstract.Valid
import qualified Data.List as L
import qualified Data.Map as M
import Data.Maybe (fromJust, fromMaybe, mapMaybe)
import Data.String.Utils (startswith)
import qualified Graph.Graph as G
import Graph.GraphMorphism as GM
import SndOrder.Morphism
Expand Down Expand Up @@ -53,7 +52,7 @@ readGrammar fileName useConstraints morphismsConf = do
parsedGraphs <- readGraphs fileName
parsedRules <- readRules fileName

let (sndOrdRules, fstOrdRules) = L.partition (\((x,_,_,_),_) -> startswith "2rule_" x) parsedRules
let (sndOrdRules, fstOrdRules) = L.partition (\((x,_,_,_),_) -> L.isPrefixOf "2rule_" x) parsedRules
rulesNames = map (\((x,_,_,_),_) -> x) fstOrdRules
productions = map (instantiateRule typeGraph) fstOrdRules

Expand Down Expand Up @@ -221,7 +220,7 @@ instantiateAtomicConstraint tg (name, premise, conclusion, maps) = buildNamedAto
p = instantiateTypedGraph premise tg
c = instantiateTypedGraph conclusion tg
m = buildGraphMorphism (domain p) (domain c) (map mapToId mNodes) (map mapToId mEdges)
isPositive = not $ startswith "-" name
isPositive = not $ L.isPrefixOf "-" name
mapToId (a,_,b) = (toN b, toN a)
pNodes = G.nodeIds (domain p)
(mNodes,mEdges) = L.partition (\(_,_,x) -> G.NodeId (toN x) `elem` pNodes) maps
Expand Down
8 changes: 4 additions & 4 deletions src/library/XML/ParseSndOrderRule.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ module XML.ParseSndOrderRule (

import Data.Char (toLower)
import Data.Function (on)
import Data.List (find, groupBy, sortBy, sortOn, (\\))
import Data.List (find, groupBy, intercalate, sortBy, sortOn, (\\))
import Data.Maybe (fromMaybe, mapMaybe)
import Data.String.Utils (join, split)

import Abstract.Morphism
import Graph.Graph
import Graph.GraphMorphism as GM
import TypedGraph.Morphism as TGM
import Util.List
import XML.ParsedTypes

-- | Gets the object name map between the left of two rules
Expand Down Expand Up @@ -119,7 +119,7 @@ getSndOrderRuleSide rule@((name,_,_,_),_) = (side, ruleName, rule)
side = if length splitted < 3
then error "Error parsing 2rule name"
else map toLower $ splitted !! 1
ruleName = join "_" (tail (tail splitted))
ruleName = intercalate "_" (tail (tail splitted))

-- put together rules in the form (left,right,[nacs])
groupRules :: [SndOrderRuleSide] -> [(SndOrderRuleSide,SndOrderRuleSide,[SndOrderRuleSide])]
Expand Down Expand Up @@ -174,7 +174,7 @@ parseNonMonoObjNames (x:xs) = (a,b,newObjName) : parseNonMonoObjNames xs
where
(a,b,_) = head x
allObjNames = map (\(_,_,y) -> y) x
newObjName = join "|" allObjNames
newObjName = intercalate "|" allObjNames

-- | Given two morphisms with the same domain, maps the codomain of both according to the interface (domain graph)
-- Used to translate DPO in verigraph to SPO in ggx
Expand Down
3 changes: 0 additions & 3 deletions verigraph.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ library
build-depends: base >=4.8 && <4.10,
containers >=0.4 && <0.6,
hxt >=9.3.1.15 && <9.4,
MissingH >=1.1 && <1.5,
mtl >=2.2 && <2.3,
parsec >=3.1 && <3.2,
QuickCheck >=2.8 && <2.10,
Expand Down Expand Up @@ -112,7 +111,6 @@ executable verigraph
containers,
hxt,
matrix >= 0.3,
MissingH,
optparse-applicative>=0.12 && < 0.14,
split >= 0.2
other-modules: ApplySndOrderRules
Expand Down Expand Up @@ -177,7 +175,6 @@ test-suite SecondOrderTest
main-is: SecondOrderTest.hs
type: exitcode-stdio-1.0
build-depends: base, verigraph,
MissingH >=1.1 && <1.5,
HUnit >= 1.3.1.2
other-modules: Utils

Expand Down

0 comments on commit 70dd324

Please sign in to comment.