Révision 38
SRC/src/fr/triangle/hyperalign/kernel/dico/Dictionary.java (revision 38) | ||
---|---|---|
4 | 4 |
import java.net.URL; |
5 | 5 |
import java.util.ArrayList; |
6 | 6 |
import java.util.Collections; |
7 |
import java.util.Enumeration; |
|
7 | 8 |
import java.util.HashMap; |
8 | 9 |
import java.util.List; |
9 | 10 |
import java.util.Vector; |
... | ... | |
56 | 57 |
/** |
57 | 58 |
* This static value corresponds to the level in the dictionary : "dico" |
58 | 59 |
*/ |
59 |
public final static String DICO_DICO = "dictionary_dico";
|
|
60 |
public final static String DICO_DICO = "dico"; |
|
60 | 61 |
/** |
61 | 62 |
* This static value corresponds to the level in the dictionary : "form" |
62 | 63 |
*/ |
63 |
public final static String DICO_FORM = "dictionary_form";
|
|
64 |
public final static String DICO_FORM = "form"; |
|
64 | 65 |
/** |
65 | 66 |
* This static value corresponds to the level in the dictionary : "lemme" |
66 | 67 |
*/ |
67 |
public final static String DICO_LEMME = "dictionary_lemme";
|
|
68 |
public final static String DICO_LEMME = "lemme"; |
|
68 | 69 |
/** |
69 | 70 |
* This static value corresponds to the level in the dictionary : "occ" |
70 | 71 |
*/ |
71 |
public final static String DICO_OCC = "dictionary_occ";
|
|
72 |
public final static String DICO_OCC = "occ"; |
|
72 | 73 |
|
73 | 74 |
|
74 | 75 |
public final static String OCC = "occ";//Occ |
... | ... | |
129 | 130 |
public Vector<DictionaryElement> getLemmes(){ |
130 | 131 |
Vector<DictionaryElement> children = null; |
131 | 132 |
if(root!=null){ |
132 |
children = root.children(); |
|
133 |
children = root.childrenVect();
|
|
133 | 134 |
} |
134 | 135 |
return children; |
135 | 136 |
} |
... | ... | |
147 | 148 |
Vector<DictionaryElement> children = getLemmes(); |
148 | 149 |
//System.out.println("Terminology.getConcept() with id "+id); |
149 | 150 |
//Concept LEVEL |
150 |
if(children.size()>0){ |
|
151 |
for(int i = 0 ; i < children.size(); ++i){ |
|
152 |
DictionaryElement child = (DictionaryElement) children.get(i); |
|
153 |
if(child.getId().equals(id)){ |
|
154 |
lemme = child; |
|
155 |
//System.out.println("------------- concept => "+child); |
|
156 |
} |
|
151 |
for (DictionaryElement child : children) { |
|
152 |
if(child.getId().equals(id)){ |
|
153 |
lemme = child; |
|
154 |
//System.out.println("------------- concept => "+child); |
|
157 | 155 |
} |
158 | 156 |
} |
159 | 157 |
return lemme; |
... | ... | |
186 | 184 |
public Vector<DictionaryElement> getNearLemme(String word, DictionaryElement root){ |
187 | 185 |
Vector<DictionaryElement> nearLemmes = new Vector<DictionaryElement>(); |
188 | 186 |
boolean isNearLemme = false; |
189 |
Vector<DictionaryElement> children = root.children();
|
|
187 |
Enumeration<DictionaryElement> children = root.children();
|
|
190 | 188 |
if(children!=null){ |
191 |
|
|
192 | 189 |
//Concept LEVEL |
193 |
if(children.size()>0){ |
|
194 |
for(int i = 0 ; i < children.size(); ++i){ |
|
195 |
DictionaryElement child = (DictionaryElement) children.get(i); |
|
196 |
StringDistance stDist = new StringDistance(); |
|
197 |
int dist = stDist.computeLevenshteinDistance(child.getName(), word); |
|
190 |
while(children.hasMoreElements()){ |
|
191 |
DictionaryElement child = (DictionaryElement) children.nextElement(); |
|
192 |
StringDistance stDist = new StringDistance(); |
|
193 |
int dist = stDist.computeLevenshteinDistance(child.getName(), word); |
|
198 | 194 |
|
199 |
if(dist <= 2){ |
|
200 |
//System.out.println("Distance entre ["+child.getName()+"] et ["+word+"] = "+dist); |
|
195 |
if(dist <= 2){ |
|
196 |
//System.out.println("Distance entre ["+child.getName()+"] et ["+word+"] = "+dist); |
|
197 |
nearLemmes.add(child); |
|
198 |
} |
|
199 |
|
|
200 |
else { |
|
201 |
isNearLemme = getForm(word, child, stDist); |
|
202 |
if(isNearLemme){ |
|
201 | 203 |
nearLemmes.add(child); |
202 | 204 |
} |
203 |
|
|
204 |
else { |
|
205 |
isNearLemme = getForm(word, child, stDist); |
|
206 |
if(isNearLemme){ |
|
207 |
nearLemmes.add(child); |
|
208 |
} |
|
209 |
} |
|
210 | 205 |
} |
211 | 206 |
} |
212 | 207 |
} |
... | ... | |
216 | 211 |
public DictionaryElement getLemme(String word, DictionaryElement root){ |
217 | 212 |
DictionaryElement lemme = null; |
218 | 213 |
boolean isNearLemme = false; |
219 |
Vector<DictionaryElement> children = root.children();
|
|
214 |
Enumeration<DictionaryElement> children = root.children();
|
|
220 | 215 |
if(children!=null){ |
221 | 216 |
|
222 | 217 |
//Concept LEVEL |
223 |
if(children.size()>0){ |
|
224 |
for(int i = 0 ; i < children.size(); ++i){ |
|
225 |
DictionaryElement child = (DictionaryElement) children.get(i); |
|
226 |
|
|
227 |
if(child.getName().equals(word)){ |
|
228 |
return child; |
|
229 |
} |
|
218 |
while(children.hasMoreElements()){ |
|
219 |
DictionaryElement child = (DictionaryElement) children.nextElement(); |
|
220 |
if(child.getName().equals(word)){ |
|
221 |
return child; |
|
230 | 222 |
} |
231 | 223 |
} |
232 | 224 |
} |
... | ... | |
242 | 234 |
*/ |
243 | 235 |
public boolean getForm(String word, DictionaryElement root, StringDistance stDist){ |
244 | 236 |
//System.out.println("------------------TerminologyManager.getTerm"); |
245 |
Vector<DictionaryElement> children = root.children();
|
|
237 |
Enumeration<DictionaryElement> children = root.children();
|
|
246 | 238 |
//Concept LEVEL |
247 |
if(children.size()>0){ |
|
248 |
for(int i = 0 ; i < children.size(); ++i){ |
|
249 |
DictionaryElement child = (DictionaryElement) children.get(i); |
|
239 |
while(children.hasMoreElements()){ |
|
240 |
DictionaryElement child = (DictionaryElement) children.nextElement(); |
|
250 | 241 |
|
251 |
int dist = stDist.computeLevenshteinDistance(child.getName(), word); |
|
252 |
//System.out.println("Distance entre ["+child.getElement()+"] et ["+word+"] = "+dist); |
|
253 |
|
|
254 |
//if(child.getElement().equals(word)){ |
|
255 |
if(dist < 2){ |
|
256 |
return true; |
|
257 |
} |
|
242 |
int dist = stDist.computeLevenshteinDistance(child.getName(), word); |
|
243 |
//System.out.println("Distance entre ["+child.getElement()+"] et ["+word+"] = "+dist); |
|
244 |
//if(child.getElement().equals(word)){ |
|
245 |
if(dist < 2){ |
|
246 |
return true; |
|
258 | 247 |
} |
259 | 248 |
} |
260 |
|
|
261 | 249 |
return false; |
262 | 250 |
} |
263 | 251 |
|
... | ... | |
268 | 256 |
public Vector<DictionaryElement> getForms(){ |
269 | 257 |
Vector<DictionaryElement> forms = new Vector<DictionaryElement>(); |
270 | 258 |
Vector<DictionaryElement> lemmes = getLemmes(); |
271 |
for(int i = 0 ; i < lemmes.size() ; ++i){ |
|
272 |
DictionaryElement lemme = lemmes.get(i); |
|
273 |
Vector<DictionaryElement> formsOfLemme = lemme.children(); |
|
274 |
for(int j = 0 ; j < formsOfLemme.size() ; ++j){ |
|
275 |
forms.add(formsOfLemme.get(j)); |
|
259 |
for (DictionaryElement lemme : lemmes) { |
|
260 |
Enumeration<DictionaryElement> formsOfLemme = lemme.children(); |
|
261 |
while(formsOfLemme.hasMoreElements()){ |
|
262 |
forms.add(formsOfLemme.nextElement()); |
|
276 | 263 |
} |
277 | 264 |
} |
278 | 265 |
return forms; |
... | ... | |
289 | 276 |
for(int i = 0 ; i < terms.size() ; ++i){ |
290 | 277 |
DictionaryElement termEl = terms.get(i); |
291 | 278 |
if(termEl.getName().equals(term)){ |
292 |
Vector<DictionaryElement> occs = termEl.children();
|
|
293 |
for(int j = 0 ; j < occs.size() ; ++j){
|
|
294 |
DictionaryElement occEl = occs.get(j);
|
|
279 |
Enumeration<DictionaryElement> occs = termEl.children();
|
|
280 |
while(occs.hasMoreElements()){
|
|
281 |
DictionaryElement occEl = occs.nextElement();
|
|
295 | 282 |
if(occEl.getId().equals(idOcc)){ |
296 | 283 |
return occEl; |
297 | 284 |
} |
... | ... | |
345 | 332 |
DictionaryElement term = null; |
346 | 333 |
if(element.getReference().equals(Dictionary.DICO_FORM)){ |
347 | 334 |
term = element; |
348 |
Vector<DictionaryElement> children = term.children();
|
|
349 |
System.out.println("Dictionary.getOccurrence() NB OCCS "+children.size()+" for term ["+term+"]");
|
|
335 |
Enumeration<DictionaryElement> children = term.children();
|
|
336 |
System.out.println("Dictionary.getOccurrence() for term ["+term+"]"); |
|
350 | 337 |
|
351 |
for(int i = 0 ; i < children.size();++i){
|
|
352 |
occEl = children.get(i);
|
|
338 |
while(children.hasMoreElements()){
|
|
339 |
occEl = children.nextElement();
|
|
353 | 340 |
//System.out.println("Terminology.getOccurrence() >>>> "+occEl); |
354 | 341 |
if(occEl.getOccurrence()==occSet){ |
355 | 342 |
System.out.println("Dictionary.getOccurrence() >>>> "+occEl); |
... | ... | |
391 | 378 |
public Vector<DictionaryElement> getOccurrencesForLemme(DictionaryElement lemme){ |
392 | 379 |
Vector<DictionaryElement> occs = new Vector<DictionaryElement>(); |
393 | 380 |
if(lemme.children()!=null){ |
394 |
for(int i = 0 ; i < lemme.children().size(); ++i){
|
|
395 |
DictionaryElement form = (DictionaryElement) lemme.children().get(i);
|
|
381 |
while(lemme.children().hasMoreElements()){
|
|
382 |
DictionaryElement form = (DictionaryElement) lemme.children().nextElement();
|
|
396 | 383 |
if(form.children()!=null){ |
397 |
for(int j = 0 ; j < form.children().size(); ++j){
|
|
398 |
DictionaryElement occ = (DictionaryElement) form.children().get(j);
|
|
384 |
while(form.children().hasMoreElements()){
|
|
385 |
DictionaryElement occ = (DictionaryElement) form.children().nextElement();
|
|
399 | 386 |
occs.add(occ); |
400 | 387 |
} |
401 | 388 |
} |
... | ... | |
430 | 417 |
*/ |
431 | 418 |
public DictionaryElement getFormWithLemme(DictionaryElement lemme, String formStr){ |
432 | 419 |
DictionaryElement form = null; |
433 |
Vector<DictionaryElement> forms = lemme.children();
|
|
434 |
for(int i = 0 ; i < forms.size() ; ++i){
|
|
435 |
form = forms.get(i);
|
|
420 |
Enumeration<DictionaryElement> forms = lemme.children();
|
|
421 |
while(forms.hasMoreElements()){
|
|
422 |
form = forms.nextElement();
|
|
436 | 423 |
if(formStr.equals(form.getName())){ |
437 | 424 |
return form; |
438 | 425 |
} |
... | ... | |
483 | 470 |
public DictionaryElement checkElementAsChild(String elementName, DictionaryElement parent){ |
484 | 471 |
//System.out.println("Terminology.checkElementAsChild() >> "+elementName+" FROM "+parent.getName()); |
485 | 472 |
if(parent!=null){ |
486 |
Vector<DictionaryElement> children = parent.children();
|
|
473 |
Enumeration<DictionaryElement> children = parent.children();
|
|
487 | 474 |
if(children!=null){ |
488 |
for(int i = 0 ; i< children.size(); ++i){
|
|
489 |
DictionaryElement child = children.get(i);
|
|
475 |
while(children.hasMoreElements()){
|
|
476 |
DictionaryElement child = children.nextElement();
|
|
490 | 477 |
if(child.getName().equals(elementName)){ |
491 | 478 |
return child; |
492 | 479 |
} |
... | ... | |
499 | 486 |
public DictionaryElement checkLemme(String idLemme, DictionaryElement root){ |
500 | 487 |
//System.out.println("Terminology.checkElementAsChild() >> "+elementName+" FROM "+parent.getName()); |
501 | 488 |
if(root!=null){ |
502 |
Vector<DictionaryElement> children = root.children();
|
|
489 |
Enumeration<DictionaryElement> children = root.children();
|
|
503 | 490 |
if(children!=null){ |
504 |
for(int i = 0 ; i< children.size(); ++i){
|
|
505 |
DictionaryElement child = children.get(i);
|
|
491 |
while(children.hasMoreElements()){
|
|
492 |
DictionaryElement child = children.nextElement();
|
|
506 | 493 |
if(child.getId().equals(idLemme)){ |
507 | 494 |
return child; |
508 | 495 |
} |
... | ... | |
520 | 507 |
*/ |
521 | 508 |
public DictionaryElement checkAndAddForm(String newForm, DictionaryElement lemme){ |
522 | 509 |
if(lemme!=null){ |
523 |
Vector<DictionaryElement> forms = lemme.children();
|
|
510 |
Enumeration<DictionaryElement> forms = lemme.children();
|
|
524 | 511 |
if(forms!=null){ |
525 |
for(int i = 0 ; i< forms.size(); ++i){
|
|
526 |
DictionaryElement formOfLemme = forms.get(i);
|
|
512 |
while(forms.hasMoreElements()){
|
|
513 |
DictionaryElement formOfLemme = forms.nextElement();
|
|
527 | 514 |
if(formOfLemme.getName().equals(newForm)){ |
528 | 515 |
//System.out.println(newTerm+" is already in the terminology !"); |
529 | 516 |
return formOfLemme; |
Formats disponibles : Unified diff