KickJava   Java API By Example, From Geeks To Geeks.

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


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 english.
10  * @author Michael Scholz
11  * @version 1.0
12  */

13 public final class EnglishWeighter implements Weighter {
14
15     private Hashtable JavaDoc<String JavaDoc, Integer JavaDoc> trigrams;
16     
17     public EnglishWeighter() {
18         trigrams = new Hashtable JavaDoc<String JavaDoc, Integer JavaDoc>();
19         trigrams.put("the", new Integer JavaDoc(200));
20         trigrams.put("and", new Integer JavaDoc(93));
21         trigrams.put("ing", new Integer JavaDoc(74));
22         trigrams.put("her", new Integer JavaDoc(58));
23         trigrams.put("tha", new Integer JavaDoc(47));
24         trigrams.put("hat", new Integer JavaDoc(44));
25         trigrams.put("his", new Integer JavaDoc(41));
26         trigrams.put("you", new Integer JavaDoc(40));
27         trigrams.put("ere", new Integer JavaDoc(39));
28         trigrams.put("dth", new Integer JavaDoc(35));
29         trigrams.put("ent", new Integer JavaDoc(34));
30         trigrams.put("eth", new Integer JavaDoc(32));
31         trigrams.put("for", new Integer JavaDoc(32));
32         trigrams.put("nth", new Integer JavaDoc(31));
33         trigrams.put("thi", new Integer JavaDoc(30));
34         trigrams.put("she", new Integer JavaDoc(30));
35         trigrams.put("was", new Integer JavaDoc(29));
36         trigrams.put("hes", new Integer JavaDoc(29));
37         trigrams.put("ith", new Integer JavaDoc(28));
38         trigrams.put("tth", new Integer JavaDoc(28));
39     }
40     
41     /**
42      * If the given trigram is in the list of mostly common trigrams of english
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