-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileToTrie.h
127 lines (106 loc) · 3.55 KB
/
FileToTrie.h
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
/*
* Copyright (C) 2010 University of Tartu
* Authors: Reina Käärik, Siim Orasmaa, Kristo Tammeoja, Jaak Vilo
* Contact: siim . orasmaa {at} ut . ee
*
* This file is part of Generalized Edit Distance Tool.
*
* Generalized Edit Distance Tool is free software: you can redistribute
* it and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Generalized Edit Distance Tool is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Generalized Edit Distance Tool.
* If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef FILETOTRIE_H
#define FILETOTRIE_H
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <errno.h>
#include "Trie.h"
#include "List.h"
#include <math.h>
#include "ARTrie.h"
#include <string.h>
#include <locale.h>
extern int debug;
extern double add;
extern double rep;
extern double rem;
extern IgnoreCaseListElement *ignoreCase;
extern int caseInsensitiveMode;
extern Trie *t;
extern ARTrie *addT;
extern ARTrie *remT;
extern Trie *traceT;
extern ARTrie *traceAddT;
extern ARTrie *traceRemT;
/**
* Reads file \a *filename into memory, using \c mmap() function. Returns
* pointer to the memory-mapped file, which is read-only. Any errors on
* reading will cause the program to abort.
*/
char *readFile(char *filename);
/**
* Reads a string snippet ( at position \a i to \a j ) from \a *data and
* converts into a double value. Returns found double.
*/
double findValue(char *data, int i, int j);
/**
* Reads transformations from file content \a *data and builds tries \a *t,
* \a *addT and \a *remT. If the file also specifies weights for default
* edit operations \a add, \a rep and \a rem, these weights will also be
* set.
* At the end of work, the memory under \a *data is released via method
* \c munmap().
*/
int trieFromFile(char *data);
/**
* Reads 'ignore case' transformations from file content \a *data and
* builds tries \a ignoreCase list.
* At the end of work, the memory under \a *data is released via method
* \c munmap().
*/
int ignoreCaseListFromFile(char *data);
/**
* Normalizes a case of a single character via transforming it using
* a transformation from \a ignoreCase list. More precisely: if the
* input char matches one of the left side chars in \a ignoreCase
* list, corresponding right side char from the list is returned;
* if no match is found, returns the input character.
* Only the first match is returned, as multiple matches are not
* expected.
*/
wchar_t makeToIgnoreCase(wchar_t s);
/**
* Makes \a *string case insensitive via transforming it with
* \a makeToIgnoreCase() method. Transformation is applied to
* a substring (0, \a len - 1).
*/
wchar_t *makeStringToIgnoreCase(wchar_t *string, int len);
/**
* Transforms given wchar string \a *str into multibyte char string.
*/
char *wcharToLocale(wchar_t *str);
/**
* Transforms given multibyte char string \a *str into wchar string.
*/
wchar_t *localeToWchar(char *str);
/**
* Returns a new string that is a reversed version of given string \a *str .
*/
wchar_t *reverseWchar(wchar_t *str, int strLen);
#endif