lowmem.C
3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*******************************************************************/
/* */
/* FILE lowmem.C */
/* MODULE lowmem */
/* PROGRAM SFST */
/* AUTHOR Helmut Schmid, IMS, University of Stuttgart */
/* */
/* PURPOSE Code needed for analysing data */
/* */
/*******************************************************************/
#include <stdio.h>
#include "lowmem.h"
using std::vector;
const int BUFFER_SIZE=1000;
/*******************************************************************/
/* */
/* LowMemTransducer::analyze */
/* */
/*******************************************************************/
void LowMemTransducer::analyze( const LMNode &node,
vector<Character> &input, size_t ipos,
Analysis &ca, vector<Analysis> &analyses )
{
if (node.finalp && ipos == input.size())
// store the new analysis
analyses.push_back(ca);
// follow the transitions
for( int i=0; i<node.number_of_arcs; i++ ) {
ca.push_back(node.arc[i].label);
LMNode target(node.arc[i].tnodepos, lmafile);
if (node.arc[i].label.upper_char() == Label::epsilon)
analyze(target, input, ipos, ca, analyses);
else if (ipos < input.size() &&
node.arc[i].label.upper_char() == (Character)input[ipos])
analyze(target, input, ipos+1, ca, analyses);
ca.pop_back();
}
}
/*******************************************************************/
/* */
/* LowMemTransducer::analyze_string */
/* */
/*******************************************************************/
void LowMemTransducer::analyze_string(char *string, vector<Analysis> &analyses)
{
vector<Character> input;
alphabet.string2symseq( string, input );
Analysis ca;
analyses.clear();
analyze(*rootnode, input, 0, ca, analyses);
if (simplest_only)
alphabet.disambiguate( analyses );
}
/*******************************************************************/
/* */
/* LowMemTransducer::LowMemTransducer */
/* */
/*******************************************************************/
LowMemTransducer::LowMemTransducer( FILE *file )
{
simplest_only = false;
lmafile = file;
if (fgetc(file) != 'l')
throw "Error: wrong file format (not a lowmem transducer)\n";
alphabet.read(file);
rootnode = new LMNode(ftell(file), lmafile);
}