Datasets:

ArXiv:
License:
File size: 2,534 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */
package tool.sieves;

import java.util.ArrayList;
import java.util.List;
import tool.util.Concept;
import tool.util.Util;

/**

 *

 * @author

 */
public class HyphenationSieve extends Sieve{
    
    public static String apply(Concept concept) {
        transformName(concept);
        return normalize(concept.getNamesKnowledgeBase());
    }      
 
    private static void transformName(Concept concept) {
        List<String> namesForTransformation = new ArrayList<>(concept.getNamesKnowledgeBase());
        List<String> transformedNames = new ArrayList<>();        
        
        for (String nameForTransformation : namesForTransformation) {
            transformedNames = Util.addUnique(transformedNames, hyphenateString(nameForTransformation.split("\\s+")));
            transformedNames = Util.addUnique(transformedNames, dehyphenateString(nameForTransformation.split("\\-")));
        }
        
        concept.setNamesKnowledgeBase(transformedNames);   
    }    
    
    public static List<String> hyphenateString(String[] stringTokens) {
        List<String> hyphenatedStrings = new ArrayList<>();
        for (int i = 1; i < stringTokens.length; i++) {
            String hyphenatedString = "";
            for (int j = 0; j < stringTokens.length; j++) {
                if (j == i)
                    hyphenatedString += "-"+stringTokens[j];
                else 
                    hyphenatedString = hyphenatedString.equals("") ? stringTokens[j] : hyphenatedString+" "+stringTokens[j];
            }
            hyphenatedStrings = Util.setList(hyphenatedStrings, hyphenatedString);
        }
        return hyphenatedStrings;
    }    
    
    public static List<String> dehyphenateString(String[] stringTokens) {
        List<String> dehyphenatedStrings = new ArrayList<>();
        for (int i = 1; i < stringTokens.length; i++) {
            String dehyphenatedString = "";
            for (int j = 0; j < stringTokens.length; j++) {
                if (j == i)
                    dehyphenatedString += " "+stringTokens[j];
                else
                    dehyphenatedString = dehyphenatedString.equals("") ? stringTokens[j] : dehyphenatedString+"-"+stringTokens[j];
            }
            dehyphenatedStrings = Util.setList(dehyphenatedStrings, dehyphenatedString);
        }
        return dehyphenatedStrings;
    }    
    
}