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

Scoring.Deprecated.Flat

Description

This module is deprecated, use Scoring.FunTyped instead.

Semiring scores with "holes". Holes are used to express "partially applied" scores that occur when the score of a verticalization (unspread) is distributed to two parent edges. The full score of the operation is restored when the two parent edges are eventually combined again.

This module implements partial scores using lists, which is slow and not very elegant. The grammar combinators are partial and will fail if used incorrectly, indicating parser bugs.

Synopsis

The Score Type

data Score s i Source #

A partially applied score of type s. Comes in four variants, depending on whether the score is fully applied or needs to be combined on either or both sides. Values that need to be combined are lists that represent scores with holes. Each variant carries IDs of type i that determine which objects fit on either of its sides. Only score objects with matching IDs can be combined.

As a shorthand notation, we use a-b to indicate a value that depends on a on its left and on b on its right. If the value does not depend on anything on either side, we use (), i.e. ()-a stands for SLeft _ a and ()-() stands for SVal _.

Constructors

SVal !s

Carries a fully applied value

SRight !(LeftId i) ![Holes s]

The right part of a combination, expects an argument to its left. Implemented as a list of right elements

SLeft ![Holes s] !(RightId i)

The left part of a combination, expects an argument to its right. Implemented as a list of right elements

SBoth !(LeftId i) ![(Holes s, Holes s)] !(RightId i)

A combination of SLeft and SRight that expects arguments on both sides. Implemented as a list of right elements on the left and a list of left elements to the right

Instances

Instances details
Generic (Score s i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

Associated Types

type Rep (Score s i) :: Type -> Type #

Methods

from :: Score s i -> Rep (Score s i) x #

to :: Rep (Score s i) x -> Score s i #

(Show i, Show s) => Show (Score s i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

Methods

showsPrec :: Int -> Score s i -> ShowS #

show :: Score s i -> String #

showList :: [Score s i] -> ShowS #

(NFData s, NFData i) => NFData (Score s i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

Methods

rnf :: Score s i -> () #

type Rep (Score s i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

type Holes s = [s] Source #

A type alias for the holes in a Score.

val :: s -> Score s i Source #

Creates a simple value score of type ()-().

newtype LeftId i Source #

Newtype for the left ID of a partial score.

Constructors

LeftId i 

Instances

Instances details
Generic (LeftId i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

Associated Types

type Rep (LeftId i) :: Type -> Type #

Methods

from :: LeftId i -> Rep (LeftId i) x #

to :: Rep (LeftId i) x -> LeftId i #

Show i => Show (LeftId i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

Methods

showsPrec :: Int -> LeftId i -> ShowS #

show :: LeftId i -> String #

showList :: [LeftId i] -> ShowS #

NFData i => NFData (LeftId i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

Methods

rnf :: LeftId i -> () #

Eq i => Eq (LeftId i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

Methods

(==) :: LeftId i -> LeftId i -> Bool #

(/=) :: LeftId i -> LeftId i -> Bool #

Ord i => Ord (LeftId i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

Methods

compare :: LeftId i -> LeftId i -> Ordering #

(<) :: LeftId i -> LeftId i -> Bool #

(<=) :: LeftId i -> LeftId i -> Bool #

(>) :: LeftId i -> LeftId i -> Bool #

(>=) :: LeftId i -> LeftId i -> Bool #

max :: LeftId i -> LeftId i -> LeftId i #

min :: LeftId i -> LeftId i -> LeftId i #

Hashable i => Hashable (LeftId i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

Methods

hashWithSalt :: Int -> LeftId i -> Int #

hash :: LeftId i -> Int #

type Rep (LeftId i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

type Rep (LeftId i) = D1 ('MetaData "LeftId" "Scoring.Deprecated.Flat" "proto-voice-model-0.1.0.0-IpbUkUcWDicKjQK7SlZCoP" 'True) (C1 ('MetaCons "LeftId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 i)))

newtype RightId i Source #

Newtype for the right ID of a partial score.

Constructors

RightId i 

Instances

Instances details
Generic (RightId i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

Associated Types

type Rep (RightId i) :: Type -> Type #

Methods

from :: RightId i -> Rep (RightId i) x #

to :: Rep (RightId i) x -> RightId i #

Show i => Show (RightId i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

Methods

showsPrec :: Int -> RightId i -> ShowS #

show :: RightId i -> String #

showList :: [RightId i] -> ShowS #

NFData i => NFData (RightId i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

Methods

rnf :: RightId i -> () #

Eq i => Eq (RightId i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

Methods

(==) :: RightId i -> RightId i -> Bool #

(/=) :: RightId i -> RightId i -> Bool #

Ord i => Ord (RightId i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

Methods

compare :: RightId i -> RightId i -> Ordering #

(<) :: RightId i -> RightId i -> Bool #

(<=) :: RightId i -> RightId i -> Bool #

(>) :: RightId i -> RightId i -> Bool #

(>=) :: RightId i -> RightId i -> Bool #

max :: RightId i -> RightId i -> RightId i #

min :: RightId i -> RightId i -> RightId i #

Hashable i => Hashable (RightId i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

Methods

hashWithSalt :: Int -> RightId i -> Int #

hash :: RightId i -> Int #

type Rep (RightId i) Source # 
Instance details

Defined in Scoring.Deprecated.Flat

type Rep (RightId i) = D1 ('MetaData "RightId" "Scoring.Deprecated.Flat" "proto-voice-model-0.1.0.0-IpbUkUcWDicKjQK7SlZCoP" 'True) (C1 ('MetaCons "RightId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 i)))

leftSide :: Score s i -> Maybe (LeftId i) Source #

Returns the ID on the left side of an Score, or Nothing for SVal and SLeft.

a-b -> a

rightSide :: Score s i -> Maybe (RightId i) Source #

Returns the ID on the right side of an Score, or Nothing for SVal and SRight.

a-b -> b

showScore :: (Show s, Show i) => Score s i -> String Source #

Returns a string representation of a Score (more compact than it's Show instance).

Semiring operations

Semiring operations can be lifted to partial scores, but since it is not guaranteed that their arguments can be combined, they are partial.

times :: (Semiring s, Eq i, Show i) => Score s i -> Score s i -> Maybe (Score s i) Source #

Combines two partially applied Scores by applying them to each other and/or multiplying the underlying semiring values. Shapes and IDs at the adjacent sides must match, otherwise Nothing is returned.

a-b × b-c -> a-c

plus :: (Semiring s, Eq i) => Score s i -> Score s i -> Maybe (Score s i) Source #

Adds two partially applied Scores by adding their underlying (or resulting) semiring values. This operation is only admitted if the two scores are of the same shape and have matching IDs. Otherwise, Nothing is returned.

a-b + a-b -> a-b

grammatical combinators

The following combinators correspond to the unsplit and unspread operations of the path-graph grammar.

unsplitScores Source #

Arguments

:: (Semiring s, Eq i, Show i, Show s) 
=> s

The score of the split operation.

-> Score s i

The Score of the left child edge.

-> Score s i

The Score of the right child edge.

-> Score s i

The Score of the parent edge, if it exists.

Combines the Scores of two edges with a split operation into the score of the parent edge. This is expected to be called on compatible scores and will throw an error otherwise to indicate parser bugs.

a-b   b-c
--------- unsplit
   a-c

unspreadScoresLeft Source #

Arguments

:: (Eq i, Show i, Semiring s, Show s) 
=> i

The new ID that marks both parent edges

-> Score s i

The Score of the left child edge.

-> Score s i

The Score of the left parent edge, if it exists.

Creates the Score of a left parent edge from a left child edge of an unspread. Will throw an error if called on invalid input to indicate parser bugs.

unspreadScoresRight Source #

Arguments

:: (Eq i, Semiring s, Show i, Show s) 
=> i

The new ID that marks both parent edges.

-> s

The score of the spread operation.

-> Score s i

The Score of the middle child edge.

-> Score s i

The Score of the right child edge.

-> Score s i

The Score of the right parent edge, if it exists.

Creates the Score of a right parent edge from the middle and right child edges of an unspread and a spread operation.

addScores :: (Semiring s, Eq i) => Score s i -> Score s i -> Score s i Source #

Adds two Scores that are alternative derivations of the same transition. This is expected to be called on compatible scores and will throw an error otherwise to indicate parser bugs.

a-b   a-b
--------- add
   a-b

getScoreVal :: Score s i -> s Source #

Extracts the value from a fully applied Score. This function is intended to be used to extract the final score of the parser. If the score is not fully applied, throws an exception to indicate parser bugs.