Datasets:

ArXiv:
License:
File size: 3,512 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*

 * 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.Ling;
import tool.util.Util;

/**

 *

 * @author

 */
public class SymbolReplacementSieve 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, substituteSymbolsInStringWithWords(nameForTransformation));
            transformedNames = Util.addUnique(transformedNames, substituteWordsInStringWithSymbols(nameForTransformation));
        }
        
        concept.setNamesKnowledgeBase(transformedNames);   
    }
    
    public static List<String> getClinicalReportTypeSubstitutions(String string) {
        List<String> newStrings = new ArrayList<>();
        for (String digit : Ling.getDigitToWordMap().keySet()) {
            if (!string.contains(digit)) 
                continue;
            List<String> wordsList = Ling.getDigitToWordMap().get(digit);
            for (String word : wordsList) {
                String newString = string.replaceAll(digit, word);
                if (!newString.equals(string))
                    newStrings = Util.setList(newStrings, newString);
            }
        }        
        return newStrings;
    }
    
    public static String getBiomedicalTypeSubstitutions(String string) {
        if (string.contains("and/or")) 
            string = string.replaceAll("and/or", "and");
        if (string.contains("/"))
            string = string.replaceAll("/", " and ");
        if (string.contains(" (") && string.contains(")"))
            string = string.replace(" (", "").replace(")", "");
        else if (string.contains("(") && string.contains(")"))
            string = string.replace("(", "").replace(")", "");
        return string;
    }
    
    public static List<String> substituteSymbolsInStringWithWords(String string) {
        List<String> newStrings = getClinicalReportTypeSubstitutions(string);
        List<String> tempNewStrings = new ArrayList<>();
        for (String newString : newStrings)
            tempNewStrings = Util.setList(tempNewStrings, getBiomedicalTypeSubstitutions(newString));        
        newStrings = Util.addUnique(newStrings, tempNewStrings);
        newStrings = Util.setList(newStrings, getBiomedicalTypeSubstitutions(string));        
        return newStrings;
    }
    
    public static List<String> substituteWordsInStringWithSymbols(String string) {
        List<String> newStrings = new ArrayList<>();
        for (String word : Ling.getWordToDigitMap().keySet()) {
            if (!string.contains(word))
                continue;
            String digit = Ling.getWordToDigitMap().get(word);
            String newString = string.replaceAll(word, digit);
            if (!newString.equals(string))
                newStrings = Util.setList(newStrings, newString);
        }
        return newStrings;
    }
        
}