summaryrefslogtreecommitdiff
path: root/external/hunspell/0001-Hunspell-patches-for-missing-OCONV-conversion.patch
blob: 83d429f509796efb0a5c595858ab5961f2821837 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
From e13ff056fd65990b88d29fb9eae304b411e58234 Mon Sep 17 00:00:00 2001
From: Changwoo Ryu <cwryu@debian.org>
Date: Wed, 8 Mar 2017 14:04:26 +0900
Subject: [PATCH] Hunspell patches for missing OCONV conversion

4e2abfd Clean up PR #479
cc2d71e Add oconv2 test to Makefile
ca14fdb Avoid gotos across variable initialization
7e5cb62 Use goto to reduce repetitive code
f528192 Add missing OCONV conversion of root and morphemes output
---
 src/hunspell/hunspell.cxx | 59 +++++++++++++++++++++++++++++++++++++++--------
 tests/test.sh             | 23 +++++++++++++++---
 2 files changed, 70 insertions(+), 12 deletions(-)

diff --git a/src/hunspell/hunspell.cxx b/src/hunspell/hunspell.cxx
index 1100a6f..87d1b4a 100644
--- a/src/hunspell/hunspell.cxx
+++ b/src/hunspell/hunspell.cxx
@@ -98,10 +98,13 @@ public:
   std::vector<std::string> stem(const std::string& word);
   std::vector<std::string> stem(const std::vector<std::string>& morph);
   std::vector<std::string> analyze(const std::string& word);
+  std::vector<std::string> analyze_internal(const std::string& word);
   int get_langnum() const;
   bool input_conv(const std::string& word, std::string& dest);
   bool spell(const std::string& word, int* info = NULL, std::string* root = NULL);
+  bool spell_internal(const std::string& word, int* info = NULL, std::string* root = NULL);
   std::vector<std::string> suggest(const std::string& word);
+  std::vector<std::string> suggest_internal(const std::string& word);
   const std::string& get_wordchars() const;
   const std::vector<w_char>& get_wordchars_utf16() const;
   const std::string& get_dict_encoding() const;
@@ -415,6 +418,21 @@ bool Hunspell::spell(const std::string& word, int* info, std::string* root) {
 }
 
 bool HunspellImpl::spell(const std::string& word, int* info, std::string* root) {
+  bool r = spell_internal(word, info, root);
+  if (r && root) {
+    // output conversion
+    RepList* rl = (pAMgr) ? pAMgr->get_oconvtable() : NULL;
+    if (rl) {
+      std::string wspace;
+      if (rl->conv(*root, wspace)) {
+        *root = wspace;
+      }
+    }
+  }
+  return r;
+}
+
+bool HunspellImpl::spell_internal(const std::string& word, int* info, std::string* root) {
   struct hentry* rv = NULL;
 
   int info2 = 0;
@@ -834,6 +852,22 @@ std::vector<std::string> Hunspell::suggest(const std::string& word) {
 
 std::vector<std::string> HunspellImpl::suggest(const std::string& word) {
   std::vector<std::string> slst;
+  slst = suggest_internal(word);
+  // output conversion
+  RepList* rl = (pAMgr) ? pAMgr->get_oconvtable() : NULL;
+  if (rl) {
+    for (size_t i = 0; rl && i < slst.size(); ++i) {
+      std::string wspace;
+      if (rl->conv(slst[i], wspace)) {
+        slst[i] = wspace;
+      }
+    }
+  }
+  return slst;
+}
+
+std::vector<std::string> HunspellImpl::suggest_internal(const std::string& word) {
+  std::vector<std::string> slst;
 
   int onlycmpdsug = 0;
   if (!pSMgr || m_HMgrs.empty())
@@ -1150,15 +1184,6 @@ std::vector<std::string> HunspellImpl::suggest(const std::string& word) {
   }
   slst.resize(l);
 
-  // output conversion
-  rl = (pAMgr) ? pAMgr->get_oconvtable() : NULL;
-  for (size_t j = 0; rl && j < slst.size(); ++j) {
-    std::string wspace;
-    if (rl->conv(slst[j], wspace)) {
-      slst[j] = wspace;
-    }
-  }
-
   return slst;
 }
 
@@ -1365,6 +1390,22 @@ std::vector<std::string> Hunspell::analyze(const std::string& word) {
 
 std::vector<std::string> HunspellImpl::analyze(const std::string& word) {
   std::vector<std::string> slst;
+  slst = analyze_internal(word);
+  // output conversion
+  RepList* rl = (pAMgr) ? pAMgr->get_oconvtable() : NULL;
+  if (rl) {
+    for (size_t i = 0; rl && i < slst.size(); ++i) {
+      std::string wspace;
+      if (rl->conv(slst[i], wspace)) {
+        slst[i] = wspace;
+      }
+    }
+  }
+  return slst;
+}
+
+std::vector<std::string> HunspellImpl::analyze_internal(const std::string& word) {
+  std::vector<std::string> slst;
   if (!pSMgr || m_HMgrs.empty())
     return slst;
   if (utf8) {
diff --git a/tests/test.sh b/tests/test.sh
index 22e5087..9344f82 100755
--- a/tests/test.sh
+++ b/tests/test.sh
@@ -112,7 +112,7 @@ if test -f $TESTDIR/$NAME.wrong; then
         echo "============================================="
         echo "Fail in $NAME.wrong. Bad words recognised as good:"
         tr -d '	' <$TESTDIR/$NAME.wrong >$TEMPDIR/$NAME.wrong.detab
-        diff $TEMPDIR/$NAME.wrong.detab $TEMPDIR/$NAME.wrong | grep '^<' | sed 's/^..//'
+        diff -u $TEMPDIR/$NAME.wrong.detab $TEMPDIR/$NAME.wrong | grep '^<' | sed 's/^..//'
         rm -f $TEMPDIR/$NAME.wrong $TEMPDIR/$NAME.wrong.detab
         exit 1
     fi
@@ -121,6 +121,23 @@ fi
 
 check_valgrind_log "bad words"
 
+# Tests good words' root
+if test -f $TESTDIR/$NAME.root; then
+    # Extract the root words of the affixed words, after '+'
+    hunspell $* -d $TESTDIR/$NAME <$TESTDIR/$NAME.good | grep -a '^+ ' | \
+        sed 's/^+ //' >$TEMPDIR/$NAME.root
+    if ! cmp $TEMPDIR/$NAME.root $TESTDIR/$NAME.root >/dev/null; then
+        echo "============================================="
+        echo "Fail in $NAME.root. Bad prefix or suffix?"
+        diff -u $TESTDIR/$NAME.root $TEMPDIR/$NAME.root
+        rm -f $TEMPDIR/$NAME.root
+        exit 1
+    fi
+    rm -f $TEMPDIR/$NAME.root
+fi
+
+check_valgrind_log "root"
+
 # Tests morphological analysis
 if test -f $TESTDIR/$NAME.morph; then
     sed 's/	$//' $TESTDIR/$NAME.good >$TEMPDIR/$NAME.good
@@ -129,7 +146,7 @@ if test -f $TESTDIR/$NAME.morph; then
     if ! cmp $TEMPDIR/$NAME.morph $TESTDIR/$NAME.morph >/dev/null; then
         echo "============================================="
         echo "Fail in $NAME.morph. Bad analysis?"
-        diff $TESTDIR/$NAME.morph $TEMPDIR/$NAME.morph | grep '^<' | sed 's/^..//'
+        diff -u $TESTDIR/$NAME.morph $TEMPDIR/$NAME.morph | grep '^<' | sed 's/^..//'
         rm -f $TEMPDIR/$NAME.morph
         exit 1
     fi
@@ -145,7 +162,7 @@ if test -f $TESTDIR/$NAME.sug; then
     if ! cmp $TEMPDIR/$NAME.sug $TESTDIR/$NAME.sug >/dev/null; then
         echo "============================================="
         echo "Fail in $NAME.sug. Bad suggestion?"
-        diff $TESTDIR/$NAME.sug $TEMPDIR/$NAME.sug
+        diff -u $TESTDIR/$NAME.sug $TEMPDIR/$NAME.sug
         rm -f $TEMPDIR/$NAME.sug
         exit 1
     fi
-- 
2.7.4