Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing a simple graph api #14

Merged
merged 35 commits into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e0ada79
updated readme
Jun 28, 2017
aa2a7c2
Spacing changes
Jun 28, 2017
fff5d44
Updated to simple interface, list based
Jul 13, 2017
ede942c
Removed old implementation and altered the current parser to use the …
Jul 17, 2017
2520073
VHDL working again, most likely the list of nodes it used was reorder…
Jul 18, 2017
4a2f7bc
split insertEdges into addEdge and updateEdge
Jul 18, 2017
aad0b01
Fixed git issues, last few commits contain details of this commit
Jul 18, 2017
645eb02
Another iteration on the api, taking the idea that the maps and list …
Jul 19, 2017
4f24710
Applied hlint
Jul 19, 2017
c004654
bump stack to lts-8.22
Jul 19, 2017
8518bd0
Update to readme and example
Jul 19, 2017
e00d071
Added a second function which returns a pangraph or throws errors rat…
Jul 19, 2017
73ed92f
Changed vertices and edges function in Graph.hs to use Map.Strict ele…
Jul 20, 2017
83ee458
Removed dead code, improved error handling with a sum type in Error.h…
Jul 24, 2017
288e7a1
Changed Edge show implementation to make it compilable
Jul 24, 2017
95c8348
Merged Error.hs and GraphTypes.hs into Pangraph.hs
Jul 24, 2017
6799b76
Removed Error.hs in favour of Maybe to reflect errors in graphs
Jul 25, 2017
8c1f677
Improved implementation of *ContainsKey functions
Jul 25, 2017
3df235d
Applied hlint and uses of case statements to specialised functions
Jul 27, 2017
4b18f17
Moved the reading example into an area that is compiled
Jul 27, 2017
8a6b9e6
Apply Hlint
Jul 27, 2017
c23f4f8
Updated readme
Jul 27, 2017
666a081
Refactor of Test.hs following your style recommendations
Jul 27, 2017
58ad815
Formatting changes in monadic code, bug fix for VHDL testing
Jul 28, 2017
b6011fb
Used HUnit in testing, no file IO is required for testing the run now
Aug 4, 2017
30143ab
Added Haddock, updates to readme
Aug 4, 2017
20ead9b
Spacing Change
Aug 4, 2017
ab76a56
Fixed mistake in example
thisiswhereitype Aug 4, 2017
ae4b278
Bump to lts-9.00
thisiswhereitype Aug 6, 2017
2f0be80
Merge branch 'master' of github.com:thisiswhereitype/pangraph
thisiswhereitype Aug 6, 2017
9afc3d2
Haddock typo
thisiswhereitype Aug 7, 2017
d55bb02
Fixed all --wall warnings
thisiswhereitype Aug 7, 2017
dd42b08
Fixed --wall messages in test/
thisiswhereitype Aug 7, 2017
46333ec
VHDL now exported through Pangraph.VHDL with ByteString Interface, re…
thisiswhereitype Aug 9, 2017
dab67f7
Moved the VHDL writer to have the same nomenclature as the reset of t…
thisiswhereitype Aug 10, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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