source: branches/2.2/jabberit_messenger/java_source/src/com/swabunga/spell/engine/Configuration.java @ 3102

Revision 3102, 4.9 KB checked in by amuller, 14 years ago (diff)

Ticket #986 - Efetuado merge para o Branch 2.2( atualizacao do modulo)

  • Property svn:executable set to *
Line 
1package com.swabunga.spell.engine;
2
3
4/**
5 * The various settings used to control how a spell checker works are read from here.
6 * Includes the COST_* constants that decide how to figure the cost of converting one word to
7 * another in the EditDistance class.
8 * <p/>
9 * Also includes SPELL_* constants that control how misspellings are detected, for example, how to handle
10 * mixed-case words, etc.
11 *
12 * @author aim4min
13 * @see EditDistance
14 */
15public abstract class Configuration {
16
17  /** used by EditDistance: the cost of having to remove a character <br/>(integer greater than 0) */
18  public static final String COST_REMOVE_CHAR = "EDIT_DEL1";
19
20  /** used by EditDistance: the cost of having to insert a character <br/>(integer greater than 0)*/
21  public static final String COST_INSERT_CHAR = "EDIT_DEL2";
22
23  /**
24   * used by EditDistance: the cost of having to swap two adjoinging characters
25   * for the swap value to ever be used, it should be smaller than the COST_REMOVE_CHAR or COST_INSERT_CHAR values
26   * <br/>(integer greater than 0)
27   */
28  public static final String COST_SWAP_CHARS = "EDIT_SWAP";
29
30  /**
31   * used by EditDistance: the cost of having to change case, for example, from i to I.
32   * <br/>(integer greater than 0)
33   */
34  public static final String COST_CHANGE_CASE = "EDIT_CASE";
35
36  /**
37   * used by EditDistance: the cost of having to substitute one character for another
38   * for the sub value to ever be used, it should be smaller than the COST_REMOVE_CHAR or COST_INSERT_CHAR values
39   * <br/>(integer greater than 0)
40   */
41  public static final String COST_SUBST_CHARS = "EDIT_SUB";
42
43//    public static final String EDIT_SIMILAR = "EDIT_SIMILAR"; //DMV: these does not seem to be used at all
44//    public static final String EDIT_MIN = "EDIT_MIN";
45//    public static final String EDIT_MAX = "EDIT_MAX";
46
47  /** the maximum cost of suggested spelling. Any suggestions that cost more are thrown away
48   * <br/> integer greater than 1)
49   */
50  public static final String SPELL_THRESHOLD = "SPELL_THRESHOLD";
51
52  /** words that are all upper case are not spell checked, example: "CIA" <br/>(boolean) */
53  public static final String SPELL_IGNOREUPPERCASE = "SPELL_IGNOREUPPERCASE";
54  /**  words that have mixed case are not spell checked, example: "SpellChecker"<br/>(boolean) */
55  public static final String SPELL_IGNOREMIXEDCASE = "SPELL_IGNOREMIXEDCASE";
56  /** words that look like an internet address are not spell checked, example: "http://www.google.com" <br/>(boolean)*/
57  public static final String SPELL_IGNOREINTERNETADDRESSES = "SPELL_IGNOREINTERNETADDRESS";
58  /** words that have digits in them are not spell checked, example: "mach5" <br/>(boolean) */
59  public static final String SPELL_IGNOREDIGITWORDS = "SPELL_IGNOREDIGITWORDS";
60  /** I don't know what this does. It doesn't seem to be used <br/>(boolean) */
61  public static final String SPELL_IGNOREMULTIPLEWORDS = "SPELL_IGNOREMULTIPLEWORDS";
62  /** the first word of a sentance is expected to start with an upper case letter <br/>(boolean) */
63  public static final String SPELL_IGNORESENTENCECAPITALIZATION = "SPELL_IGNORESENTENCECAPTILIZATION";
64
65  /**
66   * Gets one of the integer constants
67   * @param key one of the integer constants defined in this class
68   * @return int value of the setting
69   */
70  public abstract int getInteger(String key);
71
72  /**
73   * Gets one of the boolean constants
74   * @param key one of the boolean constants defined in this class
75   * @return boolean value of the setting
76   */
77  public abstract boolean getBoolean(String key);
78
79  /**
80   * Sets one of the integer constants
81   * @param key one of the integer constants defined in this class
82   * @param value new integer value of the constant
83   */
84  public abstract void setInteger(String key, int value);
85
86  /**
87   * Sets one of the boolean constants
88   * @param key one of the boolean constants defined in this class
89   * @param value new boolean value of this setting
90   */
91  public abstract void setBoolean(String key, boolean value);
92
93  /**
94   * gets a new default Configuration
95   * @return Configuration
96   */
97  public static final Configuration getConfiguration() {
98    return getConfiguration(null);
99  }
100
101  /**
102   * Returns a new instance of a Configuration class
103   * @param className - the class to return, must be based on Configuration
104   * @return Configuration
105   */
106  public static final Configuration getConfiguration(String className) {
107
108    Configuration result;
109
110    if (className != null && className.length() > 0) {
111      try {
112        result = (Configuration) Class.forName(className).newInstance();
113      } catch (InstantiationException e) {
114        result = new PropertyConfiguration();
115      } catch (IllegalAccessException e) {
116        result = new PropertyConfiguration();
117      } catch (ClassNotFoundException e) {
118        result = new PropertyConfiguration();
119      }
120    } else {
121      result = new PropertyConfiguration();
122    }
123    return result;
124  }
125}
Note: See TracBrowser for help on using the repository browser.