GenI-0.23.20130212: A natural language generator (specifically, an FB-LTAG surface realiser)

Safe HaskellSafe-Infered

NLP.GenI.Semantics

Contents

Description

We use a flat semantics in GenI (bag of literals).

Synopsis

Documentation

data Literal gv

A single semantic literal containing its handle, predicate, and arguments

This can be paramaterised on the kinds of variables it uses, for example, GeniVal for a semantics that you might still want to do unification on or Text if it's supposed to be ground.

Constructors

Literal 

Fields

lHandle :: gv

the handle can be seen as a special kind of argument; stored separately

lPredicate :: gv
 
lArgs :: [gv]
 

type Sem = [Literal GeniVal]

A semantics is just a set of literals.

type LitConstr = (Literal GeniVal, [Text])

A literal and any constraints associated with it (semantic input)

type SemInput = (Sem, Flist GeniVal, [LitConstr])

Semantics, index constraints, literal constraints

The intention here is that for (sem, icons, lcons) all (elem sem) lcons

emptyLiteral :: Literal GeniVal

An empty literal, not sure you should really be using this

Utility functions

removeConstraints :: SemInput -> SemInput

Strip any index or literal constraints from an input. Use with care.

sortSem :: Ord a => [Literal a] -> [Literal a]

Default sorting for a semantics

compareOnLiteral :: Ord a => Literal a -> Literal a -> Ordering

Default comparison for a literal

sortByAmbiguity :: Sem -> Sem

Sort primarily putting the ones with the most constants first and secondarily by the number of instances a predicate occurs (if plain string; atomic disjunction/vars treated as infinite)

class HasConstants a where

Anything that we would want to count the number constants in (as opposed to variables)

Methods

constants :: a -> Int

Number of constants

displaySemInput :: ([LitConstr] -> Text) -> SemInput -> Text

Helper for displaying or pretty printing a semantic input

This gives you a bit of control over how each literal is displayed

isInternalHandle :: Text -> Bool

Is a handle generated by GenI. GenI lets you write literals without a handle; in these cases a unique handle is generated and hidden from the UI.

Subsumption

subsumeSem :: Sem -> Sem -> [(Sem, Subst)]

x subsumeSem y returns all the possible ways to unify x with some SUBSET of y so that x subsumes y. If x does NOT subsume y, we return the empty list.

subsumeSemH :: Sem -> Sem -> [(Sem, Subst)]

Helper for subsumeSem traversal

subsumeLiteral :: MonadUnify m => Literal GeniVal -> Literal GeniVal -> m (Literal GeniVal, Subst)

p1 subsumeLiteral p2 is the unification of p1 and p2 if both literals have the same arity, and the handles, predicates, and arguments in p1 all subsume their counterparts in p2

Unification

unifySem :: Sem -> Sem -> [(Sem, Subst)]

Return the list of minimal ways to unify two semantics, ie. where any literals that are not the product of a succesful unification really do not unify with anything else.

unifySemH :: Sem -> Sem -> [(Sem, Subst)]

Helper traversal for unifySem

unifyLiteral :: MonadUnify m => Literal GeniVal -> Literal GeniVal -> m (Literal GeniVal, Subst)

Two literals unify if they have the same arity, and their handles, predicates, and arguments also unify