-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionaryReaderFactoryBean.java
More file actions
89 lines (75 loc) · 2.49 KB
/
Copy pathDictionaryReaderFactoryBean.java
File metadata and controls
89 lines (75 loc) · 2.49 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Copyright 2011: Thomson Reuters Global Resources. All Rights Reserved.
*
* Proprietary and Confidential information of TRGR. Disclosure, Use or
* Reproduction without the written authorization of TRGR is prohibited
*/
package com.research.course.debate.util ;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
/**
*
*
*/
public class DictionaryReaderFactoryBean
{
private List<File> headwordFiles;
private List<File> conflationsFiles;
public DictionaryReaderFactoryBean(List<File> headwordFiles, List<File> conflationsFiles)
{
this.headwordFiles = headwordFiles;
this.conflationsFiles = conflationsFiles;
}
public Map<String, KrovetzStemmer.DictionaryEntry> getDictionary() throws Exception
{
Map<String, KrovetzStemmer.DictionaryEntry> dictionary = new HashMap<String, KrovetzStemmer.DictionaryEntry>();
for (File headwordFile : headwordFiles)
{
BufferedReader br = new BufferedReader(new FileReader(headwordFile));
try
{
String line = br.readLine();
while (line != null)
{
String word = line.trim();
dictionary.put(word, new KrovetzStemmer.DictionaryEntry("", false));
line = br.readLine();
}
}
finally
{
try { br.close(); } catch (IOException ignored) { }
}
}
for (File conflationsFile : conflationsFiles)
{
BufferedReader br = new BufferedReader(new FileReader(conflationsFile));
try
{
String line = br.readLine();
while (line != null)
{
StringTokenizer st = new StringTokenizer(line, " ");
if (st.countTokens() == 2)
{
String variant = st.nextToken();
String headword = st.nextToken();
dictionary.put(variant, new KrovetzStemmer.DictionaryEntry(headword, false));
}
line = br.readLine();
}
}
finally
{
try { br.close(); } catch (IOException ignored) { }
}
}
return dictionary;
}
}