proto-voice-model-0.1.0.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Display

Description

This module contains functions for visualizing derivations using LaTeX and TikZ. These functions are generic over slice and transition contents and are thus somewhat limited. For protovoice derivations, an alternative to plotting a derivation would be to export an Analysis to JSON and view it interactively in the protovoice annotation tool (not implemented yet).

Plotting happens in two steps. First, a the derivation is "replayed" using a (generic or grammar-specific) "player" to construct a DerivationGraph, which contains all graphical objects and their positions explicitly. The DerivationGraph can then be plotted using different backends (currently only TikZ, but a diagrams/SVG backed would be useful too).

Synopsis

Documentation

data DerivationGraph slc tr Source #

A derivation graph. Contains the graphical objects of a derivation plot as well as intermediate information that is used during a replay.

Constructors

DGraph 

Fields

Instances

Instances details
(Show slc, Show tr) => Show (DerivationGraph slc tr) Source # 
Instance details

Defined in Display

Methods

showsPrec :: Int -> DerivationGraph slc tr -> ShowS #

show :: DerivationGraph slc tr -> String #

showList :: [DerivationGraph slc tr] -> ShowS #

(Eq slc, Eq tr) => Eq (DerivationGraph slc tr) Source # 
Instance details

Defined in Display

Methods

(==) :: DerivationGraph slc tr -> DerivationGraph slc tr -> Bool #

(/=) :: DerivationGraph slc tr -> DerivationGraph slc tr -> Bool #

(Ord slc, Ord tr) => Ord (DerivationGraph slc tr) Source # 
Instance details

Defined in Display

Methods

compare :: DerivationGraph slc tr -> DerivationGraph slc tr -> Ordering #

(<) :: DerivationGraph slc tr -> DerivationGraph slc tr -> Bool #

(<=) :: DerivationGraph slc tr -> DerivationGraph slc tr -> Bool #

(>) :: DerivationGraph slc tr -> DerivationGraph slc tr -> Bool #

(>=) :: DerivationGraph slc tr -> DerivationGraph slc tr -> Bool #

max :: DerivationGraph slc tr -> DerivationGraph slc tr -> DerivationGraph slc tr #

min :: DerivationGraph slc tr -> DerivationGraph slc tr -> DerivationGraph slc tr #

data DerivSlice slc Source #

A slice together with a depth and an ID

Constructors

DerivSlice 

Fields

Instances

Instances details
Show slc => Show (DerivSlice slc) Source # 
Instance details

Defined in Display

Methods

showsPrec :: Int -> DerivSlice slc -> ShowS #

show :: DerivSlice slc -> String #

showList :: [DerivSlice slc] -> ShowS #

Eq slc => Eq (DerivSlice slc) Source # 
Instance details

Defined in Display

Methods

(==) :: DerivSlice slc -> DerivSlice slc -> Bool #

(/=) :: DerivSlice slc -> DerivSlice slc -> Bool #

Ord slc => Ord (DerivSlice slc) Source # 
Instance details

Defined in Display

Methods

compare :: DerivSlice slc -> DerivSlice slc -> Ordering #

(<) :: DerivSlice slc -> DerivSlice slc -> Bool #

(<=) :: DerivSlice slc -> DerivSlice slc -> Bool #

(>) :: DerivSlice slc -> DerivSlice slc -> Bool #

(>=) :: DerivSlice slc -> DerivSlice slc -> Bool #

max :: DerivSlice slc -> DerivSlice slc -> DerivSlice slc #

min :: DerivSlice slc -> DerivSlice slc -> DerivSlice slc #

type DerivTrans slc tr = (DerivSlice slc, tr, DerivSlice slc) Source #

A transition between two DerivSlices.

Replaying Derivations

replayDerivation Source #

Arguments

:: (Foldable t, Ord slc, Ord tr) 
=> DerivationPlayer s f h slc tr

the derivation player

-> t (Leftmost s f h)

the derivation

-> Either String (DerivationGraph slc tr) 

Replay a derivation from ⋊——⋉.

replayDerivation' Source #

Arguments

:: (Foldable t, Ord slc, Ord tr) 
=> Path tr slc

the starting point of the derivation

-> DerivationPlayer s f h slc tr

the derivation player

-> t (Leftmost s f h)

the derivation

-> Either String (DerivationGraph slc tr) 

Replay a derivation from n top-level transitions.

replayDerivationFull Source #

Arguments

:: (Foldable t, Ord slc, Ord tr) 
=> DerivationPlayer s f h slc tr

the derivation player

-> t (Leftmost s f h)

the derivation

-> Either String (DerivationGraph slc tr) 

Replay a derivation from ⋊——⋉ and ensure that the dervation is complete (freezing all transitions). Return an error message if not.

unfoldDerivation Source #

Arguments

:: (Ord slc, Ord tr) 
=> DerivationPlayer s f h slc tr

the derivation player

-> [Leftmost s f h]

the derivation

-> [Either String (DerivationGraph slc tr)] 

Replays a derivation from ⋊——⋉ and returns every intermediate derivation graph.

unfoldDerivation' Source #

Arguments

:: (Ord slc, Ord tr) 
=> Path tr slc

the starting point of the derivation

-> DerivationPlayer s f h slc tr

the derivation player

-> [Leftmost s f h]

the derivation

-> [Either String (DerivationGraph slc tr)] 

Replays a derivation from n top-level transitions and returns every intermediate derivation graph.

Derivation Players

data DerivationPlayer s f h slc tr Source #

A derivation player. Contains functions for replaying derivations of a particular grammar, i.e. for deriving child elements from parent elements.

Constructors

DerivationPlayer 

Fields

derivationPlayerUnit :: DerivationPlayer s f h () () Source #

A derivation player that uses () for slice and transition contents. The actual derivation operations are ignored, so only the outer structure is produced.

derivationPlayerEmpty :: DerivationPlayer s f h Empty Empty Source #

A derivation player that uses Empty for slice and transition content. The actual derivation operations are ignored, so only the outer structure is produced.

data Empty Source #

A helper type that is like () but has a Show instance that returns the empty string.

Instances

Instances details
Show Empty Source # 
Instance details

Defined in Display

Methods

showsPrec :: Int -> Empty -> ShowS #

show :: Empty -> String #

showList :: [Empty] -> ShowS #

Eq Empty Source # 
Instance details

Defined in Display

Methods

(==) :: Empty -> Empty -> Bool #

(/=) :: Empty -> Empty -> Bool #

Ord Empty Source # 
Instance details

Defined in Display

Methods

compare :: Empty -> Empty -> Ordering #

(<) :: Empty -> Empty -> Bool #

(<=) :: Empty -> Empty -> Bool #

(>) :: Empty -> Empty -> Bool #

(>=) :: Empty -> Empty -> Bool #

max :: Empty -> Empty -> Empty #

min :: Empty -> Empty -> Empty #

Plotting Derivation Graphs with TikZ

tikzDerivationGraph Source #

Arguments

:: (Eq slc, Eq tr) 
=> (slc -> Text)

a function for displaying slice contents

-> (tr -> Text)

a function for displaying transitions contents

-> DerivationGraph slc tr

the derivation graph

-> Text 

Convert a derivation graph into a series of TikZ commands.

tikzPic :: (Semigroup a, IsString a) => a -> a Source #

Wraps TikZ commands in a tikzpicture environment.

tikzStandalone Source #

Arguments

:: (Semigroup a, IsString a) 
=> Bool

a flag for using the the varwidth option of standalone (needed for multiline content)

-> a

the document content

-> a 

Wraps latex code (e.g. a tikzpicture) in a complete standalone document. This environment includes default styles for slices, transitions, and hori edges.

writeGraph :: (Show slc, Eq slc, Eq tr, Show tr) => FilePath -> DerivationGraph slc tr -> IO () Source #

Write a single derivation graph to a tex file.

writeGraphs :: (Show tr, Show slc, Eq slc, Eq tr) => FilePath -> [DerivationGraph slc tr] -> IO () Source #

Write a several derivation graphs to a tex file.

viewGraph :: (Eq slc, Eq tr, Show slc, Show tr) => FilePath -> DerivationGraph slc tr -> IO () Source #

Write a single derivation graph to a tex file and compile the file using pdflatex.

viewGraphs :: (Show tr, Show slc, Eq slc, Eq tr) => FilePath -> [DerivationGraph slc tr] -> IO () Source #

Write a several derivation graphs to a tex file and compile the file using pdflatex.