Statistics
| Revision:

root / tmp / org.txm.dictionary.rcp / src / org / txm / dictionary / functions / tsv / ConvRules.groovy @ 470

History | View | Annotate | Download (941 Bytes)

1
package org.txm.dictionary.functions.tsv
2

    
3
import java.io.File;
4
import java.io.IOException;
5
import java.io.Serializable;
6
import java.util.HashMap;
7
import java.util.regex.Pattern
8

    
9
class ConvRules {
10
        public static HashMap<Serializable, Serializable[]> getConversionRulesFromFile(
11
                        File conversionTSVFile) throws IOException {
12
                HashMap<Serializable, Serializable[]> conversionRules = new HashMap<Serializable, Serializable[]>();
13
                BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(conversionTSVFile) , "UTF-8"));
14
                String line = reader.readLine();
15
                Pattern pattern = Pattern.compile("\t");
16
                Pattern multipleValuePattern = Pattern.compile("\\|");
17

    
18
                while (line != null) {
19
                        String[] split = pattern.split(line, 2);
20
                        if (split.length == 2) {
21
                                conversionRules.put(split[0], multipleValuePattern.split(split[1]));
22
                        }
23
                        line = reader.readLine();
24
                }
25
                reader.close();
26

    
27
                return conversionRules;
28
        }
29
}