| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
ChartParser
Description
A chart-based semiring parser for path grammars (e.g. the PV grammar).
Path grammars operate on "paths"
consisting of nodes (slices) and edges (transitions),
both of which can contain arbitrary content.
Paths are elaborated through two operations,
splitting transitions and spreading slices
(plus freeze, which terminates generation on a transition).
The parser is polymorphic in the grammar
as well as the contents of slices (path nodes) and transitions (path edges).
The grammar to parse is definend in an "evaluator" (Eval)
which provides completions for parsing the splits, spreads and freezes.
Synopsis
- parse :: Parsable tr slc h v => (TChart tr slc v -> Either (VChart tr slc h v) [Slice slc] -> Int -> IO ()) -> Eval tr tr' slc slc' h v -> Path slc' tr' -> IO v
- parseSize :: Parsable tr slc h v => Eval tr tr' slc slc' h v -> Path slc' tr' -> IO v
- parseSilent :: Parsable tr slc h v => Eval tr tr' slc slc' h v -> Path slc' tr' -> IO v
- logSize :: TChart tr1 slc1 v1 -> Either (VChart tr2 slc2 h2 v2) [Slice slc2] -> Int -> IO ()
- logTikz :: (Foldable t, Show slc1, Show slc2, Hashable tr1, Eq slc3) => TChart tr1 slc3 v1 -> Either (VChart tr2 slc1 h v2) (t (Slice slc2)) -> Int -> IO ()
- data Slice slc
- data Transition tr slc
- transLen :: Transition e a -> Int
- data Item i v
- type TItem tr slc v = Item (Transition tr slc) v
- type TContents tr slc v = HashMap (Transition tr slc, Maybe (LeftId Int), Maybe (RightId Int)) (Score v Int)
- data TChart tr slc v
- tcGetByLength :: TChart tr slc v -> Int -> [TItem tr slc v]
- data Vert tr slc h v
- data VChart tr slc h v
- vcGetByLength :: VChart tr slc h v -> Int -> [Vert tr slc h v]
- type Parsable tr slc h v = (Normal tr, Normal slc, Normal h, Normal' v)
- type Normal x = (Eq x, Ord x, Show x, Hashable x, NFData x)
- type Normal' x = (Eq x, Show x, NFData x, Semiring x)
Parsing Interface
Arguments
| :: Parsable tr slc h v | |
| => (TChart tr slc v -> Either (VChart tr slc h v) [Slice slc] -> Int -> IO ()) | logging function |
| -> Eval tr tr' slc slc' h v | the grammar's evaluator |
| -> Path slc' tr' | the input path (from first to last slice, excluding |
| -> IO v | the semiring value at the top |
The main entrypoint to the parser. Expects an evaluator for the specific grammar and an input path. Returns the combined semiring value of all full derivations.
parseSize :: Parsable tr slc h v => Eval tr tr' slc slc' h v -> Path slc' tr' -> IO v Source #
Parse a piece using the logSize logging function.
parseSilent :: Parsable tr slc h v => Eval tr tr' slc slc' h v -> Path slc' tr' -> IO v Source #
Parse a piece without logging.
logSize :: TChart tr1 slc1 v1 -> Either (VChart tr2 slc2 h2 v2) [Slice slc2] -> Int -> IO () Source #
A logging function that logs the sice of the charts at each level.
logTikz :: (Foldable t, Show slc1, Show slc2, Hashable tr1, Eq slc3) => TChart tr1 slc3 v1 -> Either (VChart tr2 slc1 h v2) (t (Slice slc2)) -> Int -> IO () Source #
A logging function that emits the state of the chart in TikZ code at every level.
Charts
Basic Elements
A slice during chart parsing. Besides the slice content (e.g., notes), it maintains indices to the first and last surface slice covered, as well as an ID that is used for matching compatible parents of a spread.
Instances
data Transition tr slc Source #
A transition during chart parsing. Has pointers to the two slices it connects, a content (e.g., protovoice connections), and a flag indicating whether it is the second (right) parent of a spread.
Instances
| (NFData slc, NFData tr) => NFData (Transition tr slc) Source # | |||||
Defined in ChartParser Methods rnf :: Transition tr slc -> () # | |||||
| Generic (Transition tr slc) Source # | |||||
Defined in ChartParser Associated Types
Methods from :: Transition tr slc -> Rep (Transition tr slc) x # to :: Rep (Transition tr slc) x -> Transition tr slc # | |||||
| (Show a, Show e) => Show (Transition e a) Source # | |||||
Defined in ChartParser Methods showsPrec :: Int -> Transition e a -> ShowS # show :: Transition e a -> String # showList :: [Transition e a] -> ShowS # | |||||
| (Eq slc, Eq tr) => Eq (Transition tr slc) Source # | |||||
Defined in ChartParser Methods (==) :: Transition tr slc -> Transition tr slc -> Bool # (/=) :: Transition tr slc -> Transition tr slc -> Bool # | |||||
| (Ord slc, Ord tr) => Ord (Transition tr slc) Source # | |||||
Defined in ChartParser Methods compare :: Transition tr slc -> Transition tr slc -> Ordering # (<) :: Transition tr slc -> Transition tr slc -> Bool # (<=) :: Transition tr slc -> Transition tr slc -> Bool # (>) :: Transition tr slc -> Transition tr slc -> Bool # (>=) :: Transition tr slc -> Transition tr slc -> Bool # max :: Transition tr slc -> Transition tr slc -> Transition tr slc # min :: Transition tr slc -> Transition tr slc -> Transition tr slc # | |||||
| (Eq slc, Hashable tr) => Hashable (Transition tr slc) Source # | |||||
Defined in ChartParser | |||||
| type Rep (Transition tr slc) Source # | |||||
Defined in ChartParser type Rep (Transition tr slc) = D1 ('MetaData "Transition" "ChartParser" "protovoices-0.1.0.0-BDEUxFN8Fm0COc6pAhx3U0" 'False) (C1 ('MetaCons "Transition" 'PrefixI 'True) ((S1 ('MetaSel ('Just "tLeftSlice") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Slice slc)) :*: S1 ('MetaSel ('Just "tContent") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 tr)) :*: (S1 ('MetaSel ('Just "tRightSlice") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Slice slc)) :*: S1 ('MetaSel ('Just "t2nd") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool)))) | |||||
transLen :: Transition e a -> Int Source #
Returns the "length" of the transition in terms of surface slices covered.
A parsing item. Combines an intermediate value (e.g. a transition) with a semiring score.
Instances
| (NFData i, NFData v) => NFData (Item i v) Source # | |||||
Defined in ChartParser | |||||
| Generic (Item i v) Source # | |||||
Defined in ChartParser Associated Types
| |||||
| (Show i, Show v) => Show (Item i v) Source # | |||||
| type Rep (Item i v) Source # | |||||
Defined in ChartParser type Rep (Item i v) = D1 ('MetaData "Item" "ChartParser" "protovoices-0.1.0.0-BDEUxFN8Fm0COc6pAhx3U0" 'False) (C1 ('MetaCons ":=" 'PrefixI 'True) (S1 ('MetaSel ('Just "iItem") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 i) :*: S1 ('MetaSel ('Just "iScore") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Score v Int)))) | |||||
type TItem tr slc v = Item (Transition tr slc) v Source #
A transition item.
Transition Chart
type TContents tr slc v = HashMap (Transition tr slc, Maybe (LeftId Int), Maybe (RightId Int)) (Score v Int) Source #
The contents of a transition chart (under a particular index). A mapping from transitions (with score ID constraints left and right) to (partial) semiring scores. This mapping usually contains all transition items that satisfy a certain criterion, irrespective of their position in the chart (which is encoded in the transitions themselves).
When new transition items are added, if the transition already exists in the chart (as the result of a different partial parse), the scores of the new and existing items are "added" (this also requires the score IDs to match).
A transition chart. Stores intermediate transition items redundantly under several indices:
- by surface length
- by left slice
- by right slice
Instances
| (NFData slc, NFData tr, NFData v) => NFData (TChart tr slc v) Source # | |||||
Defined in ChartParser | |||||
| Generic (TChart tr slc v) Source # | |||||
Defined in ChartParser Associated Types
| |||||
| (Show slc, Show tr) => Show (TChart tr slc v) Source # | |||||
| type Rep (TChart tr slc v) Source # | |||||
Defined in ChartParser type Rep (TChart tr slc v) = D1 ('MetaData "TChart" "ChartParser" "protovoices-0.1.0.0-BDEUxFN8Fm0COc6pAhx3U0" 'False) (C1 ('MetaCons "TChart" 'PrefixI 'True) (S1 ('MetaSel ('Just "tcByLength") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (IntMap (TContents tr slc v))) :*: (S1 ('MetaSel ('Just "tcByLeft") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (HashMap (Slice slc) (TContents tr slc v))) :*: S1 ('MetaSel ('Just "tcByRight") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (HashMap (Slice slc) (TContents tr slc v)))))) | |||||
tcGetByLength :: TChart tr slc v -> Int -> [TItem tr slc v] Source #
Returns all transition items with the same length.
Verticalization Chart
Represents the middle part of an incomplete unspread ("verticalization").
Expresses how the middle transition and the two child slices (vMiddle)
are derived from the parent slice (vTop) using a spread operation (vOp).
Vert objects are stored in the VChart
to record the intermediate steps of an unspread,
which is found by first parsing the middle transition into the parent slice
(generating a Vert)
and then combining the Vert with the left and right child transitions
to generate the left and right parent transitions, respectively.
Instances
| (NFData slc, NFData h, NFData v, NFData tr) => NFData (Vert tr slc h v) Source # | |||||
Defined in ChartParser | |||||
| Generic (Vert tr slc h v) Source # | |||||
Defined in ChartParser Associated Types
| |||||
| (Show e, Show a, Show h, Show v) => Show (Vert e a h v) Source # | |||||
| type Rep (Vert tr slc h v) Source # | |||||
Defined in ChartParser type Rep (Vert tr slc h v) = D1 ('MetaData "Vert" "ChartParser" "protovoices-0.1.0.0-BDEUxFN8Fm0COc6pAhx3U0" 'False) (C1 ('MetaCons "Vert" 'PrefixI 'True) ((S1 ('MetaSel ('Just "vTop") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Slice slc)) :*: S1 ('MetaSel ('Just "vOp") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 h)) :*: (S1 ('MetaSel ('Just "vVal") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 v) :*: S1 ('MetaSel ('Just "vMiddle") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (TItem tr slc v))))) | |||||
data VChart tr slc h v Source #
A verticalization chart.
Stores Vert objects at certain chart positions.
To support efficient lookup of Vert objects from different indices,
each Vert is redundantly stored in several hash maps,
one for each index:
- by surface length
- by surface length (only left border of a
Vert) - by left child slice ID and mid transition length
- by right child ID
In addition, the VChart maintains IDs of new slices.
(Every new slice is the parent of an unspread.)
Instances
| (NFData slc, NFData h, NFData v, NFData tr) => NFData (VChart tr slc h v) Source # | |||||
Defined in ChartParser | |||||
| Generic (VChart tr slc h v) Source # | |||||
Defined in ChartParser Associated Types
| |||||
| (Show tr, Show slc, Show h, Show v) => Show (VChart tr slc h v) Source # | |||||
| type Rep (VChart tr slc h v) Source # | |||||
Defined in ChartParser type Rep (VChart tr slc h v) = D1 ('MetaData "VChart" "ChartParser" "protovoices-0.1.0.0-BDEUxFN8Fm0COc6pAhx3U0" 'False) (C1 ('MetaCons "VChart" 'PrefixI 'True) ((S1 ('MetaSel ('Just "vcNextId") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: (S1 ('MetaSel ('Just "vcIDs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (HashMap (Int, Int) Int)) :*: S1 ('MetaSel ('Just "vcByLength") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (IntMap [Vert tr slc h v])))) :*: (S1 ('MetaSel ('Just "vcByLengthLeft") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (IntMap (Set (Slice slc, Slice slc, h)))) :*: (S1 ('MetaSel ('Just "vcByLeftChild") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (HashMap (Int, Int) (Set (Slice slc, h)))) :*: S1 ('MetaSel ('Just "vcByRightChild") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (HashMap (Int, Int) [Vert tr slc h v])))))) | |||||
Constraint Aliases
type Parsable tr slc h v = (Normal tr, Normal slc, Normal h, Normal' v) Source #
A summary constraint for transitions, slices, hori-operations, and semiring values