|
Packit |
2b3545 |
/* Copyright (C) 1995 Bjoern Beutel.
|
|
Packit |
2b3545 |
* 2009 Harri Pitkänen <hatapitk@iki.fi>
|
|
Packit |
2b3545 |
*
|
|
Packit |
2b3545 |
* This program is free software; you can redistribute it and/or
|
|
Packit |
2b3545 |
* modify it under the terms of the GNU General Public License
|
|
Packit |
2b3545 |
* as published by the Free Software Foundation; either version 2
|
|
Packit |
2b3545 |
* of the License, or (at your option) any later version.
|
|
Packit |
2b3545 |
*
|
|
Packit |
2b3545 |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
2b3545 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
2b3545 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
2b3545 |
* GNU General Public License for more details.
|
|
Packit |
2b3545 |
*
|
|
Packit |
2b3545 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
2b3545 |
* along with this program; if not, write to the Free Software
|
|
Packit |
2b3545 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
Packit |
2b3545 |
*********************************************************************************/
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
/* Description. =============================================================*/
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
/* This module contains the Malaga rule interpreter. */
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
#ifndef LIBVOIKKO_MORPHOLOGY_MALAGA_RULES_HPP
|
|
Packit |
2b3545 |
#define LIBVOIKKO_MORPHOLOGY_MALAGA_RULES_HPP
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
#include "morphology/malaga/rule_type.hpp"
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
namespace libvoikko { namespace morphology { namespace malaga {
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
class MalagaState;
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
/* Types. ===================================================================*/
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
typedef struct
|
|
Packit |
2b3545 |
/* Contains a rule system of a compiled rule file.
|
|
Packit |
2b3545 |
* A "..._count" or "..._size" variable contains the number of elements
|
|
Packit |
2b3545 |
* in the following table. */
|
|
Packit |
2b3545 |
{
|
|
Packit |
2b3545 |
int_t initial_rule_set; /* Rules index of the initial rule set. */
|
|
Packit |
2b3545 |
int_t initial_feat; /* Values index of initial feature structure. */
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
int_t pruning_rule; /* Number of pruning_rule or -1. */
|
|
Packit |
2b3545 |
int_t output_filter; /* Number of output filter rule or -1. */
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
rule_t *rules; /* Name and code of every rule. */
|
|
Packit |
2b3545 |
int_t rule_count;
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
int_t *rule_sets; /* A collection of lists. Each list is a series of rules,
|
|
Packit |
2b3545 |
* followed by -1. A list may be subdivided into sublists,
|
|
Packit |
2b3545 |
* which are separated by -2. The rules of a sublist are
|
|
Packit |
2b3545 |
* executed if none of the rules of the preceding sublist
|
|
Packit |
2b3545 |
* has been successful. */
|
|
Packit |
2b3545 |
int_t rule_sets_size;
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
instr_t *instrs; /* The actual rule instructions. */
|
|
Packit |
2b3545 |
int_t instr_count;
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
cell_t *values; /* All constant Malaga values. */
|
|
Packit |
2b3545 |
int_t values_size;
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
char_t *strings; /* Names of files, variables, rules, patterns. */
|
|
Packit |
2b3545 |
int_t strings_size;
|
|
Packit |
2b3545 |
} rule_sys_t;
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
/* Variables. ===============================================================*/
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
/* Functions. ===============================================================*/
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
extern bool execute_rule(rule_sys_t *rule_sys, int_t rule_number, MalagaState * malagaState);
|
|
Packit |
2b3545 |
/* Execute rule RULE_NUMBER in the rule system RULE_SYS.
|
|
Packit |
2b3545 |
* Any parameters must be on the value stack.
|
|
Packit |
2b3545 |
* Returns true if executed rule was successful */
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
extern rule_sys_t *read_rule_sys( string_t file_name );
|
|
Packit |
2b3545 |
/* Read rule system from file FILE_NAME.
|
|
Packit |
2b3545 |
* A symbol file must have already been loaded. */
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
extern void free_rule_sys( rule_sys_t **rule_sys );
|
|
Packit |
2b3545 |
/* Free all memory used by *RULE_SYS. */
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
}}}
|
|
Packit |
2b3545 |
|
|
Packit |
2b3545 |
#endif
|