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

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

Parsing Interface

parse Source #

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 Start and Stop)

-> 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

data Slice slc Source #

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

Instances details
Generic (Slice slc) Source # 
Instance details

Defined in ChartParser

Associated Types

type Rep (Slice slc) :: Type -> Type #

Methods

from :: Slice slc -> Rep (Slice slc) x #

to :: Rep (Slice slc) x -> Slice slc #

Show slc => Show (Slice slc) Source # 
Instance details

Defined in ChartParser

Methods

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

show :: Slice slc -> String #

showList :: [Slice slc] -> ShowS #

NFData slc => NFData (Slice slc) Source # 
Instance details

Defined in ChartParser

Methods

rnf :: Slice slc -> () #

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

Defined in ChartParser

Methods

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

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

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

Defined in ChartParser

Methods

compare :: Slice slc -> Slice slc -> Ordering #

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

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

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

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

max :: Slice slc -> Slice slc -> Slice slc #

min :: Slice slc -> Slice slc -> Slice slc #

Eq slc => Hashable (Slice slc) Source # 
Instance details

Defined in ChartParser

Methods

hashWithSalt :: Int -> Slice slc -> Int #

hash :: Slice slc -> Int #

type Rep (Slice slc) Source # 
Instance details

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

Instances details
Generic (Transition tr slc) Source # 
Instance details

Defined in ChartParser

Associated Types

type Rep (Transition tr slc) :: Type -> Type #

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 # 
Instance details

Defined in ChartParser

Methods

showsPrec :: Int -> Transition e a -> ShowS #

show :: Transition e a -> String #

showList :: [Transition e a] -> ShowS #

(NFData slc, NFData tr) => NFData (Transition tr slc) Source # 
Instance details

Defined in ChartParser

Methods

rnf :: Transition tr slc -> () #

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

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 # 
Instance details

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 # 
Instance details

Defined in ChartParser

Methods

hashWithSalt :: Int -> Transition tr slc -> Int #

hash :: Transition tr slc -> Int #

type Rep (Transition tr slc) Source # 
Instance details

Defined in ChartParser

type Rep (Transition tr slc) = D1 ('MetaData "Transition" "ChartParser" "proto-voice-model-0.1.0.0-IpbUkUcWDicKjQK7SlZCoP" '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.

data Item i v Source #

A parsing item. Combines an intermediate value (e.g. a transition) with a semiring score.

Instances

Instances details
Generic (Item i v) Source # 
Instance details

Defined in ChartParser

Associated Types

type Rep (Item i v) :: Type -> Type #

Methods

from :: Item i v -> Rep (Item i v) x #

to :: Rep (Item i v) x -> Item i v #

(Show i, Show v) => Show (Item i v) Source # 
Instance details

Defined in ChartParser

Methods

showsPrec :: Int -> Item i v -> ShowS #

show :: Item i v -> String #

showList :: [Item i v] -> ShowS #

(NFData i, NFData v) => NFData (Item i v) Source # 
Instance details

Defined in ChartParser

Methods

rnf :: Item i v -> () #

type Rep (Item i v) Source # 
Instance details

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).

data TChart tr slc v Source #

A transition chart. Stores intermediate transition items redundantly under several indices:

  • by surface length
  • by left slice
  • by right slice

Instances

Instances details
Generic (TChart tr slc v) Source # 
Instance details

Defined in ChartParser

Associated Types

type Rep (TChart tr slc v) :: Type -> Type #

Methods

from :: TChart tr slc v -> Rep (TChart tr slc v) x #

to :: Rep (TChart tr slc v) x -> TChart tr slc v #

(Show slc, Show tr) => Show (TChart tr slc v) Source # 
Instance details

Defined in ChartParser

Methods

showsPrec :: Int -> TChart tr slc v -> ShowS #

show :: TChart tr slc v -> String #

showList :: [TChart tr slc v] -> ShowS #

(NFData slc, NFData tr, NFData v) => NFData (TChart tr slc v) Source # 
Instance details

Defined in ChartParser

Methods

rnf :: TChart tr slc v -> () #

type Rep (TChart tr slc v) Source # 
Instance details

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

data Vert tr slc v Source #

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

Instances details
Generic (Vert tr slc v) Source # 
Instance details

Defined in ChartParser

Associated Types

type Rep (Vert tr slc v) :: Type -> Type #

Methods

from :: Vert tr slc v -> Rep (Vert tr slc v) x #

to :: Rep (Vert tr slc v) x -> Vert tr slc v #

(Show e, Show a, Show v) => Show (Vert e a v) Source # 
Instance details

Defined in ChartParser

Methods

showsPrec :: Int -> Vert e a v -> ShowS #

show :: Vert e a v -> String #

showList :: [Vert e a v] -> ShowS #

(NFData slc, NFData v, NFData tr) => NFData (Vert tr slc v) Source # 
Instance details

Defined in ChartParser

Methods

rnf :: Vert tr slc v -> () #

type Rep (Vert tr slc v) Source # 
Instance details

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)))))

data VChart tr slc 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

Instances details
Generic (VChart tr slc v) Source # 
Instance details

Defined in ChartParser

Associated Types

type Rep (VChart tr slc v) :: Type -> Type #

Methods

from :: VChart tr slc v -> Rep (VChart tr slc v) x #

to :: Rep (VChart tr slc v) x -> VChart tr slc v #

(Show e, Show a, Show v) => Show (VChart e a v) Source # 
Instance details

Defined in ChartParser

Methods

showsPrec :: Int -> VChart e a v -> ShowS #

show :: VChart e a v -> String #

showList :: [VChart e a v] -> ShowS #

(NFData slc, NFData v, NFData tr) => NFData (VChart tr slc v) Source # 
Instance details

Defined in ChartParser

Methods

rnf :: VChart tr slc v -> () #

type Rep (VChart tr slc v) Source # 
Instance details

Defined in ChartParser

type Rep (VChart tr slc v) = D1 ('MetaData "VChart" "ChartParser" "proto-voice-model-0.1.0.0-IpbUkUcWDicKjQK7SlZCoP" '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 v])))) :*: (S1 ('MetaSel ('Just "vcByLengthLeft") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (IntMap (Set (Slice slc, Slice slc)))) :*: (S1 ('MetaSel ('Just "vcByLeftChild") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (HashMap (Int, Int) (Set (Slice slc)))) :*: S1 ('MetaSel ('Just "vcByRightChild") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (HashMap (Int, Int) [Vert tr slc v]))))))

vcGetByLength Source #

Arguments

:: VChart tr slc v

the chart

-> Int

surface length of a middle transition

-> [Vert tr slc v]

all corresponding Vert objects

Returns all Vert objects in the VChart with the same length.

Constraint Aliases

type Parsable tr slc v = (Normal tr, Normal slc, Normal' v) Source #

A summary constraint for transitions, slices, and semiring values

type Normal x = (Eq x, Ord x, Show x, Hashable x, NFData x) Source #

An alias for common constraints on slices and transitions

type Normal' x = (Eq x, Show x, NFData x, Semiring x) Source #

An alias for common constraints on semiring values