From: Teemu Huovila Date: Wed, 1 Jun 2016 09:24:57 +0000 (+0300) Subject: lib-fts: Improved stopword file reading. X-Git-Tag: 2.3.0.rc1~3585 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3f3c1b629196bc8491f146705b6f8ddadfcde1c8;p=thirdparty%2Fdovecot%2Fcore.git lib-fts: Improved stopword file reading. The reading tries to be a little bit stricter now. Only stopwords at the start of a new line are accepted now. Changed fi stopwords accordingly. Also removed superfluous stack allocation in parsing. --- diff --git a/src/lib-fts/Makefile.am b/src/lib-fts/Makefile.am index 4eb3f49e93..1219ddf82a 100644 --- a/src/lib-fts/Makefile.am +++ b/src/lib-fts/Makefile.am @@ -38,7 +38,8 @@ EXTRA_DIST = \ word-properties.pl \ WordBreakProperty.txt \ word-boundary-data.c \ - word-break-data.c + word-break-data.c \ + stopwords/stopwords_malformed.txt WordBreakProperty.txt: test -f WordBreakProperty.txt || wget http://www.unicode.org/Public/UNIDATA/auxiliary/WordBreakProperty.txt diff --git a/src/lib-fts/fts-filter-stopwords.c b/src/lib-fts/fts-filter-stopwords.c index 2d6df6964f..8b7a1067a5 100644 --- a/src/lib-fts/fts-filter-stopwords.c +++ b/src/lib-fts/fts-filter-stopwords.c @@ -11,8 +11,8 @@ #define STOPWORDS_FILE_FORMAT "%s/stopwords_%s.txt" -#define STOPWORDS_COMMENT_CHAR1 '|' -#define STOPWORDS_COMMENT_CHAR2 '#' +#define STOPWORDS_CUTCHARS "|#\t " +#define STOPWORDS_DISALLOWED_CHARS "/\\<>.,\":()\t\n\r" struct fts_filter_stopwords { struct fts_filter filter; @@ -26,29 +26,33 @@ static int fts_filter_stopwords_read_list(struct fts_filter_stopwords *filter, const char **error_r) { struct istream *input; - const char *line, **words, *path; + const char *line, *word, *path; int ret = 0; + size_t len; path = t_strdup_printf(STOPWORDS_FILE_FORMAT, filter->stopwords_dir, filter->lang->name); input = i_stream_create_file(path, IO_BLOCK_SIZE); - while ((line = i_stream_read_next_line(input)) != NULL) T_BEGIN { - line = t_strcut(line, STOPWORDS_COMMENT_CHAR1); - line = t_strcut(line, STOPWORDS_COMMENT_CHAR2); - - words = t_strsplit_spaces(line, " \t"); - for (; *words != NULL; words++) { - const char *word = p_strdup(filter->pool, *words); - hash_table_insert(filter->stopwords, word, word); - } - } T_END; + while ((line = i_stream_read_next_line(input)) != NULL) { + len = strcspn(line, STOPWORDS_CUTCHARS); + if (len == 0) + continue; + if (strcspn(line, STOPWORDS_DISALLOWED_CHARS) < len) + continue; + word = p_strndup(filter->pool, line, len); + hash_table_insert(filter->stopwords, word, word); + } if (input->stream_errno != 0) { *error_r = t_strdup_printf("Failed to read stopword list %s: %s", path, i_stream_get_error(input)); ret = -1; } + + if (ret == 0 && hash_table_count(filter->stopwords) == 0) + i_warning("Stopwords list \"%s\" seems empty. Is the file correctly formatted?", path); + i_stream_destroy(&input); return ret; } diff --git a/src/lib-fts/stopwords/stopwords_fi.txt b/src/lib-fts/stopwords/stopwords_fi.txt index addad798c4..95c74f256b 100644 --- a/src/lib-fts/stopwords/stopwords_fi.txt +++ b/src/lib-fts/stopwords/stopwords_fi.txt @@ -38,28 +38,193 @@ emme ette eivät +|Words below in the following cases: |Nom Gen Acc Part Iness Elat Illat Adess Ablat Allat Ess Trans -minä minun minut minua minussa minusta minuun minulla minulta minulle | I -sinä sinun sinut sinua sinussa sinusta sinuun sinulla sinulta sinulle | you -hän hänen hänet häntä hänessä hänestä häneen hänellä häneltä hänelle | he she -me meidän meidät meitä meissä meistä meihin meillä meiltä meille | we -te teidän teidät teitä teissä teistä teihin teillä teiltä teille | you -he heidän heidät heitä heissä heistä heihin heillä heiltä heille | they - -tämä tämän tätä tässä tästä tähän tallä tältä tälle tänä täksi | this -tuo tuon tuotä tuossa tuosta tuohon tuolla tuolta tuolle tuona tuoksi | that -se sen sitä siinä siitä siihen sillä siltä sille sinä siksi | it -nämä näiden näitä näissä näistä näihin näillä näiltä näille näinä näiksi | these -nuo noiden noita noissa noista noihin noilla noilta noille noina noiksi | those -ne niiden niitä niissä niistä niihin niillä niiltä niille niinä niiksi | they - -kuka kenen kenet ketä kenessä kenestä keneen kenellä keneltä kenelle kenenä keneksi| who -ketkä keiden ketkä keitä keissä keistä keihin keillä keiltä keille keinä keiksi | (pl) -mikä minkä minkä mitä missä mistä mihin millä miltä mille minä miksi | which what -mitkä | (pl) - -joka jonka jota jossa josta johon jolla jolta jolle jona joksi | who which -jotka joiden joita joissa joista joihin joilla joilta joille joina joiksi | (pl) +minä | I +minun | I +minut | I +minua | I +minussa | I +minusta | I +minuun | I +minulla | I +minulta | I +minulle | I +sinä | you +sinun | you +sinut | you +sinua | you +sinussa | you +sinusta | you +sinuun | you +sinulla | you +sinulta | you +sinulle | you +hän | he she +hänen | he she +hänet | he she +häntä | he she +hänessä | he she +hänestä | he she +häneen | he she +hänellä | he she +häneltä | he she +hänelle | he she +me | we +meidän | we +meidät | we +meitä | we +meissä | we +meistä | we +meihin | we +meillä | we +meiltä | we +meille | we +te | you +teidän | you +teidät | you +teitä | you +teissä | you +teistä | you +teihin | you +teillä | you +teiltä | you +teille | you +he | they +heidän | they +heidät | they +heitä | they +heissä | they +heistä | they +heihin | they +heillä | they +heiltä | they +heille | they +tämä | this +tämän | this +tätä | this +tässä | this +tästä | this +tähän | this +tallä | this +tältä | this +tälle | this +tänä | this +täksi | this +tuo | that +tuon | that +tuotä | that +tuossa | that +tuosta | that +tuohon | that +tuolla | that +tuolta | that +tuolle | that +tuona | that +tuoksi | that +se | it +sen | it +sitä | it +siinä | it +siitä | it +siihen | it +sillä | it +siltä | it +sille | it +sinä | it +siksi | it +nämä | these +näiden | these +näitä | these +näissä | these +näistä | these +näihin | these +näillä | these +näiltä | these +näille | these +näinä | these +näiksi | these +nuo | those +noiden | those +noita | those +noissa | those +noista | those +noihin | those +noilla | those +noilta | those +noille | those +noina | those +noiksi | those +ne | they +niiden | they +niitä | they +niissä | they +niistä | they +niihin | they +niillä | they +niiltä | they +niille | they +niinä | they +niiksi | they +kuka | who +kenen | who +kenet | who +ketä | who +kenessä | who +kenestä | who +keneen | who +kenellä | who +keneltä | who +kenelle | who +kenenä | who +keneksi | who +ketkä | who (pl) +keiden | who (pl) +ketkä | who (pl) +keitä | who (pl) +keissä | who (pl) +keistä | who (pl) +keihin | who (pl) +keillä | who (pl) +keiltä | who (pl) +keille | who (pl) +keinä | who (pl) +keiksi | who (pl) +mikä | which what +minkä | which what +minkä | which what +mitä | which what +missä | which what +mistä | which what +mihin | which what +millä | which what +miltä | which what +mille | which what +minä | which what +miksi | which what +mitkä | which what (pl) +joka | who which +jonka | who which +jota | who which +jossa | who which +josta | who which +johon | who which +jolla | who which +jolta | who which +jolle | who which +jona | who which +joksi | who which +jotka | who which (pl) +joiden | who which (pl) +joita | who which (pl) +joissa | who which (pl) +joista | who which (pl) +joihin | who which (pl) +joilla | who which (pl) +joilta | who which (pl) +joille | who which (pl) +joina | who which (pl) +joiksi | who which (pl) | conjunctions diff --git a/src/lib-fts/stopwords/stopwords_malformed.txt b/src/lib-fts/stopwords/stopwords_malformed.txt new file mode 100644 index 0000000000..5899230617 --- /dev/null +++ b/src/lib-fts/stopwords/stopwords_malformed.txt @@ -0,0 +1,2866 @@ + + + + + + + + + + + + + + + + + + + + + + + + lucene-solr/stopwords_de.txt at master · apache/lucene-solr · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Skip to content + + + + + + + + + + + + +
+ +
+
+ + +
+
+
+ +
+
+ + + + + +

+ + /lucene-solr + + + + + + + mirrored from git://git.apache.org/lucene-solr.git + +

+ +
+ +
+ +
+
+ + + + + + + +
+ +
+ + + +
+ +
+ + Find file + + +
+ +
+ + +
+ + + be4680a + + + + + +
+ + +
+ + +
+ +
+
+
+ +
+ Raw + Blame + History +
+ + + + +
+ +
+ 295 lines (243 sloc) + + 4.47 KB +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
| From svn.tartarus.org/snowball/trunk/website/algorithms/german/stop.txt
| This file is distributed under the BSD License.
| See http://snowball.tartarus.org/license.php
| Also see http://www.opensource.org/licenses/bsd-license.html
| - Encoding was converted to UTF-8.
| - This notice was added.
|
| NOTE: To use this file with StopFilterFactory, you must specify format="snowball"
+
| A German stop word list. Comments begin with vertical bar. Each stop
| word is at the start of a line.
+
| The number of forms in this list is reduced significantly by passing it
| through the German stemmer.
+
+
aber | but
+
alle | all
allem
allen
aller
alles
+
als | than, as
also | so
am | an + dem
an | at
+
ander | other
andere
anderem
anderen
anderer
anderes
anderm
andern
anderr
anders
+
auch | also
auf | on
aus | out of
bei | by
bin | am
bis | until
bist | art
da | there
damit | with it
dann | then
+
der | the
den
des
dem
die
das
+
daß | that
+
derselbe | the same
derselben
denselben
desselben
demselben
dieselbe
dieselben
dasselbe
+
dazu | to that
+
dein | thy
deine
deinem
deinen
deiner
deines
+
denn | because
+
derer | of those
dessen | of him
+
dich | thee
dir | to thee
du | thou
+
dies | this
diese
diesem
diesen
dieser
dieses
+
+
doch | (several meanings)
dort | (over) there
+
+
durch | through
+
ein | a
eine
einem
einen
einer
eines
+
einig | some
einige
einigem
einigen
einiger
einiges
+
einmal | once
+
er | he
ihn | him
ihm | to him
+
es | it
etwas | something
+
euer | your
eure
eurem
euren
eurer
eures
+
für | for
gegen | towards
gewesen | p.p. of sein
hab | have
habe | have
haben | have
hat | has
hatte | had
hatten | had
hier | here
hin | there
hinter | behind
+
ich | I
mich | me
mir | to me
+
+
ihr | you, to her
ihre
ihrem
ihren
ihrer
ihres
euch | to you
+
im | in + dem
in | in
indem | while
ins | in + das
ist | is
+
jede | each, every
jedem
jeden
jeder
jedes
+
jene | that
jenem
jenen
jener
jenes
+
jetzt | now
kann | can
+
kein | no
keine
keinem
keinen
keiner
keines
+
können | can
könnte | could
machen | do
man | one
+
manche | some, many a
manchem
manchen
mancher
manches
+
mein | my
meine
meinem
meinen
meiner
meines
+
mit | with
muss | must
musste | had to
nach | to(wards)
nicht | not
nichts | nothing
noch | still, yet
nun | now
nur | only
ob | whether
oder | or
ohne | without
sehr | very
+
sein | his
seine
seinem
seinen
seiner
seines
+
selbst | self
sich | herself
+
sie | they, she
ihnen | to them
+
sind | are
so | so
+
solche | such
solchem
solchen
solcher
solches
+
soll | shall
sollte | should
sondern | but
sonst | else
über | over
um | about, around
und | and
+
uns | us
unse
unsem
unsen
unser
unses
+
unter | under
viel | much
vom | von + dem
von | from
vor | before
während | while
war | was
waren | were
warst | wast
was | what
weg | away, off
weil | because
weiter | further
+
welche | which
welchem
welchen
welcher
welches
+
wenn | when
werde | will
werden | will
wie | how
wieder | again
will | want
wir | we
wird | will
wirst | willst
wo | where
wollen | want
wollte | wanted
würde | would
würden | would
zu | to
zum | zu + dem
zur | zu + der
zwar | indeed
zwischen | between
+
+ +
+ +
+ + + + +
+ +
+ + +
+
+ +
+ + + + + + + + + +
+ + + Something went wrong with that request. Please try again. +
+ + + + + + + + + + + + + + diff --git a/src/lib-fts/test-fts-filter.c b/src/lib-fts/test-fts-filter.c index 55dd25f640..a3844b477a 100644 --- a/src/lib-fts/test-fts-filter.c +++ b/src/lib-fts/test-fts-filter.c @@ -348,6 +348,22 @@ static void test_fts_filter_stopwords_fail_lazy_init(void) } +static void test_fts_filter_stopwords_malformed(void) +{ + const struct fts_language malformed = { .name = "malformed" }; + struct fts_filter *filter = NULL; + const char *error = NULL, *token = "foobar"; + + test_begin("fts filter stopwords, malformed list"); + test_assert(fts_filter_create(fts_filter_stopwords, NULL, &malformed, stopword_settings, &filter, &error) == 0); + test_expect_error_string("seems empty. Is the file correctly formatted?"); + test_assert(fts_filter_filter(filter, &token, &error) > 0); + test_expect_no_more_errors(); + fts_filter_unref(&filter); + test_end(); + +} + #ifdef HAVE_FTS_STEMMER static void test_fts_filter_stemmer_snowball_stem_english(void) { @@ -893,6 +909,7 @@ int main(void) test_fts_filter_stopwords_fra, test_fts_filter_stopwords_no, test_fts_filter_stopwords_fail_lazy_init, + test_fts_filter_stopwords_malformed, #ifdef HAVE_FTS_STEMMER test_fts_filter_stemmer_snowball_stem_english, test_fts_filter_stemmer_snowball_stem_french,