@delali/narsil-react-native 0.3.1-next.155 → 0.3.1-next.157
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +144 -0
- package/NarsilReactNative.podspec +2 -2
- package/android/CMakeLists.txt +1 -1
- package/cpp/HybridNarsilCoreAnalysis.cpp +277 -0
- package/cpp/HybridNarsilCoreImpl.hpp +43 -0
- package/cpp/HybridNarsilCoreKeyword.cpp +253 -0
- package/cpp/HybridNarsilCoreMath.cpp +47 -0
- package/cpp/core/include/narsil_analysis.h +86 -0
- package/cpp/core/include/narsil_core.h +1 -1
- package/cpp/core/include/narsil_keyword.h +110 -0
- package/cpp/core/include/narsil_math.h +36 -0
- package/cpp/core/src/analysis/analyse.c +281 -0
- package/cpp/core/src/analysis/analyser.h +49 -0
- package/cpp/core/src/analysis/languages.c +79 -0
- package/cpp/core/src/analysis/languages.h +42 -0
- package/cpp/core/src/analysis/normalise.c +242 -0
- package/cpp/core/src/analysis/normalise.h +28 -0
- package/cpp/core/src/analysis/split.c +183 -0
- package/cpp/core/src/analysis/split.h +27 -0
- package/cpp/core/src/analysis/stop_words.c +82 -0
- package/cpp/core/src/analysis/stop_words.h +19 -0
- package/cpp/core/src/analysis/term_cache.c +88 -0
- package/cpp/core/src/analysis/term_cache.h +36 -0
- package/cpp/core/src/analysis/text.c +161 -0
- package/cpp/core/src/analysis/text.h +45 -0
- package/cpp/core/src/analysis/transform.c +103 -0
- package/cpp/core/src/analysis/unicode.c +252 -0
- package/cpp/core/src/analysis/unicode.h +54 -0
- package/cpp/core/src/internal.h +4 -0
- package/cpp/core/src/keyword/pass.h +117 -0
- package/cpp/core/src/keyword/prune.c +324 -0
- package/cpp/core/src/keyword/request.c +179 -0
- package/cpp/core/src/keyword/rows.c +83 -0
- package/cpp/core/src/keyword/rows.h +18 -0
- package/cpp/core/src/keyword/score.c +257 -0
- package/cpp/core/src/keyword/score.h +17 -0
- package/cpp/core/src/keyword/scratch.c +226 -0
- package/cpp/core/src/keyword/scratch.h +55 -0
- package/cpp/core/src/keyword/select.c +155 -0
- package/cpp/core/src/keyword/select.h +17 -0
- package/cpp/core/src/languages/bulgarian_stemmer.c +114 -0
- package/cpp/core/src/languages/data/albanian.c +54 -0
- package/cpp/core/src/languages/data/amharic.c +93 -0
- package/cpp/core/src/languages/data/arabic.c +146 -0
- package/cpp/core/src/languages/data/armenian.c +46 -0
- package/cpp/core/src/languages/data/azerbaijani.c +68 -0
- package/cpp/core/src/languages/data/bambara.c +48 -0
- package/cpp/core/src/languages/data/basque.c +62 -0
- package/cpp/core/src/languages/data/belarusian.c +56 -0
- package/cpp/core/src/languages/data/bengali.c +63 -0
- package/cpp/core/src/languages/data/bosnian.c +73 -0
- package/cpp/core/src/languages/data/breton.c +52 -0
- package/cpp/core/src/languages/data/bulgarian.c +144 -0
- package/cpp/core/src/languages/data/burmese.c +48 -0
- package/cpp/core/src/languages/data/catalan.c +84 -0
- package/cpp/core/src/languages/data/chinese.c +70 -0
- package/cpp/core/src/languages/data/croatian.c +72 -0
- package/cpp/core/src/languages/data/czech.c +72 -0
- package/cpp/core/src/languages/data/dagbani.c +88 -0
- package/cpp/core/src/languages/data/danish.c +56 -0
- package/cpp/core/src/languages/data/declarations.h +114 -0
- package/cpp/core/src/languages/data/dutch.c +58 -0
- package/cpp/core/src/languages/data/english.c +172 -0
- package/cpp/core/src/languages/data/esperanto.c +71 -0
- package/cpp/core/src/languages/data/estonian.c +417 -0
- package/cpp/core/src/languages/data/ewe.c +89 -0
- package/cpp/core/src/languages/data/faroese.c +54 -0
- package/cpp/core/src/languages/data/fijian.c +44 -0
- package/cpp/core/src/languages/data/finnish.c +100 -0
- package/cpp/core/src/languages/data/french.c +74 -0
- package/cpp/core/src/languages/data/ga.c +83 -0
- package/cpp/core/src/languages/data/galician.c +70 -0
- package/cpp/core/src/languages/data/georgian.c +57 -0
- package/cpp/core/src/languages/data/german.c +96 -0
- package/cpp/core/src/languages/data/greek.c +202 -0
- package/cpp/core/src/languages/data/guarani.c +110 -0
- package/cpp/core/src/languages/data/gujarati.c +90 -0
- package/cpp/core/src/languages/data/haitian-creole.c +54 -0
- package/cpp/core/src/languages/data/hausa.c +85 -0
- package/cpp/core/src/languages/data/hawaiian.c +50 -0
- package/cpp/core/src/languages/data/hebrew.c +85 -0
- package/cpp/core/src/languages/data/hindi.c +91 -0
- package/cpp/core/src/languages/data/hungarian.c +98 -0
- package/cpp/core/src/languages/data/icelandic.c +73 -0
- package/cpp/core/src/languages/data/igbo.c +90 -0
- package/cpp/core/src/languages/data/indonesian.c +296 -0
- package/cpp/core/src/languages/data/irish.c +60 -0
- package/cpp/core/src/languages/data/italian.c +107 -0
- package/cpp/core/src/languages/data/japanese.c +52 -0
- package/cpp/core/src/languages/data/kannada.c +60 -0
- package/cpp/core/src/languages/data/kazakh.c +57 -0
- package/cpp/core/src/languages/data/khmer.c +71 -0
- package/cpp/core/src/languages/data/kinyarwanda.c +54 -0
- package/cpp/core/src/languages/data/kirundi.c +53 -0
- package/cpp/core/src/languages/data/korean.c +74 -0
- package/cpp/core/src/languages/data/kurmanji.c +43 -0
- package/cpp/core/src/languages/data/kyrgyz.c +65 -0
- package/cpp/core/src/languages/data/lao.c +46 -0
- package/cpp/core/src/languages/data/latin.c +46 -0
- package/cpp/core/src/languages/data/latvian.c +75 -0
- package/cpp/core/src/languages/data/lingala.c +88 -0
- package/cpp/core/src/languages/data/lithuanian.c +65 -0
- package/cpp/core/src/languages/data/luxembourgish.c +80 -0
- package/cpp/core/src/languages/data/macedonian.c +286 -0
- package/cpp/core/src/languages/data/malagasy.c +51 -0
- package/cpp/core/src/languages/data/malay.c +184 -0
- package/cpp/core/src/languages/data/malayalam.c +64 -0
- package/cpp/core/src/languages/data/maltese.c +102 -0
- package/cpp/core/src/languages/data/maori.c +52 -0
- package/cpp/core/src/languages/data/marathi.c +62 -0
- package/cpp/core/src/languages/data/nepali.c +72 -0
- package/cpp/core/src/languages/data/norwegian.c +74 -0
- package/cpp/core/src/languages/data/oromo.c +51 -0
- package/cpp/core/src/languages/data/persian.c +150 -0
- package/cpp/core/src/languages/data/polish.c +111 -0
- package/cpp/core/src/languages/data/portuguese.c +91 -0
- package/cpp/core/src/languages/data/punjabi.c +80 -0
- package/cpp/core/src/languages/data/registry.c +116 -0
- package/cpp/core/src/languages/data/romanian.c +93 -0
- package/cpp/core/src/languages/data/russian.c +76 -0
- package/cpp/core/src/languages/data/samoan.c +47 -0
- package/cpp/core/src/languages/data/sanskrit.c +53 -0
- package/cpp/core/src/languages/data/scottish-gaelic.c +119 -0
- package/cpp/core/src/languages/data/serbian.c +84 -0
- package/cpp/core/src/languages/data/shona.c +55 -0
- package/cpp/core/src/languages/data/sinhala.c +78 -0
- package/cpp/core/src/languages/data/slovak.c +135 -0
- package/cpp/core/src/languages/data/slovenian.c +139 -0
- package/cpp/core/src/languages/data/sorani.c +55 -0
- package/cpp/core/src/languages/data/spanish.c +84 -0
- package/cpp/core/src/languages/data/swahili.c +59 -0
- package/cpp/core/src/languages/data/swedish.c +60 -0
- package/cpp/core/src/languages/data/tagalog.c +75 -0
- package/cpp/core/src/languages/data/tamil.c +69 -0
- package/cpp/core/src/languages/data/tatar.c +548 -0
- package/cpp/core/src/languages/data/telugu.c +54 -0
- package/cpp/core/src/languages/data/thai.c +46 -0
- package/cpp/core/src/languages/data/tibetan.c +55 -0
- package/cpp/core/src/languages/data/tigrinya.c +73 -0
- package/cpp/core/src/languages/data/tongan.c +47 -0
- package/cpp/core/src/languages/data/turkish.c +100 -0
- package/cpp/core/src/languages/data/twi.c +88 -0
- package/cpp/core/src/languages/data/ukrainian.c +99 -0
- package/cpp/core/src/languages/data/urdu.c +174 -0
- package/cpp/core/src/languages/data/vietnamese.c +88 -0
- package/cpp/core/src/languages/data/welsh.c +143 -0
- package/cpp/core/src/languages/data/wolof.c +51 -0
- package/cpp/core/src/languages/data/xhosa.c +56 -0
- package/cpp/core/src/languages/data/yoruba.c +93 -0
- package/cpp/core/src/languages/data/zulu.c +58 -0
- package/cpp/core/src/languages/marks.c +64 -0
- package/cpp/core/src/languages/rules.c +63 -0
- package/cpp/core/src/languages/rules.h +68 -0
- package/cpp/core/src/languages/sanskrit_stemmer.c +50 -0
- package/cpp/core/src/languages/scripts.c +143 -0
- package/cpp/core/src/languages/slovenian_stemmer.c +46 -0
- package/cpp/core/src/languages/snowball/api.c +52 -0
- package/cpp/core/src/languages/snowball/api.h +43 -0
- package/cpp/core/src/languages/snowball/arabic_stemmer.c +1506 -0
- package/cpp/core/src/languages/snowball/arabic_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/armenian_stemmer.c +523 -0
- package/cpp/core/src/languages/snowball/armenian_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/basque_stemmer.c +1089 -0
- package/cpp/core/src/languages/snowball/basque_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/catalan_stemmer.c +1380 -0
- package/cpp/core/src/languages/snowball/catalan_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/czech_stemmer.c +582 -0
- package/cpp/core/src/languages/snowball/czech_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/danish_stemmer.c +352 -0
- package/cpp/core/src/languages/snowball/danish_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/dutch_stemmer.c +1657 -0
- package/cpp/core/src/languages/snowball/dutch_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/english_stemmer.c +1019 -0
- package/cpp/core/src/languages/snowball/english_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/esperanto_stemmer.c +716 -0
- package/cpp/core/src/languages/snowball/esperanto_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/estonian_stemmer.c +1361 -0
- package/cpp/core/src/languages/snowball/estonian_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/finnish_stemmer.c +800 -0
- package/cpp/core/src/languages/snowball/finnish_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/french_stemmer.c +1217 -0
- package/cpp/core/src/languages/snowball/french_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/german_stemmer.c +567 -0
- package/cpp/core/src/languages/snowball/german_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/greek_stemmer.c +3450 -0
- package/cpp/core/src/languages/snowball/greek_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/hindi_stemmer.c +325 -0
- package/cpp/core/src/languages/snowball/hindi_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/hungarian_stemmer.c +742 -0
- package/cpp/core/src/languages/snowball/hungarian_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/indonesian_stemmer.c +443 -0
- package/cpp/core/src/languages/snowball/indonesian_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/irish_stemmer.c +428 -0
- package/cpp/core/src/languages/snowball/irish_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/italian_stemmer.c +983 -0
- package/cpp/core/src/languages/snowball/italian_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/lithuanian_stemmer.c +794 -0
- package/cpp/core/src/languages/snowball/lithuanian_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/nepali_stemmer.c +361 -0
- package/cpp/core/src/languages/snowball/nepali_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/norwegian_stemmer.c +332 -0
- package/cpp/core/src/languages/snowball/norwegian_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/persian_stemmer.c +538 -0
- package/cpp/core/src/languages/snowball/persian_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/polish_stemmer.c +501 -0
- package/cpp/core/src/languages/snowball/polish_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/portuguese_stemmer.c +866 -0
- package/cpp/core/src/languages/snowball/portuguese_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/romanian_stemmer.c +940 -0
- package/cpp/core/src/languages/snowball/romanian_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/russian_stemmer.c +598 -0
- package/cpp/core/src/languages/snowball/russian_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/serbian_stemmer.c +6765 -0
- package/cpp/core/src/languages/snowball/serbian_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/snowball_runtime.h +122 -0
- package/cpp/core/src/languages/snowball/spanish_stemmer.c +955 -0
- package/cpp/core/src/languages/snowball/spanish_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/swedish_stemmer.c +364 -0
- package/cpp/core/src/languages/snowball/swedish_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/tamil_stemmer.c +1305 -0
- package/cpp/core/src/languages/snowball/tamil_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/turkish_stemmer.c +1700 -0
- package/cpp/core/src/languages/snowball/turkish_stemmer.h +24 -0
- package/cpp/core/src/languages/snowball/utilities.c +716 -0
- package/cpp/core/src/languages/substitutions.c +131 -0
- package/cpp/core/src/languages/swahili_stemmer.c +85 -0
- package/cpp/core/src/languages/ukrainian_stemmer.c +168 -0
- package/cpp/core/src/locks.c +2 -15
- package/cpp/core/src/math/apply.c +44 -0
- package/cpp/core/src/math/fdlibm.h +16 -0
- package/cpp/core/src/math/inverse.c +242 -0
- package/cpp/core/src/math/log.c +90 -0
- package/cpp/core/src/math/reduce.c +325 -0
- package/cpp/core/src/math/trig.c +188 -0
- package/cpp/core/src/math/words.h +45 -0
- package/cpp/core/src/thread_yield.h +18 -0
- package/cpp/core/src/unicode/decompositions.c +310 -0
- package/cpp/core/src/unicode/lowercase.c +172 -0
- package/cpp/core/src/unicode/properties.c +214 -0
- package/cpp/core/src/workspace.c +5 -1
- package/lib/engine/analysis.d.ts +3 -0
- package/lib/engine/analysis.js +76 -0
- package/lib/engine/core.js +5 -0
- package/lib/engine/keyword.d.ts +3 -0
- package/lib/engine/keyword.js +25 -0
- package/lib/specs/core.nitro.d.ts +1 -0
- package/nitrogen/generated/shared/c++/HybridNarsilCoreSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridNarsilCoreSpec.hpp +1 -0
- package/package.json +4 -3
- package/src/engine/analysis.ts +87 -0
- package/src/engine/core.ts +6 -0
- package/src/engine/keyword.ts +26 -0
- package/src/specs/core.nitro.ts +1 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#include "../../analysis/languages.h"
|
|
2
|
+
#include "declarations.h"
|
|
3
|
+
|
|
4
|
+
#include <stddef.h>
|
|
5
|
+
#include <stdint.h>
|
|
6
|
+
|
|
7
|
+
static const uint16_t stop_word_units[398] = {
|
|
8
|
+
97, 98, 97, 98, 111, 110, 97, 98, 111, 110, 107, 101, 98, 117, 101, 101, 109, 118, 97, 102, 117, 116, 104, 105, 104,
|
|
9
|
+
97, 121, 105, 105, 105, 110, 105, 107, 97, 107, 97, 104, 108, 101, 107, 97, 107, 104, 117, 108, 117, 107, 97, 110, 99,
|
|
10
|
+
97, 110, 101, 107, 97, 110, 106, 97, 110, 105, 107, 97, 110, 116, 105, 107, 97, 110, 121, 101, 107, 104, 111, 110, 97,
|
|
11
|
+
107, 111, 100, 119, 97, 107, 111, 110, 107, 101, 107, 117, 107, 117, 110, 103, 97, 110, 105, 107, 117, 112, 104, 101,
|
|
12
|
+
108, 97, 107, 117, 115, 104, 111, 107, 119, 97, 108, 97, 108, 97, 107, 104, 101, 108, 97, 112, 104, 97, 108, 97, 112,
|
|
13
|
+
104, 111, 108, 97, 119, 97, 108, 97, 121, 111, 108, 101, 108, 101, 108, 105, 108, 101, 108, 111, 108, 101, 115, 105,
|
|
14
|
+
108, 101, 121, 111, 108, 105, 108, 111, 108, 111, 98, 117, 108, 111, 107, 111, 108, 111, 107, 117, 108, 111, 108, 117,
|
|
15
|
+
108, 117, 109, 105, 110, 97, 110, 97, 110, 101, 110, 103, 97, 110, 103, 97, 107, 104, 111, 110, 103, 101, 110, 103,
|
|
16
|
+
101, 107, 101, 110, 103, 101, 115, 105, 107, 104, 97, 116, 104, 105, 110, 103, 105, 110, 103, 111, 98, 97, 110, 103,
|
|
17
|
+
117, 110, 105, 110, 105, 110, 97, 110, 105, 110, 105, 110, 106, 97, 108, 111, 110, 106, 101, 110, 111, 110, 111, 107,
|
|
18
|
+
104, 111, 110, 111, 109, 97, 111, 107, 117, 112, 104, 97, 107, 97, 116, 104, 105, 112, 104, 97, 109, 98, 105, 112,
|
|
19
|
+
104, 97, 110, 100, 108, 101, 112, 104, 97, 110, 115, 105, 112, 104, 101, 122, 117, 108, 117, 112, 104, 105, 115, 97,
|
|
20
|
+
115, 101, 115, 105, 115, 111, 110, 107, 101, 116, 104, 105, 110, 97, 117, 117, 98, 97, 110, 105, 117, 107, 117, 98,
|
|
21
|
+
97, 117, 107, 117, 116, 104, 105, 117, 107, 117, 122, 101, 117, 109, 97, 119, 97, 119, 97, 104, 97, 109, 98, 97, 119,
|
|
22
|
+
97, 107, 104, 101, 119, 97, 109, 105, 119, 97, 115, 101, 119, 97, 116, 104, 105, 119, 101, 110, 97, 119, 111, 110,
|
|
23
|
+
107, 101, 119, 117, 121, 97, 121, 97, 107, 104, 101, 121, 101, 98, 111, 121, 101, 110, 97, 121, 105, 122, 97, 122, 97,
|
|
24
|
+
107, 104, 101, 122, 111, 110, 107, 101,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
static const uint32_t stop_word_offsets[99] = {
|
|
28
|
+
0, 1, 3, 7, 12, 14, 15, 19, 24, 28, 29, 32, 34, 39, 46, 53, 60, 65, 70, 75, 80, 85, 87, 94, 101, 106, 109, 111, 116,
|
|
29
|
+
121, 126, 130, 134, 136, 140, 144, 148, 152, 154, 156, 160, 164, 168, 172, 174, 178, 180, 182, 185, 191, 194, 199,
|
|
30
|
+
210, 213, 218, 221, 223, 227, 231, 236, 239, 241, 246, 250, 253, 261, 267, 274, 280, 287, 290, 292, 294, 296, 301,
|
|
31
|
+
306, 307, 312, 317, 323, 328, 331, 333, 340, 345, 349, 353, 358, 362, 367, 369, 371, 376, 380, 384, 386, 388, 393,
|
|
32
|
+
398,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
static const uint32_t keep_ranges[8] = {
|
|
36
|
+
45, 45, 48, 57, 65, 90, 97, 122,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const narsil_language narsil_language_zulu = {
|
|
40
|
+
.name = "zulu",
|
|
41
|
+
.revision = "1",
|
|
42
|
+
.stop_word_units = stop_word_units,
|
|
43
|
+
.stop_word_offsets = stop_word_offsets,
|
|
44
|
+
.stop_word_count = 98,
|
|
45
|
+
.ascii_keep = {0x03FF200000000000ULL, 0x07FFFFFE07FFFFFEULL},
|
|
46
|
+
.keep_ranges = keep_ranges,
|
|
47
|
+
.keep_range_count = 4,
|
|
48
|
+
.splits_code_points = 0,
|
|
49
|
+
.strips_possessive = 0,
|
|
50
|
+
.normalises_diacritics = 0,
|
|
51
|
+
.min_token_length = 1,
|
|
52
|
+
.ngram_size = 0,
|
|
53
|
+
.normalise = NULL,
|
|
54
|
+
.stem_by_rules = NULL,
|
|
55
|
+
.create_snowball = NULL,
|
|
56
|
+
.snowball_stem = NULL,
|
|
57
|
+
.close_snowball = NULL,
|
|
58
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#include "../analysis/normalise.h"
|
|
2
|
+
#include "../analysis/text.h"
|
|
3
|
+
#include "rules.h"
|
|
4
|
+
|
|
5
|
+
#include <stddef.h>
|
|
6
|
+
#include <stdint.h>
|
|
7
|
+
|
|
8
|
+
#define COMBINING_GRAVE 0x0300U
|
|
9
|
+
#define COMBINING_ACUTE 0x0301U
|
|
10
|
+
#define COMBINING_CIRCUMFLEX 0x0302U
|
|
11
|
+
#define COMBINING_MACRON 0x0304U
|
|
12
|
+
#define COMBINING_DOT_ABOVE 0x0307U
|
|
13
|
+
#define COMBINING_DIAERESIS 0x0308U
|
|
14
|
+
#define COMBINING_HOOK_ABOVE 0x0309U
|
|
15
|
+
#define COMBINING_GREEK_YPOGEGRAMMENI 0x0345U
|
|
16
|
+
|
|
17
|
+
static int is_grave(uint32_t code_point) { return code_point == COMBINING_GRAVE; }
|
|
18
|
+
|
|
19
|
+
static int is_acute(uint32_t code_point) { return code_point == COMBINING_ACUTE; }
|
|
20
|
+
|
|
21
|
+
static int is_macron(uint32_t code_point) { return code_point == COMBINING_MACRON; }
|
|
22
|
+
|
|
23
|
+
static int is_diaeresis(uint32_t code_point) { return code_point == COMBINING_DIAERESIS; }
|
|
24
|
+
|
|
25
|
+
static int is_slovenian_tone(uint32_t code_point) {
|
|
26
|
+
return code_point >= COMBINING_GRAVE && code_point <= COMBINING_CIRCUMFLEX;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static int is_greek_diacritic_other_than_dialytika(uint32_t code_point) {
|
|
30
|
+
return (code_point >= COMBINING_GRAVE && code_point <= COMBINING_DOT_ABOVE) ||
|
|
31
|
+
(code_point >= COMBINING_HOOK_ABOVE && code_point <= COMBINING_GREEK_YPOGEGRAMMENI);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
int narsil_bulgarian_normalise(const uint16_t *units, size_t length, narsil_text *out,
|
|
35
|
+
narsil_normalise_scratch *scratch) {
|
|
36
|
+
return narsil_remove_marks(units, length, is_grave, out, scratch);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
int narsil_danish_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch) {
|
|
40
|
+
return narsil_remove_marks(units, length, is_acute, out, scratch);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
int narsil_greek_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch) {
|
|
44
|
+
return narsil_remove_marks(units, length, is_greek_diacritic_other_than_dialytika, out, scratch);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
int narsil_latin_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch) {
|
|
48
|
+
return narsil_remove_marks(units, length, is_macron, out, scratch);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
int narsil_macedonian_normalise(const uint16_t *units, size_t length, narsil_text *out,
|
|
52
|
+
narsil_normalise_scratch *scratch) {
|
|
53
|
+
return narsil_remove_marks(units, length, is_grave, out, scratch);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
int narsil_portuguese_normalise(const uint16_t *units, size_t length, narsil_text *out,
|
|
57
|
+
narsil_normalise_scratch *scratch) {
|
|
58
|
+
return narsil_remove_marks(units, length, is_diaeresis, out, scratch);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
int narsil_slovenian_normalise(const uint16_t *units, size_t length, narsil_text *out,
|
|
62
|
+
narsil_normalise_scratch *scratch) {
|
|
63
|
+
return narsil_remove_marks(units, length, is_slovenian_tone, out, scratch);
|
|
64
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#include "rules.h"
|
|
2
|
+
|
|
3
|
+
#include "../../include/narsil_core.h"
|
|
4
|
+
#include "../analysis/text.h"
|
|
5
|
+
|
|
6
|
+
#include <stddef.h>
|
|
7
|
+
#include <stdint.h>
|
|
8
|
+
#include <string.h>
|
|
9
|
+
|
|
10
|
+
static const narsil_unit_substitution *substitution_for(uint16_t unit, const narsil_unit_substitution *substitutions,
|
|
11
|
+
size_t substitution_count) {
|
|
12
|
+
for (size_t i = 0; i < substitution_count; i++) {
|
|
13
|
+
if (unit >= substitutions[i].first && unit <= substitutions[i].last) { return &substitutions[i]; }
|
|
14
|
+
}
|
|
15
|
+
return NULL;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
int narsil_substitute_units(const uint16_t *units, size_t length, const narsil_unit_substitution *substitutions,
|
|
19
|
+
size_t substitution_count, narsil_text *out) {
|
|
20
|
+
out->length = 0;
|
|
21
|
+
int status = narsil_text_reserve(out, length + 1);
|
|
22
|
+
for (size_t i = 0; i < length && status == NARSIL_OK; i++) {
|
|
23
|
+
const narsil_unit_substitution *substitution = substitution_for(units[i], substitutions, substitution_count);
|
|
24
|
+
if (substitution == NULL) {
|
|
25
|
+
status = narsil_text_push(out, units[i]);
|
|
26
|
+
} else {
|
|
27
|
+
status = narsil_text_append(out, substitution->replacement, substitution->length);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return status;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
size_t narsil_rule_length(const uint16_t *literal) {
|
|
34
|
+
size_t length = 0;
|
|
35
|
+
while (literal[length] != 0) { length++; }
|
|
36
|
+
return length;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
int narsil_rule_ends_with(const narsil_text *word, const uint16_t *suffix) {
|
|
40
|
+
size_t length = narsil_rule_length(suffix);
|
|
41
|
+
if (length > word->length) { return 0; }
|
|
42
|
+
return memcmp(word->units + (word->length - length), suffix, length * sizeof(uint16_t)) == 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
int narsil_rule_starts_with(const narsil_text *word, const uint16_t *prefix) {
|
|
46
|
+
size_t length = narsil_rule_length(prefix);
|
|
47
|
+
if (length > word->length) { return 0; }
|
|
48
|
+
return memcmp(word->units, prefix, length * sizeof(uint16_t)) == 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
int narsil_rule_ends_with_unit(const narsil_text *word, uint16_t unit) {
|
|
52
|
+
return word->length > 0 && word->units[word->length - 1] == unit;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
size_t narsil_rule_code_point_count(const uint16_t *units, size_t length) {
|
|
56
|
+
size_t count = 0;
|
|
57
|
+
size_t index = 0;
|
|
58
|
+
while (index < length) {
|
|
59
|
+
narsil_decode_next(units, length, &index);
|
|
60
|
+
count++;
|
|
61
|
+
}
|
|
62
|
+
return count;
|
|
63
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#ifndef NARSIL_LANGUAGES_RULES_H
|
|
2
|
+
#define NARSIL_LANGUAGES_RULES_H
|
|
3
|
+
|
|
4
|
+
#include "../analysis/normalise.h"
|
|
5
|
+
#include "../analysis/text.h"
|
|
6
|
+
|
|
7
|
+
#include <stddef.h>
|
|
8
|
+
#include <stdint.h>
|
|
9
|
+
|
|
10
|
+
#define NARSIL_SUBSTITUTION_MAX_UNITS 2U
|
|
11
|
+
|
|
12
|
+
typedef struct {
|
|
13
|
+
uint16_t first;
|
|
14
|
+
uint16_t last;
|
|
15
|
+
uint8_t length;
|
|
16
|
+
uint16_t replacement[NARSIL_SUBSTITUTION_MAX_UNITS];
|
|
17
|
+
} narsil_unit_substitution;
|
|
18
|
+
|
|
19
|
+
typedef struct {
|
|
20
|
+
const uint16_t *units;
|
|
21
|
+
size_t length;
|
|
22
|
+
} narsil_rule_word;
|
|
23
|
+
|
|
24
|
+
int narsil_substitute_units(const uint16_t *units, size_t length, const narsil_unit_substitution *substitutions,
|
|
25
|
+
size_t substitution_count, narsil_text *out);
|
|
26
|
+
size_t narsil_rule_length(const uint16_t *literal);
|
|
27
|
+
int narsil_rule_ends_with(const narsil_text *word, const uint16_t *suffix);
|
|
28
|
+
int narsil_rule_starts_with(const narsil_text *word, const uint16_t *prefix);
|
|
29
|
+
int narsil_rule_ends_with_unit(const narsil_text *word, uint16_t unit);
|
|
30
|
+
size_t narsil_rule_code_point_count(const uint16_t *units, size_t length);
|
|
31
|
+
|
|
32
|
+
int narsil_bulgarian_normalise(const uint16_t *units, size_t length, narsil_text *out,
|
|
33
|
+
narsil_normalise_scratch *scratch);
|
|
34
|
+
int narsil_danish_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
35
|
+
int narsil_greek_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
36
|
+
int narsil_latin_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
37
|
+
int narsil_macedonian_normalise(const uint16_t *units, size_t length, narsil_text *out,
|
|
38
|
+
narsil_normalise_scratch *scratch);
|
|
39
|
+
int narsil_portuguese_normalise(const uint16_t *units, size_t length, narsil_text *out,
|
|
40
|
+
narsil_normalise_scratch *scratch);
|
|
41
|
+
int narsil_slovenian_normalise(const uint16_t *units, size_t length, narsil_text *out,
|
|
42
|
+
narsil_normalise_scratch *scratch);
|
|
43
|
+
|
|
44
|
+
int narsil_dagbani_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
45
|
+
int narsil_ewe_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
46
|
+
int narsil_german_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
47
|
+
int narsil_guarani_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
48
|
+
int narsil_hebrew_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
49
|
+
int narsil_persian_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
50
|
+
int narsil_romanian_normalise(const uint16_t *units, size_t length, narsil_text *out,
|
|
51
|
+
narsil_normalise_scratch *scratch);
|
|
52
|
+
int narsil_serbian_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
53
|
+
int narsil_sinhala_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
54
|
+
int narsil_telugu_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
55
|
+
int narsil_twi_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
56
|
+
|
|
57
|
+
int narsil_hindi_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
58
|
+
int narsil_malayalam_normalise(const uint16_t *units, size_t length, narsil_text *out,
|
|
59
|
+
narsil_normalise_scratch *scratch);
|
|
60
|
+
int narsil_sorani_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
61
|
+
|
|
62
|
+
int narsil_bulgarian_stem(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
63
|
+
int narsil_sanskrit_stem(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
64
|
+
int narsil_slovenian_stem(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
65
|
+
int narsil_swahili_stem(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
66
|
+
int narsil_ukrainian_stem(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch);
|
|
67
|
+
|
|
68
|
+
#endif
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#include "../../include/narsil_core.h"
|
|
2
|
+
#include "../analysis/normalise.h"
|
|
3
|
+
#include "../analysis/text.h"
|
|
4
|
+
#include "rules.h"
|
|
5
|
+
|
|
6
|
+
#include <stddef.h>
|
|
7
|
+
#include <stdint.h>
|
|
8
|
+
|
|
9
|
+
#define MIN_STEMMED_CODE_POINTS 4U
|
|
10
|
+
#define MIN_REMAINING_CODE_POINTS 3U
|
|
11
|
+
#define COUNT_OF(array) (sizeof(array) / sizeof((array)[0]))
|
|
12
|
+
|
|
13
|
+
static const uint16_t *const long_nominal_endings[] = {
|
|
14
|
+
u"आभ्याम्", u"ाभ्याम्", u"आनाम्", u"एभ्यः", u"ाणाम्", u"ेभ्यः",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
static const uint16_t *const medium_nominal_endings[] = {
|
|
18
|
+
u"स्य", u"ेषु", u"ात्", u"ाम्", u"ान्", u"ेन", u"या", u"ाः", u"अः", u"म्", u"ाम", u"ौ", u"ः", u"आ",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
static const uint16_t *const verb_endings[] = {
|
|
22
|
+
u"न्ति", u"न्ते", u"न्तु", u"अम्", u"सि", u"ति", u"मि", u"ते", u"से", u"तु",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
static const uint16_t *const short_nominal_endings[] = {
|
|
26
|
+
u"ा", u"ि", u"ी", u"ु", u"ू", u"े", u"ो", u"ं",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
static int remove_ending(narsil_text *word, const uint16_t *const *endings, size_t ending_count) {
|
|
30
|
+
for (size_t i = 0; i < ending_count; i++) {
|
|
31
|
+
if (!narsil_rule_ends_with(word, endings[i])) { continue; }
|
|
32
|
+
size_t remaining = word->length - narsil_rule_length(endings[i]);
|
|
33
|
+
if (narsil_rule_code_point_count(word->units, remaining) >= MIN_REMAINING_CODE_POINTS) {
|
|
34
|
+
word->length = remaining;
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
int narsil_sanskrit_stem(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch) {
|
|
42
|
+
(void)scratch;
|
|
43
|
+
int status = narsil_text_assign(out, units, length);
|
|
44
|
+
if (status != NARSIL_OK || narsil_rule_code_point_count(units, length) < MIN_STEMMED_CODE_POINTS) { return status; }
|
|
45
|
+
if (remove_ending(out, long_nominal_endings, COUNT_OF(long_nominal_endings))) { return NARSIL_OK; }
|
|
46
|
+
if (remove_ending(out, medium_nominal_endings, COUNT_OF(medium_nominal_endings))) { return NARSIL_OK; }
|
|
47
|
+
if (remove_ending(out, verb_endings, COUNT_OF(verb_endings))) { return NARSIL_OK; }
|
|
48
|
+
remove_ending(out, short_nominal_endings, COUNT_OF(short_nominal_endings));
|
|
49
|
+
return NARSIL_OK;
|
|
50
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#include "../../include/narsil_core.h"
|
|
2
|
+
#include "../analysis/normalise.h"
|
|
3
|
+
#include "../analysis/text.h"
|
|
4
|
+
#include "../analysis/unicode.h"
|
|
5
|
+
#include "rules.h"
|
|
6
|
+
|
|
7
|
+
#include <stddef.h>
|
|
8
|
+
#include <stdint.h>
|
|
9
|
+
|
|
10
|
+
#define ZERO_WIDTH_NON_JOINER 0x200CU
|
|
11
|
+
#define ZERO_WIDTH_JOINER 0x200DU
|
|
12
|
+
|
|
13
|
+
#define DEVANAGARI_NGA 0x0919U
|
|
14
|
+
#define DEVANAGARI_NYA 0x091EU
|
|
15
|
+
#define DEVANAGARI_NNA 0x0923U
|
|
16
|
+
#define DEVANAGARI_NA 0x0928U
|
|
17
|
+
#define DEVANAGARI_MA 0x092EU
|
|
18
|
+
#define DEVANAGARI_KA 0x0915U
|
|
19
|
+
#define DEVANAGARI_VIRAMA 0x094DU
|
|
20
|
+
#define DEVANAGARI_ANUSVARA 0x0902U
|
|
21
|
+
|
|
22
|
+
#define MALAYALAM_VIRAMA 0x0D4DU
|
|
23
|
+
|
|
24
|
+
#define ARABIC_TEH_MARBUTA 0x0629U
|
|
25
|
+
#define ARABIC_REH 0x0631U
|
|
26
|
+
#define ARABIC_TATWEEL 0x0640U
|
|
27
|
+
#define ARABIC_KAF 0x0643U
|
|
28
|
+
#define ARABIC_HEH 0x0647U
|
|
29
|
+
#define ARABIC_DOTLESS_YEH 0x0649U
|
|
30
|
+
#define ARABIC_YEH 0x064AU
|
|
31
|
+
#define ARABIC_FATHATAN 0x064BU
|
|
32
|
+
#define ARABIC_SUKUN 0x0652U
|
|
33
|
+
#define ARABIC_RREH_ABOVE 0x0692U
|
|
34
|
+
#define ARABIC_RREH 0x0695U
|
|
35
|
+
#define ARABIC_KEHEH 0x06A9U
|
|
36
|
+
#define ARABIC_HEH_DOACHASHMEE 0x06BEU
|
|
37
|
+
#define ARABIC_FARSI_YEH 0x06CCU
|
|
38
|
+
#define ARABIC_AE 0x06D5U
|
|
39
|
+
|
|
40
|
+
typedef struct {
|
|
41
|
+
uint16_t base;
|
|
42
|
+
uint16_t chillu;
|
|
43
|
+
} malayalam_chillu;
|
|
44
|
+
|
|
45
|
+
static const malayalam_chillu malayalam_chillus[] = {
|
|
46
|
+
{0x0D23, 0x0D7A}, {0x0D28, 0x0D7B}, {0x0D30, 0x0D7C}, {0x0D32, 0x0D7D}, {0x0D33, 0x0D7E}, {0x0D15, 0x0D7F},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
static int is_devanagari_nasal(uint16_t unit) {
|
|
50
|
+
return unit == DEVANAGARI_NGA || unit == DEVANAGARI_NYA || unit == DEVANAGARI_NNA || unit == DEVANAGARI_NA ||
|
|
51
|
+
unit == DEVANAGARI_MA;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static int is_devanagari_stop(uint16_t unit) { return unit >= DEVANAGARI_KA && unit <= DEVANAGARI_MA; }
|
|
55
|
+
|
|
56
|
+
int narsil_hindi_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch) {
|
|
57
|
+
(void)scratch;
|
|
58
|
+
out->length = 0;
|
|
59
|
+
int status = narsil_text_reserve(out, length + 1);
|
|
60
|
+
size_t index = 0;
|
|
61
|
+
while (index < length && status == NARSIL_OK) {
|
|
62
|
+
if (index + 2 < length && is_devanagari_nasal(units[index]) && units[index + 1] == DEVANAGARI_VIRAMA &&
|
|
63
|
+
is_devanagari_stop(units[index + 2])) {
|
|
64
|
+
status = narsil_text_push(out, DEVANAGARI_ANUSVARA);
|
|
65
|
+
index += 2;
|
|
66
|
+
} else {
|
|
67
|
+
status = narsil_text_push(out, units[index]);
|
|
68
|
+
index++;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return status;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static uint16_t malayalam_chillu_of(uint16_t base) {
|
|
75
|
+
for (size_t i = 0; i < sizeof(malayalam_chillus) / sizeof(malayalam_chillus[0]); i++) {
|
|
76
|
+
if (malayalam_chillus[i].base == base) { return malayalam_chillus[i].chillu; }
|
|
77
|
+
}
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
int narsil_malayalam_normalise(const uint16_t *units, size_t length, narsil_text *out,
|
|
82
|
+
narsil_normalise_scratch *scratch) {
|
|
83
|
+
(void)scratch;
|
|
84
|
+
out->length = 0;
|
|
85
|
+
int status = narsil_text_reserve(out, length + 1);
|
|
86
|
+
size_t index = 0;
|
|
87
|
+
while (index < length && status == NARSIL_OK) {
|
|
88
|
+
uint16_t unit = units[index];
|
|
89
|
+
uint16_t chillu = malayalam_chillu_of(unit);
|
|
90
|
+
if (chillu != 0 && index + 2 < length && units[index + 1] == MALAYALAM_VIRAMA &&
|
|
91
|
+
units[index + 2] == ZERO_WIDTH_JOINER) {
|
|
92
|
+
status = narsil_text_push(out, chillu);
|
|
93
|
+
index += 3;
|
|
94
|
+
} else {
|
|
95
|
+
if (unit != ZERO_WIDTH_NON_JOINER && unit != ZERO_WIDTH_JOINER) { status = narsil_text_push(out, unit); }
|
|
96
|
+
index++;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return status;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static int sorani_drops(uint32_t code_point) {
|
|
103
|
+
if (code_point == ARABIC_TATWEEL || (code_point >= ARABIC_FATHATAN && code_point <= ARABIC_SUKUN)) { return 1; }
|
|
104
|
+
return (narsil_unicode_properties(code_point) & NARSIL_UNICODE_FORMAT) != 0;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static uint32_t sorani_rewrite(uint32_t code_point, int first, int last) {
|
|
108
|
+
switch (code_point) {
|
|
109
|
+
case ARABIC_YEH:
|
|
110
|
+
case ARABIC_DOTLESS_YEH:
|
|
111
|
+
return ARABIC_FARSI_YEH;
|
|
112
|
+
case ARABIC_KAF:
|
|
113
|
+
return ARABIC_KEHEH;
|
|
114
|
+
case ARABIC_HEH:
|
|
115
|
+
return last ? ARABIC_AE : ARABIC_HEH;
|
|
116
|
+
case ARABIC_TEH_MARBUTA:
|
|
117
|
+
return ARABIC_AE;
|
|
118
|
+
case ARABIC_HEH_DOACHASHMEE:
|
|
119
|
+
return ARABIC_HEH;
|
|
120
|
+
case ARABIC_REH:
|
|
121
|
+
return first ? ARABIC_RREH : ARABIC_REH;
|
|
122
|
+
case ARABIC_RREH_ABOVE:
|
|
123
|
+
return ARABIC_RREH;
|
|
124
|
+
default:
|
|
125
|
+
return code_point;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
int narsil_sorani_normalise(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch) {
|
|
130
|
+
(void)scratch;
|
|
131
|
+
out->length = 0;
|
|
132
|
+
int status = narsil_text_reserve(out, length + 1);
|
|
133
|
+
size_t index = 0;
|
|
134
|
+
while (index < length && status == NARSIL_OK) {
|
|
135
|
+
uint32_t code_point = narsil_decode_next(units, length, &index);
|
|
136
|
+
if (code_point == ZERO_WIDTH_NON_JOINER) {
|
|
137
|
+
if (out->length > 0 && out->units[out->length - 1] == ARABIC_HEH) { out->units[out->length - 1] = ARABIC_AE; }
|
|
138
|
+
} else if (!sorani_drops(code_point)) {
|
|
139
|
+
status = narsil_text_push_code_point(out, sorani_rewrite(code_point, out->length == 0, index == length));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return status;
|
|
143
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#include "../../include/narsil_core.h"
|
|
2
|
+
#include "../analysis/normalise.h"
|
|
3
|
+
#include "../analysis/text.h"
|
|
4
|
+
#include "rules.h"
|
|
5
|
+
|
|
6
|
+
#include <stddef.h>
|
|
7
|
+
#include <stdint.h>
|
|
8
|
+
|
|
9
|
+
#define MIN_STEMMED_UNITS 4U
|
|
10
|
+
#define MIN_REMAINING_UNITS 3U
|
|
11
|
+
|
|
12
|
+
static const uint16_t *const noun_suffixes[] = {
|
|
13
|
+
u"ovanje", u"evanje", u"acija", u"nosti", u"nost", u"osti", u"ost", u"ami", u"jem", u"oma",
|
|
14
|
+
u"ima", u"ov", u"ev", u"om", u"em", u"ih", u"mi", u"ah", u"jo", u"ju",
|
|
15
|
+
u"ji", u"ja", u"je", u"i", u"e", u"a", u"o", u"u",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
static const uint16_t *const verb_suffixes[] = {
|
|
19
|
+
u"ovati", u"evati", u"irati", u"ati", u"iti", u"eti", u"ali", u"ili", u"eli",
|
|
20
|
+
u"ala", u"ilo", u"ila", u"ale", u"ile", u"ele", u"al", u"il", u"el",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
static const uint16_t *const adjective_suffixes[] = {
|
|
24
|
+
u"skih", u"skim", u"sko", u"ske", u"ski", u"ska", u"nih", u"nim", u"no", u"ne", u"ni", u"na", u"en", u"ih", u"im",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
static int remove_suffix(narsil_text *word, const uint16_t *const *suffixes, size_t suffix_count) {
|
|
28
|
+
for (size_t i = 0; i < suffix_count; i++) {
|
|
29
|
+
size_t length = narsil_rule_length(suffixes[i]);
|
|
30
|
+
if (narsil_rule_ends_with(word, suffixes[i]) && word->length - length >= MIN_REMAINING_UNITS) {
|
|
31
|
+
word->length -= length;
|
|
32
|
+
return 1;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
int narsil_slovenian_stem(const uint16_t *units, size_t length, narsil_text *out, narsil_normalise_scratch *scratch) {
|
|
39
|
+
(void)scratch;
|
|
40
|
+
int status = narsil_text_assign(out, units, length);
|
|
41
|
+
if (status != NARSIL_OK || length < MIN_STEMMED_UNITS) { return status; }
|
|
42
|
+
if (remove_suffix(out, noun_suffixes, sizeof(noun_suffixes) / sizeof(noun_suffixes[0]))) { return NARSIL_OK; }
|
|
43
|
+
if (remove_suffix(out, verb_suffixes, sizeof(verb_suffixes) / sizeof(verb_suffixes[0]))) { return NARSIL_OK; }
|
|
44
|
+
remove_suffix(out, adjective_suffixes, sizeof(adjective_suffixes) / sizeof(adjective_suffixes[0]));
|
|
45
|
+
return NARSIL_OK;
|
|
46
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copied from runtime/api.c by the Snowball compiler 3.1.1, with each symbol widened to a
|
|
3
|
+
* UTF-16 code unit so that the stemmer reads the same units as the TypeScript stemmer.
|
|
4
|
+
*
|
|
5
|
+
* Snowball is BSD-3-Clause, copyright (c) 2001, Dr Martin Porter and contributors. The NOTICE file at the root
|
|
6
|
+
* of the repository carries the licence. Source from https://github.com/snowballstem/snowball.git at
|
|
7
|
+
* 6772636350acfd63797e8cd24ff86c70fd2df6fc, verified against https://github.com/snowballstem/snowball-data.git at
|
|
8
|
+
* a0ec0d0a2839ec885878868de20fcb63209d92b0.
|
|
9
|
+
*
|
|
10
|
+
* packages/ts/snowball/build.ts writes this file, so regenerate it with that script.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
#if defined(__GNUC__)
|
|
14
|
+
#pragma GCC diagnostic ignored "-Wcast-align"
|
|
15
|
+
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
#include <stdlib.h> /* for malloc, free */
|
|
20
|
+
#include <string.h> /* for memset */
|
|
21
|
+
#include "snowball_runtime.h"
|
|
22
|
+
|
|
23
|
+
extern struct SN_env * SN_new_env(int alloc_size)
|
|
24
|
+
{
|
|
25
|
+
struct SN_env * z = (struct SN_env *) malloc(alloc_size);
|
|
26
|
+
if (z == NULL) return NULL;
|
|
27
|
+
/* This memset() will initialise z->p to all-bits-zero which (at least
|
|
28
|
+
* theoretically) may not be the NULL pointer representation, but that's OK
|
|
29
|
+
* as immediately afterwards we assign to z->p.
|
|
30
|
+
*/
|
|
31
|
+
memset(z, 0, alloc_size);
|
|
32
|
+
z->p = create_s();
|
|
33
|
+
if (z->p == NULL) {
|
|
34
|
+
SN_delete_env(z);
|
|
35
|
+
return NULL;
|
|
36
|
+
}
|
|
37
|
+
return z;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
extern void SN_delete_env(struct SN_env * z)
|
|
41
|
+
{
|
|
42
|
+
if (z == NULL) return;
|
|
43
|
+
if (z->p) lose_s(z->p);
|
|
44
|
+
free(z);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
extern int SN_set_current(struct SN_env * z, int size, const symbol * s)
|
|
48
|
+
{
|
|
49
|
+
int err = replace_s(z, 0, z->l, size, s);
|
|
50
|
+
z->c = 0;
|
|
51
|
+
return err;
|
|
52
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copied from runtime/api.h by the Snowball compiler 3.1.1, with each symbol widened to a
|
|
3
|
+
* UTF-16 code unit so that the stemmer reads the same units as the TypeScript stemmer.
|
|
4
|
+
*
|
|
5
|
+
* Snowball is BSD-3-Clause, copyright (c) 2001, Dr Martin Porter and contributors. The NOTICE file at the root
|
|
6
|
+
* of the repository carries the licence. Source from https://github.com/snowballstem/snowball.git at
|
|
7
|
+
* 6772636350acfd63797e8cd24ff86c70fd2df6fc, verified against https://github.com/snowballstem/snowball-data.git at
|
|
8
|
+
* a0ec0d0a2839ec885878868de20fcb63209d92b0.
|
|
9
|
+
*
|
|
10
|
+
* packages/ts/snowball/build.ts writes this file, so regenerate it with that script.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
#ifndef SNOWBALL_API_H_INCLUDED
|
|
14
|
+
#define SNOWBALL_API_H_INCLUDED
|
|
15
|
+
|
|
16
|
+
typedef unsigned short symbol;
|
|
17
|
+
|
|
18
|
+
/* Or replace 'char' above with 'short' for 16 bit characters.
|
|
19
|
+
|
|
20
|
+
More precisely, replace 'char' with whatever type guarantees the
|
|
21
|
+
character width you need.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
struct SN_env {
|
|
25
|
+
symbol * p;
|
|
26
|
+
int c; int l; int lb; int bra; int ket;
|
|
27
|
+
int af;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
#ifdef __cplusplus
|
|
31
|
+
extern "C" {
|
|
32
|
+
#endif
|
|
33
|
+
|
|
34
|
+
extern struct SN_env * SN_new_env(int alloc_size);
|
|
35
|
+
extern void SN_delete_env(struct SN_env * z);
|
|
36
|
+
|
|
37
|
+
extern int SN_set_current(struct SN_env * z, int size, const symbol * s);
|
|
38
|
+
|
|
39
|
+
#ifdef __cplusplus
|
|
40
|
+
}
|
|
41
|
+
#endif
|
|
42
|
+
|
|
43
|
+
#endif
|