summaryrefslogtreecommitdiff
path: root/contrib/tsearch2/ispell/spell.h
blob: 50a5947680e7cda064c08a659e7b5b23909c9179 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef __SPELL_H__
#define __SPELL_H__

#include "c.h"

#include <sys/types.h>

#include "regex/regex.h"

#include "regis.h"
#include "dict.h"

struct SPNode;


typedef struct
{
	uint32
				val:8,
				isword:1,
				compoundallow:1,
				affix:22;
	struct SPNode *node;
}	SPNodeData;

typedef struct SPNode
{
	uint32		length;
	SPNodeData	data[1];
}	SPNode;

#define SPNHRDSZ	(sizeof(uint32))


typedef struct spell_struct
{
	union
	{
		char		flag[16];
		struct
		{
			int			affix;
			int			len;
		}			d;
	}			p;
	char		word[1];
}	SPELL;

#define SPELLHDRSZ	(offsetof(SPELL, word))

typedef struct aff_struct
{
	uint32
				flag:8,
				type:2,
				compile:1,
				flagflags:3,
				issimple:1,
				isregis:1,
				unused:1,
				replen:16;
	char	   *mask;
	char	   *find;
	char	   *repl;
	union
	{
		regex_t		regex;
		Regis		regis;
	}			reg;
}	AFFIX;

#define FF_CROSSPRODUCT		0x01
#define FF_COMPOUNDWORD		0x02
#define FF_COMPOUNDONLYAFX		0x04
#define FF_SUFFIX				2
#define FF_PREFIX				1

struct AffixNode;

typedef struct
{
	uint32
				val:8,
				naff:24;
	AFFIX	  **aff;
	struct AffixNode *node;
}	AffixNodeData;

typedef struct AffixNode
{
	uint32		isvoid:1,
				length:31;
	AffixNodeData data[1];
}	AffixNode;

#define ANHRDSZ		   (sizeof(uint32))

typedef struct
{
	char	   *affix;
	int			len;
}	CMPDAffix;

typedef struct
{
	int			maffixes;
	int			naffixes;
	AFFIX	   *Affix;
	char		compoundcontrol;

	int			nspell;
	int			mspell;
	SPELL	  **Spell;

	AffixNode  *Suffix;
	AffixNode  *Prefix;

	SPNode	   *Dictionary;
	char	  **AffixData;
	CMPDAffix  *CompoundAffix;

}	IspellDict;

TSLexeme   *NINormalizeWord(IspellDict * Conf, char *word);
int			NIImportAffixes(IspellDict * Conf, const char *filename);
int			NIImportOOAffixes(IspellDict * Conf, const char *filename);
int			NIImportDictionary(IspellDict * Conf, const char *filename);

int			NIAddSpell(IspellDict * Conf, const char *word, const char *flag);
int			NIAddAffix(IspellDict * Conf, int flag, char flagflags, const char *mask, const char *find, const char *repl, int type);
void		NISortDictionary(IspellDict * Conf);
void		NISortAffixes(IspellDict * Conf);
void		NIFree(IspellDict * Conf);

#endif