KickJava   Java API By Example, From Geeks To Geeks.

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


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

13 public final class GermanWeighter implements Weighter {
14     
15     private Hashtable JavaDoc<String JavaDoc, Integer JavaDoc> trigrams;
16     
17     public GermanWeighter() {
18         trigrams = new Hashtable JavaDoc<String JavaDoc, Integer JavaDoc>();
19         trigrams.put("ein", new Integer JavaDoc(122));
20         trigrams.put("ich", new Integer JavaDoc(111));
21         trigrams.put("nde", new Integer JavaDoc(89));
22         trigrams.put("die", new Integer JavaDoc(87));
23         trigrams.put("und", new Integer JavaDoc(87));
24         trigrams.put("der", new Integer JavaDoc(86));
25         trigrams.put("che", new Integer JavaDoc(75));
26         trigrams.put("end", new Integer JavaDoc(75));
27         trigrams.put("gen", new Integer JavaDoc(71));
28         trigrams.put("sch", new Integer JavaDoc(66));
29         trigrams.put("cht", new Integer JavaDoc(61));
30         trigrams.put("den", new Integer JavaDoc(57));
31         trigrams.put("ine", new Integer JavaDoc(53));
32         trigrams.put("nge", new Integer JavaDoc(52));
33         trigrams.put("nun", new Integer JavaDoc(48));
34         trigrams.put("ung", new Integer JavaDoc(48));
35         trigrams.put("das", new Integer JavaDoc(47));
36         trigrams.put("hen", new Integer JavaDoc(47));
37         trigrams.put("ind", new Integer JavaDoc(46));
38         trigrams.put("enw", new Integer JavaDoc(45));
39     }
40     
41     /**
42      * If the given trigram is in the list of mostly common trigrams of german
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