grammaire
module).
More...Data Structures | |
struct | RulesLexicon |
Lexicon of syntactical rules. More... | |
struct | Grammar |
Grammar. More... | |
struct | FileId |
Unique file identifier. More... | |
Defines | |
#define | CONV_FILE_EXT "-conv" |
Postfix of the binary files that save the conversion table of Grammar::rules field. | |
#define | RULE_FILE_EXT "-rule" |
Postfix of the binary files that save the rules lexicon of Grammar::rules field. | |
#define | NUMBER_OF_RULES(grammar) lexiconGetSize((grammar)->rules->elements) |
Return the number of syntactic rules stored by a grammar. | |
#define | SLPLEX_FILE_ID "SLPLex binary grammar file v2.2 07/00" |
Grammar binary file format definition. | |
#define | INDIC_LEXICAL '"' |
Character that initiates a lexical term in a grammar textual file. | |
#define | DEFAULT_TOP_LEVEL_NT 512 |
Default value of the Grammar::top_level_nt field. | |
#define | GRAMMAR_FILE_EXT ".slpgram" |
File extension of the grammar binary file. | |
Functions | |
LexicalEntryIndex | grammarAddRule (Grammar *grammar, const char *left_part, StringArray *right_part, const Probability probability) |
Probability | grammarIncrementRuleFrequency (Grammar *grammar, LexicalEntryIndex *rule_index, const char *left_part, StringArray *right_part) |
int | grammarCreate (Grammar *grammar) |
void | grammarFree (Grammar *grammar) |
int | grammarSave (const Grammar *grammar, const char *lexicon_filename, const char *grammar_filename) |
int | grammarLoad (Grammar *grammar, const char *grammar_filename) |
int | grammarImport (Grammar *grammar, const char *filename, const gboolean probabilistic) |
void | grammarGetNTString (const Grammar *grammar, const LexicalEntryIndex nt_index, GString *output) |
LexicalEntryIndex | grammarGetNTInternalCode (const Grammar *grammar, const char *nt) |
void | grammarDump (const Grammar *grammar, int(*print)(const char *,...), const gboolean rules_number) |
int | grammarExport (const Grammar *grammar, const char *filename) |
LongArray * | grammarGetIndexFromRule (const Grammar *grammar, const char *left_part, const StringArray *right_part) |
void | grammarGetRuleFromIndex (const Grammar *grammar, const LexicalEntryIndex rule_index, char **left_part, StringArray *right_part, Probability *probability) |
grammaire
module).
SlpTK Library 0.6.0
<grammar.h>
Antonin Merçay (revision on 18.01.2005)
#define CONV_FILE_EXT "-conv" |
Postfix of the binary files that save the conversion table of Grammar::rules field.
#define RULE_FILE_EXT "-rule" |
Postfix of the binary files that save the rules lexicon of Grammar::rules field.
LexicalEntryIndex grammarAddRule | ( | Grammar * | grammar, | |
const char * | left_part, | |||
StringArray * | right_part, | |||
const Probability | probability | |||
) |
Add a new syntactic rule to the grammar
[in] | grammar | The destination grammar |
[in] | left_part | The left part of the rule |
[in] | right_part | The right part of the rule |
[in] | probability | The probability associated to the rule |
0
if operation fails)Ajoute_Regle
int grammarCreate | ( | Grammar * | grammar | ) |
Allow and initialize a new grammar
[out] | grammar | The grammar to instantiate |
Init_Grammaire
void grammarDump | ( | const Grammar * | grammar, | |
int(*)(const char *,...) | print, | |||
const gboolean | rules_number | |||
) |
Dump the list of syntactic rules stored by a grammar
[in] | grammar | The source grammar |
[in] | The print function used to dump | |
[in] | rules_number | Flag indicating whether rules numeration must be printed or not |
Liste_Grammaire
int grammarExport | ( | const Grammar * | grammar, | |
const char * | filename | |||
) |
Save the list of syntactic rules of a grammar in a human-readable ASCII file. The content of the destination file corresponds to a grammarDump() call.
[in] | grammar | The source grammar |
[in] | filename | The textual filename where to output |
Exporte_Grammaire
void grammarFree | ( | Grammar * | grammar | ) |
Free the memory allocated to a grammar
[in] | grammar | The grammar to free |
Libere_Grammaire
LongArray * grammarGetIndexFromRule | ( | const Grammar * | grammar, | |
const char * | left_part, | |||
const StringArray * | right_part | |||
) |
Look for all index (maybe several or none) of rules specified by given left and right parts
[in] | grammar | The source grammar |
[in] | left_part | The left part of the rule(s) to look for |
[in] | right_part | The right part of the rule(s) to look for |
Regle_vers_Numero
LexicalEntryIndex grammarGetNTInternalCode | ( | const Grammar * | grammar, | |
const char * | nt | |||
) |
Return the (internal) numeric value associated to a (surface) textual format non-terminal
[in] | grammar | The source grammar |
[in] | nt | The non-terminal (NT) to look for. If the NT is surrounded by a couple of INDIC_LEXICAL characters, the encapsulated string is considered as a vocabulary word and searched into the Grammar::words field. If the graphy is not found, an error is raised |
0
if not found)Convert_NT_char
void grammarGetNTString | ( | const Grammar * | grammar, | |
const LexicalEntryIndex | nt_index, | |||
GString * | output | |||
) |
Return the (external) textual value associated to a (internal) numeric format non-terminal using the following conventions:
0
) is not used;1
to Grammar::top_level_nt - 1
are pre-terminals (parts of speech of Grammar::words);nt_index
- 1
.
[in] | grammar | The source grammar |
[in] | nt_index | The intern (numeric) representation of the non-terminal to convert |
[out] | output | The string where to output |
ULONG_MAX
Convert_NT
void grammarGetRuleFromIndex | ( | const Grammar * | grammar, | |
const LexicalEntryIndex | rule_index, | |||
char ** | left_part, | |||
StringArray * | right_part, | |||
Probability * | probability | |||
) |
Extract the syntactic rule from its index
[in] | grammar | The source grammar |
[in] | rule_index | The index of the rule to extract |
[out] | left_part | The left part of the extracted rule |
[out] | right_part | The right part of the extracted rule |
[out] | probability | The probability of the extracted rule |
left_part
parameter is set to NULL
Numero_vers_Regle
int grammarImport | ( | Grammar * | grammar, | |
const char * | filename, | |||
const gboolean | probabilistic | |||
) |
Load a grammar from the content of a human-readable ASCII file. For proper processing, it's mandatory that the first non-terminal met in the input file must be the top level NT.
[out] | grammar | The grammar where to import |
[in] | filename | The name of the textual file to import |
[in] | probabilistic | Set if the given textual file contains probabilities |
Importe_Grammaire
Probability grammarIncrementRuleFrequency | ( | Grammar * | grammar, | |
LexicalEntryIndex * | rule_index, | |||
const char * | left_part, | |||
StringArray * | right_part | |||
) |
Increment from one unity the probability field of a syntactic rule. The specified rule is added with a probability of 1
if it doesn't exist already in the grammar. When the rule insertion process is over, a lexiconNormalizeProba(grammar->rules->elements
) computes the right probability for each rule.
[in] | grammar | The destination grammar |
[in] | rule_index | The syntactic rule index
|
[in] | left_part | The left part of the rule |
[in] | right_part | The right part of the rule |
Ajoute_Une_Occurence_Regle
int grammarLoad | ( | Grammar * | grammar, | |
const char * | grammar_filename | |||
) |
Load a grammar from a set of binary files. See grammarSave for more informations on the required files.
[out] | grammar | The grammar where to load |
[in] | grammar_filename | The filename of the grammar header file |
Read_Grammaire
int grammarSave | ( | const Grammar * | grammar, | |
const char * | lexicon_filename, | |||
const char * | grammar_filename | |||
) |
Save a grammar in a set of binary files. The operation generates:
grammar_filename
+ GRAMMAR_FILE_EXT that stores the internal (numeric) value of the top level non-terminal, the binary filename of the word lexicon, the names of the binary files that store the rules lexicon and the conversion table;grammar_filename
+ RULE_FILE_EXT and that store the rule lexicon;grammar_filename
+ CONV_FILE_EXT and that store the conversion table.
[in] | grammar | The grammar to save |
[in] | lexicon_filename | The binary filename of the word lexicon associated to the grammar |
[in] | grammar_filename | The base filename of the saved grammar |
Write_Grammaire