-
Notifications
You must be signed in to change notification settings - Fork 7
/
divvunspell.h
157 lines (119 loc) · 4.16 KB
/
divvunspell.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#pragma once
#ifndef __APPLE__
#define _Nonnull
#define _Nullable
#endif
// Rust FFI required types
typedef uint8_t rust_bool_t;
typedef uintptr_t rust_usize_t;
typedef struct rust_slice_s {
void *_Nullable data;
uintptr_t len;
} rust_slice_t;
#if _WIN32
typedef wchar_t rust_path_t;
#else
typedef char rust_path_t;
#endif
// Rust error handling constructs
char*_Nullable divvunspell_err = NULL;
static void divvunspell_err_callback(const char *_Nonnull msg) {
size_t sz = strlen(msg) + 1;
divvunspell_err = (char*)calloc(1, sz);
memcpy(divvunspell_err, msg, sz);
}
static void divvunspell_err_print() {
if (divvunspell_err != NULL) {
printf("Err: %s\n", divvunspell_err);
}
}
static void divvunspell_err_free() {
if (divvunspell_err != NULL) {
free(divvunspell_err);
divvunspell_err = NULL;
}
}
#define ERR_CALLBACK void (*_Nonnull exception)(const char *_Nonnull)
struct CaseHandlingConfig {
float start_penalty;
float end_penalty;
float mid_penalty;
};
struct SpellerConfig {
rust_usize_t n_best;
float max_weight;
float beam;
struct CaseHandlingConfig case_handling;
rust_usize_t node_pool_size;
};
extern const void *_Nullable
divvun_thfst_chunked_box_speller_archive_open(const rust_path_t *_Nonnull path, ERR_CALLBACK);
extern const void *_Nullable
divvun_thfst_chunked_box_speller_archive_speller(const void *_Nonnull handle, ERR_CALLBACK);
extern rust_bool_t
divvun_thfst_chunked_box_speller_is_correct(const void *_Nonnull speller, const char *_Nonnull word, ERR_CALLBACK);
extern const rust_slice_t
divvun_thfst_chunked_box_speller_suggest(const void *_Nonnull speller, const char *_Nonnull word, ERR_CALLBACK);
extern const void *_Nullable
divvun_thfst_chunked_box_speller_suggest_with_config(
const void *_Nonnull speller,
const char *_Nonnull word,
struct SpellerConfig *_Nonnull config,
ERR_CALLBACK);
extern const void *_Nullable
divvun_thfst_box_speller_archive_open(const rust_path_t *_Nonnull path, ERR_CALLBACK);
extern const void *_Nullable
divvun_thfst_box_speller_archive_speller(const void *_Nonnull handle, ERR_CALLBACK);
extern rust_bool_t
divvun_thfst_box_speller_is_correct(const void *_Nonnull speller, const char *_Nonnull word, ERR_CALLBACK);
extern const rust_slice_t
divvun_thfst_box_speller_suggest(const void *_Nonnull speller, const char *_Nonnull word, ERR_CALLBACK);
extern const void *_Nullable
divvun_thfst_box_speller_suggest_with_config(
const void *_Nonnull speller,
const char *_Nonnull word,
struct SpellerConfig *_Nonnull config,
ERR_CALLBACK);
extern const void *_Nullable
divvun_hfst_zip_speller_archive_open(const rust_path_t *_Nonnull path, ERR_CALLBACK);
extern const void *_Nullable
divvun_hfst_zip_speller_archive_speller(const void *_Nonnull handle, ERR_CALLBACK);
extern const char *_Nullable
divvun_hfst_zip_speller_archive_locale(const void *_Nonnull handle, ERR_CALLBACK);
extern rust_bool_t
divvun_hfst_zip_speller_is_correct(const void *_Nonnull speller, const char *_Nonnull word, ERR_CALLBACK);
extern const rust_slice_t
divvun_hfst_zip_speller_suggest(const void *_Nonnull speller, const char *_Nonnull word, ERR_CALLBACK);
extern const void *_Nullable
divvun_hfst_zip_speller_suggest_with_config(
const void *_Nonnull speller,
const char *_Nonnull word,
struct SpellerConfig *_Nonnull config,
ERR_CALLBACK);
extern rust_usize_t
divvun_vec_suggestion_len(const rust_slice_t suggestions, ERR_CALLBACK);
extern const char *_Nullable
divvun_vec_suggestion_get_value(
const rust_slice_t suggestions,
rust_usize_t index,
ERR_CALLBACK);
extern void
divvun_string_free(const char *_Nullable value);
// TODO: this is temporary until a better tokenizer impl is written
extern void *_Nonnull
word_bound_indices(const char *_Nonnull utf8_string);
extern rust_bool_t
word_bound_indices_next(const void *_Nonnull handle, uint64_t *_Nonnull out_index, char *_Nonnull *_Nonnull out_string);
extern void
word_bound_indices_free(void *_Nonnull handle);
#ifdef __cplusplus
}
#endif