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

Safe HaskellSafe-Infered

NLP.GenI.Tag

Description

This module provides basic datatypes specific to Tree Adjoining Grammar (TAG) elementary trees and some low-level operations.

Synopsis

Documentation

type Tags = Map String [TagElem]

An anchored grammar. The grammar associates a set of semantic predicates to a list of trees each.

class TagItem t where

TagItem is a generalisation of TagElem.

Methods

tgIdName :: t -> Text

tgIdNum :: t -> Integer

tgSemantics :: t -> Sem

tgTree :: t -> Tree (GNode GeniVal)

Instances

addToTags :: Tags -> String -> TagElem -> Tags

addTags tags key elem adds elem to the the list of elements associated to the key

tagLeaves :: TagElem -> [(NodeName, UninflectedDisjunction)]

Normally, extracting the sentences from a TAG tree would just consist of reading its leaves. But if you want the generator to return inflected forms instead of just lemmas, you also need to return the relevant features for each leaf. In TAG, or at least our use of it, the features come from the *pre-terminal* nodes, that is, not the leaves themselves but their parents. Another bit of trickiness: because of atomic disjunction, leaves might have more than one value, so we can't just return a String lemma but a list of String, one for each possibility.

getLexeme :: GNode GeniVal -> [Text]

Try in order: lexeme, lexeme attributes, node name

setTidnums :: [TagElem] -> [TagElem]

Assigns a unique id to each element of this list, that is, an integer between 1 and the size of the list.

plugTree :: Tree NodeName -> NodeName -> Tree NodeName -> Tree NodeName

Plug the first tree into the second tree at the specified node. Anything below the second node is silently discarded. We assume the trees are pluggable; it is treated as a bug if they are not!

spliceTree

Arguments

:: NodeName

foot node of the aux tree

-> Tree NodeName

aux tree

-> NodeName

place to adjoin in target tree

-> Tree NodeName

target tree

-> Tree NodeName 

Given two trees auxt and t, splice the tree auxt into t via the TAG adjunction rule.

mapBySem :: TagItem t => [t] -> Map (Literal GeniVal) [t]

Sorts trees into a Map.Map organised by the first literal of their semantics. This is useful in at least three places: the polarity optimisation, the gui display code, and code for measuring the efficiency of GenI. Note: trees with a null semantics are filed under an empty predicate, if any.

collect :: Collectable a => a -> Map CollectedVar Int -> Map CollectedVar Int

collect x m increments our count for any variables in x (adds not-yet-seen variables as needed)

detectSites :: Tree (GNode GeniVal) -> ([NodeName], [NodeName], [NodeName])

Given a tree(GNode) returns a list of substitution or adjunction nodes, as well as remaining nodes with a null adjunction constraint.