forked from apache/lucenenet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest64kAffixes.cs
More file actions
70 lines (63 loc) · 2.98 KB
/
Copy pathTest64kAffixes.cs
File metadata and controls
70 lines (63 loc) · 2.98 KB
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
// Lucene version compatibility level 4.10.4
using J2N;
using Lucene.Net.Support;
using Lucene.Net.Util;
using NUnit.Framework;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Lucene.Net.Analysis.Hunspell
{
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Tests that > 64k affixes actually works and doesn't overflow some internal int
public class Test64kAffixes : LuceneTestCase
{
[Test]
public void Test()
{
DirectoryInfo tempDir = CreateTempDir("64kaffixes");
FileInfo affix = new FileInfo(System.IO.Path.Combine(tempDir.FullName, "64kaffixes.aff"));
FileInfo dict = new FileInfo(System.IO.Path.Combine(tempDir.FullName, "64kaffixes.dic"));
using (var affixWriter = new StreamWriter(
new FileStream(affix.FullName, FileMode.OpenOrCreate), StandardCharsets.UTF_8))
{
// 65k affixes with flag 1, then an affix with flag 2
affixWriter.Write("SET UTF-8\nFLAG num\nSFX 1 Y 65536\n");
for (int i = 0; i < 65536; i++)
{
affixWriter.Write("SFX 1 0 " + i.ToHexString() + " .\n");
}
affixWriter.Write("SFX 2 Y 1\nSFX 2 0 s\n");
} // affixWriter.Dispose();
using (var dictWriter = new StreamWriter(
new FileStream(dict.FullName, FileMode.OpenOrCreate), StandardCharsets.UTF_8))
{
// drink signed with affix 2 (takes -s)
dictWriter.Write("1\ndrink/2\n");
} // dictWriter.Dispose();
using Stream affStream = new FileStream(affix.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
using Stream dictStream = new FileStream(dict.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
Dictionary dictionary = new Dictionary(affStream, dictStream);
Stemmer stemmer = new Stemmer(dictionary);
// drinks should still stem to drink
IList<CharsRef> stems = stemmer.Stem("drinks");
assertEquals(1, stems.size());
assertEquals("drink", stems[0].ToString());
}
}
}