22 |
22 |
/**
|
23 |
23 |
* Debug state.
|
24 |
24 |
*/
|
25 |
|
public static boolean debug = true;
|
|
25 |
protected boolean debug;
|
26 |
26 |
|
27 |
27 |
/**
|
28 |
28 |
* Keys matching this REGEX will be preserved.
|
29 |
29 |
*/
|
30 |
30 |
public static String preserve = "^(common_|error_|info_).*$";
|
31 |
31 |
|
|
32 |
|
|
33 |
|
32 |
34 |
/**
|
|
35 |
*
|
|
36 |
* @param debug
|
|
37 |
*/
|
|
38 |
public NormalizeKeys(boolean debug) {
|
|
39 |
this.debug = debug;
|
|
40 |
|
|
41 |
|
|
42 |
}
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
/**
|
33 |
49 |
* Normalizes the keys of the specified messages map.
|
34 |
50 |
* @param messages
|
35 |
51 |
* @return
|
36 |
52 |
*/
|
37 |
|
public static BiHashMap<String, String> normalize(BiHashMap<String, String> messages) {
|
|
53 |
public BiHashMap<String, String> normalize(BiHashMap<String, String> messages) {
|
38 |
54 |
|
39 |
55 |
for (String key : messages.getKeys()) {
|
40 |
56 |
String value = messages.get(key);
|
... | ... | |
62 |
78 |
* Normalizes the specified string.
|
63 |
79 |
* @param str
|
64 |
80 |
*/
|
65 |
|
public static String normalize(String str) {
|
|
81 |
public String normalize(String str) {
|
66 |
82 |
|
67 |
83 |
// log
|
68 |
84 |
if(debug) {
|
69 |
|
System.out.println(str);
|
|
85 |
System.out.println("NormalizeKeys.normalize(): normalizing: " + str);
|
70 |
86 |
}
|
71 |
87 |
|
72 |
88 |
str = str.replaceAll("[^a-zA-Z0-9 ]", "").trim();
|
... | ... | |
76 |
92 |
System.err.println("NormalizeKeys.normalize(): warning: empty string.");
|
77 |
93 |
}
|
78 |
94 |
else {
|
|
95 |
|
79 |
96 |
String[] words = str.split(" ");
|
80 |
97 |
str = "";
|
81 |
98 |
for (int i = 0; i < words.length; i++) {
|
... | ... | |
120 |
137 |
File messageFile = new File(projectFile, "src/java/org/txm/core/messages/TXMCoreMessages.java");
|
121 |
138 |
|
122 |
139 |
PluginMessages pmManager = new PluginMessages(projectFile, messageFile);
|
123 |
|
|
|
140 |
NormalizeKeys keysNormalizer = new NormalizeKeys(true);
|
124 |
141 |
|
125 |
142 |
// tests
|
126 |
|
BiHashMap<String, String> messages = new BiHashMap<String, String>();
|
127 |
|
messages.put("Convert5To6_46", "Error while computing.");
|
128 |
|
messages.put("Convert5To6_46", "** Error: the connexion to the server failed: wrong port format");
|
129 |
|
messages.put("Convert5To6_6", "** Error: ''{0}'' corpus directory is not conformant to TXM corpus binary format: corpus skipped.");
|
130 |
|
messages.put("common_lowestFrequency", "Lowest frequency");
|
131 |
|
messages.put("Convert5To6_27", "T");
|
132 |
|
messages.put("Convert5To6_28", "");
|
133 |
|
messages = normalize(messages);
|
|
143 |
keysNormalizer.normalize(pmManager.getMessagesForLang(""));
|
134 |
144 |
|
135 |
|
pmManager.dump(messages);
|
|
145 |
pmManager.dump(pmManager.getMessagesForLang(""));
|
136 |
146 |
|
137 |
147 |
System.out.println("NormalizeKeys.main(): terminated.");
|
138 |
148 |
|