Skip to content

Commit

Permalink
Implementing a simple graph api (tuura#14)
Browse files Browse the repository at this point in the history
* updated readme

* Spacing changes

* Updated to simple interface, list based

* Removed old implementation and altered the current parser to use the new graph. VHDL section has been disabled but I commit again before the pr is merged to fix it.

* VHDL working again, most likely the list of nodes it used was reordered in conversion to and from maps. Moved helper functions into the internal module. Added functions like  and

* split insertEdges into addEdge and updateEdge

* Fixed git issues, last few commits contain details of this commit

* Another iteration on the api, taking the idea that the maps and list librarys have lots of fucntions for manipulating their respective instances

* Applied hlint

* bump stack to lts-8.22

* Update to readme and example

* Added a second function which returns a pangraph or throws errors rather then returning either

* Changed vertices and edges function in Graph.hs to use Map.Strict elem fucntion

* Removed dead code, improved error handling with a sum type in Error.hs, concrete implementations their instances are now in an internal file to avoid cyclic dependencies

* Changed Edge show implementation to make it compilable

* Merged Error.hs and GraphTypes.hs into Pangraph.hs

* Removed Error.hs in favour of Maybe to reflect errors in graphs

* Improved implementation of *ContainsKey functions

* Applied hlint and uses of case statements to specialised functions

* Moved the reading example into an area that is compiled

* Apply Hlint

* Updated readme

* Refactor of Test.hs following your style recommendations

* Formatting changes in monadic code, bug fix for VHDL testing

* Used HUnit in testing, no file IO is required for testing the run now

* Added Haddock, updates to readme

* Spacing Change

* Fixed mistake in example

* Bump to lts-9.00

* Haddock typo

* Fixed all --wall warnings

* Fixed --wall messages in test/

* VHDL now exported through Pangraph.VHDL with ByteString Interface, removed large VHDL test case, corrected import syntax in some modules

* Moved the VHDL writer to have the same nomenclature as the reset of the project, made import names clearer
  • Loading branch information
thisiswhereitype authored and snowleopard committed Aug 10, 2017
1 parent 0037184 commit 56da512
Show file tree
Hide file tree
Showing 19 changed files with 1,104 additions and 457 deletions.
84 changes: 27 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,29 @@
This is a Haskell Library for parsing graph formats such as [GraphML](http://graphml.graphdrawing.org/) and the XML files produced by [Workcraft](https://www.workcraft.org/).
The library currently implements parsing only the nodes and edges of undirected graphs.
See the User Guide for how to use this, with examples below.
Also information on current graph support below that.
Information on current graph support can be found below that.

## Getting Started
The library `Pangraph` exports the following types:
## How to use Pangraph

Pangraph offers an api in the module `Pangraph` for accessing of graphs including constructors and getters.
You can construct entire graph or edit the results of parser.
These are imported independently form their own modules:
```haskell
import Pangraph.GraphML.Parser
```
data Att = Att (String, String) deriving (Show, Eq)
data Node = Node [Att] deriving (Show, Eq)
data Edge = Edge [Att] deriving (Show, Eq)
data ShortGraph = ShortGraph [Node] [Edge] deriving (Show, Eq)
data ShortFile = ShortFile [ShortGraph] deriving (Show, Eq)
```

The first five types above define a graph. When parsed one ShortFile will be produced containing one ShortGraph containing zero or more edges and arcs. The library does not check the graphs for correctness however.

To parse graphs you must import them directly.
```
import Pangraph.GraphML.Writer
import Pangraph.Workcraft.Parser
```

All parsers export the following:
```
module Pangraph.Example.Parser
( parseFile
, parseString
)where
```
To use these functions,
And writers export:
```
module Pangraph.GraphML.Writer
( writeGraph
) where
...
All parsers currently export the following:
```haskell
parse :: ByteString -> Maybe Pangraph
unsafeParse :: ByteString -> Pangraph
```

An example of reading code can be found in `Examples` below
## Binary generation

One of the two commands below should be used for the compilation and the generation of a binary file:


```
ghc -isrc -ifantasi fantasi/Main.hs -o Fantasi
```
Expand All @@ -56,44 +38,32 @@ cabal install
## Examples
### Parsing a Graph file
```
module Reading where
### Parsing a Graph file
Repeated here the code from `src/Pangraph/Examples`:
```haskell
module Pangraph.Examples.Reading where
import Prelude hiding (readFile)
import Data.ByteString (readFile)
import System.IO
import Pangraph
import qualified Pangraph.GraphML.Parser as G
import qualified Pangraph.GraphML.Parser as GraphML_P
main::IO()
main=do
main :: IO ()
main = do
fileName <- getLine
file <- readFile fileName
let graph = G.parseAsString file
putStr $ show graph
```

### Parsing a graph and then writing to a file
print (GraphML_P.parse file)
```
module Writing where

import System.IO
import Pangraph
import qualified Pangraph.GraphML.Writer as G
main::IO()
main=do
filePath <- getLine
G.writeGraph filePath graph
where
graph = ShortFile [ShortGraph [Node [Att ("id","n0")],Node [Att ("id","n1")],Node [Att ("id","n2")]] [Edge [Att ("source","n0"),Att ("target","n2")]]]
```
## Graph support
### [GraphML](http://graphml.graphdrawing.org/)
GraphML files are currently:
- Parsing: Ok
- Writing: Ok
- Writing: **Unimplemented**

### [Workcraft](https://www.workcraft.org/)
Workcraft files are currently:
- Parsing: need to be unzipped manually and given a path to the `model.xml` file that was unzipped.
- Parsing: **Unimplemented**
- Writing: **Unimplemented**
93 changes: 0 additions & 93 deletions Test.hs

This file was deleted.

13 changes: 0 additions & 13 deletions examples/code/Reading.hs

This file was deleted.

22 changes: 8 additions & 14 deletions fantasi/Tuura/Fantasi/Main.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
module Tuura.Fantasi.Main (main) where

import Control.Monad
import System.FilePath

import Tuura.Fantasi.Options
import qualified Pangraph.GraphML.Parser as P
import qualified Pangraph.VHDL.EnvironmentWriter as W1
import qualified Pangraph.VHDL.GraphWriter as W2
import qualified Pangraph.VHDL.Writer as VHDL
import Data.ByteString.Char8 (pack, unpack)

main :: IO ()
Expand All @@ -18,13 +14,11 @@ main = do
simulationEnvVhdlPath = optSimName options

-- parse graph
case P.parseTemplateToPangraph (head P.template) (pack graphMLPath) of
Left l -> error $ show l
Right graphParsed -> do
let graphVHDL = W2.writeGraphVhdl graphParsed
let simEnvVHDL = W1.writeEnvironmentVhdl graphParsed
let pangraph = P.unsafeParse (pack graphMLPath)
let graphVHDL = (unpack . VHDL.writeGraph) pangraph
let simEnvVHDL = (unpack . VHDL.writeEnvironment) pangraph

-- output vhdl graph
writeFile graphVHDLPath graphVHDL
-- output vhdl simulation environment
writeFile simulationEnvVhdlPath simEnvVHDL
-- output vhdl graph
writeFile graphVHDLPath graphVHDL
-- output vhdl simulation environment
writeFile simulationEnvVhdlPath simEnvVHDL
20 changes: 13 additions & 7 deletions pangraph.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,30 @@ library
hs-source-dirs: src
exposed-modules: Pangraph
, Pangraph.GraphML.Parser
, Pangraph.VHDL.GraphWriter
, Pangraph.VHDL.EnvironmentWriter
other-modules: Pangraph.XMLTemplate
, Pangraph.VHDL.Writer
, Pangraph.VHDL.Internal.GraphWriter
, Pangraph.VHDL.Internal.EnvironmentWriter
, Pangraph.Internal.XMLTemplate
other-modules: Pangraph.Examples.Reading
build-depends: base >= 4.8 && < 5
, bytestring
, hexml
, algebraic-graphs
, containers
default-language: Haskell2010
GHC-options: -Wall -fwarn-tabs -O2

test-suite pangraph-test
type: exitcode-stdio-1.0
main-is: Test.hs
hs-source-dirs: test
main-is: Main.hs
other-modules: Show
, GraphML
, VHDL
, VHDLLiterals
build-depends: base >= 4.8 && < 5
, pangraph
, hexml
, bytestring
, algebraic-graphs
, HUnit
default-language: Haskell2010
GHC-options: -Wall -fwarn-tabs -fbreak-on-exception

Expand Down
Loading

0 comments on commit 56da512

Please sign in to comment.