KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > contineo > core > text > lili > FrenchWeighter


1 /*
2  * Created on 30.10.2004
3  */

4 package org.contineo.core.text.lili;
5
6 import java.util.Hashtable JavaDoc;
7
8 /**
9  * This class weights a trigram using the most common trigrams of french.
10  * @author Michael Scholz
11  * @version 1.0
12  */

13 public class FrenchWeighter implements Weighter {
14     
15     private Hashtable JavaDoc<String JavaDoc, Integer JavaDoc> trigrams;
16     
17     public FrenchWeighter() {
18         trigrams = new Hashtable JavaDoc<String JavaDoc, Integer JavaDoc>();
19         trigrams.put("les", new Integer JavaDoc(158));
20         trigrams.put("des", new Integer JavaDoc(121));
21         trigrams.put("que", new Integer JavaDoc(91));
22         trigrams.put("une", new Integer JavaDoc(87));
23         trigrams.put("est", new Integer JavaDoc(86));
24         trigrams.put("qui", new Integer JavaDoc(70));
25         trigrams.put("pas", new Integer JavaDoc(63));
26         trigrams.put("qu'", new Integer JavaDoc(63));
27         trigrams.put("par", new Integer JavaDoc(47));
28         trigrams.put("sur", new Integer JavaDoc(42));
29         trigrams.put("son", new Integer JavaDoc(33));
30         trigrams.put("lui", new Integer JavaDoc(28));
31         trigrams.put("ses", new Integer JavaDoc(22));
32         trigrams.put("ils", new Integer JavaDoc(21));
33         trigrams.put("aux", new Integer JavaDoc(20));
34         trigrams.put("ces", new Integer JavaDoc(16));
35         trigrams.put("mon", new Integer JavaDoc(13));
36         trigrams.put("moi", new Integer JavaDoc(13));
37         trigrams.put("peu", new Integer JavaDoc(11));
38         trigrams.put("ont", new Integer JavaDoc(11));
39     }
40     
41     /**
42      * If the given trigram is in the list of mostly common trigrams of french
43      * the retsult is an value greather than 0. Otherwise the this method returns 0.
44      * @param trigram - Trigram to weight
45      * @return
46      */

47     public int getWeight(String JavaDoc trigram) {
48         if (trigrams.containsKey(trigram))
49             return ((Integer JavaDoc)trigrams.get(trigram)).intValue();
50         else
51             return 0;
52     }
53 }
54
Popular Tags