Commit 927ecc2d authored by Alp Mestanogullari's avatar Alp Mestanogullari

tentative fix

parent f0b23369
...@@ -29,6 +29,9 @@ import qualified Data.Graph.Inductive.PatriciaTree as DGIP ...@@ -29,6 +29,9 @@ import qualified Data.Graph.Inductive.PatriciaTree as DGIP
import qualified Data.List as List import qualified Data.List as List
import qualified Data.Set as Set import qualified Data.Set as Set
import qualified Data.Vector as Vector import qualified Data.Vector as Vector
import Data.Semigroup
import qualified Data.IntMap.Strict as IntMap
import Data.Maybe (fromJust)
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | Clean tools -- | Clean tools
...@@ -59,15 +62,42 @@ data FileGraph = CillexGraph | TestGraph | SnapGraph ...@@ -59,15 +62,42 @@ data FileGraph = CillexGraph | TestGraph | SnapGraph
readFileGraph :: FileGraph -> FilePath -> IO (DGIP.Gr [Text] Double) readFileGraph :: FileGraph -> FilePath -> IO (DGIP.Gr [Text] Double)
readFileGraph CillexGraph fp = toGraph <$> snd <$> readFileCsvCillex fp readFileGraph CillexGraph fp = toGraph <$> snd <$> readFileCsvCillex fp
readFileGraph TestGraph fp = toGraph <$> snd <$> readFileCsvTest fp readFileGraph TestGraph fp = toGraph <$> snd <$> readFileCsvTest fp
readFileGraph SnapGraph fp = toGraph <$> snd <$> readFileSnapCsv fp -- readFileGraph SnapGraph fp = toGraph <$> snd <$> readFileSnapCsv fp
readFileGraph SnapGraph fp = toGraph'' <$> snd <$> readFileSnapCsv fp
toGraph'' :: Vector SnapCsv -> DGIP.Gr [Text] Double
toGraph'' v = DGI.undir (DGI.mkGraph ns es')
where es = List.map (\(SnapCsv f t) -> (f, t)) $ Vector.toList v
(_, nodeDict) = List.foldl'
(\(nextIdx, dict) (from, to) ->
let (nextIdx1, dict1) = smartInsert nextIdx from dict
in smartInsert nextIdx1 to dict1
)
(0, mempty)
es
es' = List.map
(\(f, t) -> ( fromJust (IntMap.lookup f nodeDict)
, fromJust (IntMap.lookup t nodeDict)
, 1
)
)
es
ns = List.map (\(a, b) -> (b, [Protolude.show a])) (IntMap.toList nodeDict)
smartInsert nextI v dict = case IntMap.lookup v dict of
Nothing -> (nextI+1, IntMap.insert v nextI dict)
Just i -> (nextI, dict)
toGraph :: ToNode a => Vector a -> (DGIP.Gr [Text] Double) toGraph :: ToNode a => Vector a -> (DGIP.Gr [Text] Double)
toGraph vs = DGI.mkGraph ns (uniq' $ List.concat es) toGraph vs = g
where where
(ns,es) = List.unzip (ns,es) = List.unzip
$ Vector.toList $ Vector.toList
$ Vector.map toNode vs $ Vector.map toNode vs
g = DGI.mkGraph ns (uniq' $ List.concat es)
------------------------------------------------------------------------ ------------------------------------------------------------------------
class ToNode a where class ToNode a where
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment