Safe Haskell | Safe-Infered |
---|
This is the interface between the front and backends of the generator. The GUI and the console interface both talk to this module, and in turn, this module talks to the input file parsers and the surface realisation engine.
- data ProgState = ProgState {}
- type ProgStateRef = IORef ProgState
- emptyProgState :: Params -> ProgState
- type LexicalSelector = Macros -> Lexicon -> Sem -> IO LexicalSelection
- runGeni :: ProgStateRef -> SemInput -> Builder st it Params -> IO (GeniResults, st)
- data GeniResults = GeniResults {
- grResults :: [GeniResult]
- grGlobalWarnings :: [Text]
- grStatistics :: Statistics
- data GeniResult
- isSuccess :: GeniResult -> Bool
- data GeniError = GeniError [Text]
- data GeniSuccess = GeniSuccess {}
- data GeniLexSel = GeniLexSel {}
- data ResultType
- initGeni :: ProgStateRef -> SemInput -> IO (Input, GeniWarnings)
- extractResults :: ProgStateRef -> Builder st it Params -> st -> IO [GeniResult]
- lemmaSentenceString :: GeniSuccess -> Text
- prettyResult :: ProgState -> GeniSuccess -> Text
- showRealisations :: [String] -> String
- histogram :: Ord a => [a] -> Map a Int
- getTraces :: ProgState -> Text -> [Text]
- loadEverything :: ProgStateRef -> IO ()
- class Loadable x where
- lParse :: FilePath -> String -> Either ParseError x
- lSet :: x -> ProgState -> ProgState
- lSummarise :: x -> String
- loadLexicon :: ProgStateRef -> IO Lexicon
- loadGeniMacros :: ProgStateRef -> IO Macros
- loadTestSuite :: ProgStateRef -> IO [TestCase]
- parseSemInput :: String -> Either ParseError SemInput
- loadRanking :: ProgStateRef -> IO ()
- data BadInputException = BadInputException String ParseError
- loadFromString :: Loadable a => ProgStateRef -> String -> String -> IO a
Main interface
Program state and configuration
The program state consists of its configuration options and abstract, cleaned up representations of all the data it's had to load into memory (tree schemata files, lexicon files, etc). The intention is for the state to stay static until the next time something triggers some file loading.
ProgState | |
|
type ProgStateRef = IORef ProgStateSource
emptyProgState :: Params -> ProgStateSource
The program state when you start GenI for the very first time
type LexicalSelector = Macros -> Lexicon -> Sem -> IO LexicalSelectionSource
See Configuration
if you want to use GenI with a custom
lexical selection function.
Running GenI
runGeni :: ProgStateRef -> SemInput -> Builder st it Params -> IO (GeniResults, st)Source
Entry point! (the most useful function to know here)
- Initialises the realiser (lexical selection, among other things),
- Runs the builder (the surface realisation engine proper)
- Unpacks the builder results
- Finalises the results (morphological generation)
In addition to the results, this returns a generator state. The latter is is mostly useful for debugging via the graphical interface. Note that we assumes that you have already loaded in your grammar and parsed your input semantics.
data GeniResults Source
GeniResults
is the outcome of running GenI on a single input semantics.
Each distinct result is returned as a single GeniResult
(NB: a single
result may expand into multiple strings through morphological
post-processing),
GeniResults | |
|
data GeniResult Source
isSuccess :: GeniResult -> BoolSource
data GeniSuccess Source
GeniSuccess | |
|
data ResultType Source
Helpers
initGeni :: ProgStateRef -> SemInput -> IO (Input, GeniWarnings)Source
initGeni
performs lexical selection and strips the input semantics of
any morpohological literals
extractResults :: ProgStateRef -> Builder st it Params -> st -> IO [GeniResult]Source
This is a helper to runGenI
. It's mainly useful if you are building
interactive GenI debugging tools.
Given a builder state,
- Unpacks the builder results
- Finalises the results (morphological generation)
lemmaSentenceString :: GeniSuccess -> TextSource
No morphology! Pretend the lemma string is a sentence
prettyResult :: ProgState -> GeniSuccess -> TextSource
showRealisations :: [String] -> StringSource
Show the sentences produced by the generator, in a relatively compact form
getTraces :: ProgState -> Text -> [Text]Source
getTraces
is most likely useful for grammars produced by a
metagrammar system. Given a tree name, we retrieve the `trace'
information from the grammar for all trees that have this name. We
assume the tree name was constructed by GenI; see the source code for
details.
Loading things
loadEverything :: ProgStateRef -> IO ()Source
We have one master function that loads all the files GenI is expected to use. This just calls the sub-loaders below, some of which are exported for use by the graphical interface. The master function also makes sure to complain intelligently if some of the required files are missing.
The file loading functions all work the same way: we load the file, and try to parse it. If this doesn't work, we just fail in IO, and GenI dies. If we succeed, we update the program state passed in as an IORef.
loadGeniMacros :: ProgStateRef -> IO MacrosSource
The macros are stored as a hashing function in the monad.
loadTestSuite :: ProgStateRef -> IO [TestCase]Source
loadRanking :: ProgStateRef -> IO ()Source
data BadInputException Source
:: Loadable a | |
=> ProgStateRef | |
-> String | description |
-> String | string to load |
-> IO a |
Load something from a string rather than a file