Safe Haskell | Safe-Inferred |
---|---|
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,
split
ting transitions and spread
ing 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 v => (TChart tr slc v -> Either (VChart tr slc v) [Slice slc] -> Int -> IO ()) -> Eval tr tr' slc slc' v -> Path slc' tr' -> IO v
- parseSize :: Parsable tr slc v => Eval tr tr' slc slc' v -> Path slc' tr' -> IO v
- parseSilent :: Parsable tr slc v => Eval tr tr' slc slc' v -> Path slc' tr' -> IO v
- logSize :: TChart tr1 slc1 v1 -> Either (VChart tr2 slc2 v2) [Slice slc2] -> Int -> IO ()
- logTikz :: (Foldable t, Show slc, Show slc, Hashable tr, Eq slc) => TChart tr slc v -> Either (VChart tr slc v) (t (Slice slc)) -> 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 v
- data VChart tr slc v
- vcGetByLength :: VChart tr slc v -> Int -> [Vert tr slc v]
- type Parsable tr slc v = (Normal tr, Normal slc, 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 v | |
=> (TChart tr slc v -> Either (VChart tr slc v) [Slice slc] -> Int -> IO ()) | logging function |
-> Eval tr tr' slc slc' 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 v => Eval tr tr' slc slc' v -> Path slc' tr' -> IO v Source #
Parse a piece using the logSize
logging function.
parseSilent :: Parsable tr slc v => Eval tr tr' slc slc' v -> Path slc' tr' -> IO v Source #
Parse a piece without logging.
logSize :: TChart tr1 slc1 v1 -> Either (VChart tr2 slc2 v2) [Slice slc2] -> Int -> IO () Source #
A logging function that logs the sice of the charts at each level.
logTikz :: (Foldable t, Show slc, Show slc, Hashable tr, Eq slc) => TChart tr slc v -> Either (VChart tr slc v) (t (Slice slc)) -> 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
Generic (Slice slc) Source # | |
Show slc => Show (Slice slc) Source # | |
NFData slc => NFData (Slice slc) Source # | |
Defined in ChartParser | |
Eq slc => Eq (Slice slc) Source # | |
Ord slc => Ord (Slice slc) Source # | |
Eq slc => Hashable (Slice slc) Source # | |
Defined in ChartParser | |
type Rep (Slice slc) Source # | |
Defined in ChartParser type Rep (Slice slc) = D1 ('MetaData "Slice" "ChartParser" "proto-voice-model-0.1.0.0-IpbUkUcWDicKjQK7SlZCoP" 'False) (C1 ('MetaCons "Slice" 'PrefixI 'True) ((S1 ('MetaSel ('Just "sFirst") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "sContent") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (StartStop slc))) :*: (S1 ('MetaSel ('Just "sID") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "sLast") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)))) |
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
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
Generic (Item i v) Source # | |
(Show i, Show v) => Show (Item i v) Source # | |
(NFData i, NFData v) => NFData (Item i v) Source # | |
Defined in ChartParser | |
type Rep (Item i v) Source # | |
Defined in ChartParser type Rep (Item i v) = D1 ('MetaData "Item" "ChartParser" "proto-voice-model-0.1.0.0-IpbUkUcWDicKjQK7SlZCoP" '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
Generic (TChart tr slc v) Source # | |
(Show slc, Show tr) => Show (TChart tr slc v) Source # | |
(NFData slc, NFData tr, NFData v) => NFData (TChart tr slc v) Source # | |
Defined in ChartParser | |
type Rep (TChart tr slc v) Source # | |
Defined in ChartParser type Rep (TChart tr slc v) = D1 ('MetaData "TChart" "ChartParser" "proto-voice-model-0.1.0.0-IpbUkUcWDicKjQK7SlZCoP" '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
Generic (Vert tr slc v) Source # | |
(Show e, Show a, Show v) => Show (Vert e a v) Source # | |
(NFData slc, NFData v, NFData tr) => NFData (Vert tr slc v) Source # | |
Defined in ChartParser | |
type Rep (Vert tr slc v) Source # | |
Defined in ChartParser type Rep (Vert tr slc v) = D1 ('MetaData "Vert" "ChartParser" "proto-voice-model-0.1.0.0-IpbUkUcWDicKjQK7SlZCoP" 'False) (C1 ('MetaCons "Vert" 'PrefixI 'True) (S1 ('MetaSel ('Just "vTop") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Slice slc)) :*: (S1 ('MetaSel ('Just "vOp") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 v) :*: S1 ('MetaSel ('Just "vMiddle") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (TItem tr slc v))))) |
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
Constraint Aliases
type Parsable tr slc v = (Normal tr, Normal slc, Normal' v) Source #
A summary constraint for transitions, slices, and semiring values