Permalink
Browse files

Replaced use of Hashtable with Hashmap in Issue and friends.

  • Loading branch information...
1 parent 314155f commit 2b588fb7a7bc669ab5ce642dd8bd1b2845b2ec43 @subbuss committed May 14, 2012
@@ -2,7 +2,7 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Hashtable;
+import java.util.HashMap;
import java.util.List;
import java.util.Set;
@@ -126,7 +126,7 @@ public Category getParent()
public Category clone() { setupAllFields(); return super.clone(); }
protected void setupForDownloading(Issue issue) { setupAllFields(); super.setupForDownloading(issue); }
protected void collectUsedConcepts(Set<Concept> usedConcepts) { setupAllFields(); super.collectUsedConcepts(usedConcepts); }
- public synchronized Score getMatchScore(final NewsItem article, final int numTokens, final Hashtable matchScores) { setupAllFields(); return super.getMatchScore(article, numTokens, matchScores); }
+ public synchronized Score getMatchScore(final NewsItem article, final int numTokens, final HashMap<String,Score> matchScores) { setupAllFields(); return super.getMatchScore(article, numTokens, matchScores); }
// public String getTaxonomy() { setupAllFields; return super.getTaxonomy(); }
//
public Category getCategory(final String catName) { getChildren(); return super.getCategory(catName); }
@@ -4,7 +4,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
-import java.util.Hashtable;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -434,7 +434,7 @@ else if (!isLeafCategory()) {
* If a non-leaf category, the match score is the
* maximum of match score of its sub-categories
*/
- public synchronized Score getMatchScore(NewsItem article, int numTokens, Hashtable matchScores)
+ public synchronized Score getMatchScore(NewsItem article, int numTokens, HashMap<String, Score> matchScores)
{
if (_log.isDebugEnabled()) _log.debug(" --> get match score for " + _name);
@@ -3,7 +3,6 @@
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -87,7 +86,7 @@ public final static void resetMinScores()
public String getRuleString() { return _ruleString; }
public int getMinMatchScore() { return _minMatchScore; }
- public int getMatchScore(NewsItem article, int numTokens, Hashtable matchScores)
+ public int getMatchScore(NewsItem article, int numTokens, HashMap<String, Score> matchScores)
{
try {
return _rule.getMatchScore(this, article, numTokens, matchScores);
@@ -121,7 +120,7 @@ public int getMatchScore(NewsItem article, int numTokens, Hashtable matchScores)
abstract public String toString();
abstract public void print(PrintWriter pw);
abstract public void collectUsedConcepts(Set<Concept> usedConcepts);
- abstract public int getMatchScore(Filter f, NewsItem article, int numTokens, Hashtable matchScores);
+ abstract public int getMatchScore(Filter f, NewsItem article, int numTokens, HashMap<String,Score> matchScores);
}
/* class LeafConcept encodes a leaf concept */
@@ -140,7 +139,7 @@ public int getMatchScore(NewsItem article, int numTokens, Hashtable matchScores)
public void print(PrintWriter pw) { pw.println(_indent + _concept.getLexerToken().getToken() + (_minConceptHitScore == 1 ? "" : ":" + _minConceptHitScore)); }
public void collectUsedConcepts(final Set<Concept> usedConcepts) { usedConcepts.add(_concept); }
- public int getMatchScore(Filter f, NewsItem article, int numTokens, Hashtable matchScores)
+ public int getMatchScore(Filter f, NewsItem article, int numTokens, HashMap<String,Score> matchScores)
{
Score mc = (Score)matchScores.get(_concept.getLexerToken().getToken());
int score = ((mc == null) ? 0 : mc.value());
@@ -160,7 +159,7 @@ public int getMatchScore(Filter f, NewsItem article, int numTokens, Hashtable ma
public String toString() { return "[" + _filt.getName() + "]"; }
public void print(PrintWriter pw) { pw.println(_indent + _filt.getName()); }
public void collectUsedConcepts(final Set<Concept> usedConcepts) { _filt.collectUsedConcepts(usedConcepts); }
- public int getMatchScore(Filter f, NewsItem article, int numTokens, Hashtable matchScores) { return _filt.getMatchScore(article, numTokens, matchScores); }
+ public int getMatchScore(Filter f, NewsItem article, int numTokens, HashMap<String,Score> matchScores) { return _filt.getMatchScore(article, numTokens, matchScores); }
}
/* class SourceFilter encodes a source filter */
@@ -175,7 +174,7 @@ public int getMatchScore(Filter f, NewsItem article, int numTokens, Hashtable ma
public String toString() { return "[" + _srcColl.getName() + "]"; }
public void print(PrintWriter pw) { pw.println(_indent + _srcColl.getName()); }
public void collectUsedConcepts(final Set<Concept> usedConcepts) { }
- public int getMatchScore(Filter f, NewsItem article, int numTokens, Hashtable matchScores) {
+ public int getMatchScore(Filter f, NewsItem article, int numTokens, HashMap<String,Score> matchScores) {
return _srcColl.containsFeed(article.getFeed()) ? GLOBAL_MIN_MATCH_SCORE : 0;
}
}
@@ -193,7 +192,7 @@ public int getMatchScore(Filter f, NewsItem article, int numTokens, Hashtable ma
public void print(PrintWriter pw) { pw.println(_indent + _cat.getName()); }
public void collectUsedConcepts(Set<Concept> usedConcepts) { }
- public int getMatchScore(Filter f, NewsItem article, int numTokens, Hashtable matchScores)
+ public int getMatchScore(Filter f, NewsItem article, int numTokens, HashMap<String,Score> matchScores)
{
// FIXME: Use hashcode instead!
Score mc = (Score)matchScores.get("[" + _cat.getName() + "]");
@@ -249,7 +248,7 @@ public void collectUsedConcepts(final Set<Concept> usedConcepts)
_r.collectUsedConcepts(usedConcepts);
}
- public int getMatchScore(Filter f, NewsItem article, int numTokens, Hashtable matchScores)
+ public int getMatchScore(Filter f, NewsItem article, int numTokens, HashMap<String,Score> matchScores)
{
// First, check if the context matches
boolean contextMatched = false;
@@ -282,7 +281,7 @@ public int getMatchScore(Filter f, NewsItem article, int numTokens, Hashtable ma
public void print(PrintWriter pw) { pw.println(_indent + "-" + _t); }
public void collectUsedConcepts(final Set<Concept> usedConcepts) { _t.collectUsedConcepts(usedConcepts); }
- public int getMatchScore(Filter f, NewsItem article, int numTokens, Hashtable matchScores)
+ public int getMatchScore(Filter f, NewsItem article, int numTokens, HashMap<String,Score> matchScores)
{
// FIXME: This is very strict!
final int score = (1 - _t.getMatchScore(f, article, numTokens, matchScores));
@@ -324,7 +323,7 @@ public void collectUsedConcepts(final Set<Concept> usedConcepts)
_rTerm.collectUsedConcepts(usedConcepts);
}
- public int getMatchScore(Filter f, NewsItem article, int numTokens, Hashtable matchScores)
+ public int getMatchScore(Filter f, NewsItem article, int numTokens, HashMap<String,Score> matchScores)
{
final int lscore = _lTerm.getMatchScore(f, article, numTokens, matchScores);
final int rscore = _rTerm.getMatchScore(f, article, numTokens, matchScores);
@@ -359,7 +358,7 @@ public void print(PrintWriter pw)
pw.println(_indent + _c1.getLexerToken().getToken() + " ~" + _proximityVal + " " + _c2.getLexerToken().getToken());
}
- public int getMatchScore(Filter f, NewsItem article, int numTokens, Hashtable matchScores)
+ public int getMatchScore(Filter f, NewsItem article, int numTokens, HashMap<String,Score> matchScores)
{
Score s1 = (Score)matchScores.get(_c1.getLexerToken().getToken());
Score s2 = (Score)matchScores.get(_c2.getLexerToken().getToken());
@@ -13,7 +13,6 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -65,7 +64,7 @@
// Populate the table of predefined keywords with the
// corresponding JFLEX macros.
- public static Hashtable PREDEFINED_KEYWORDS;
+ public static HashMap PREDEFINED_KEYWORDS;
public static final String JFLEX_SPACE = "\" {SPACE} \"";
public static final String JFLEX_HYPHEN = "\" {HYPHEN} \"";
@@ -82,7 +81,7 @@
public static void init(DB_Interface db)
{
- PREDEFINED_KEYWORDS = new Hashtable();
+ PREDEFINED_KEYWORDS = new HashMap();
int n = PREDEF_KWORDS.length;
for (int i = 0; i < n; i += 2) {
PREDEFINED_KEYWORDS.put(PREDEF_KWORDS[i], PREDEF_KWORDS[i+1]);
@@ -102,7 +101,7 @@ private static int copyPredefinedKeyword(StringBuffer re, int i, char[] cs)
return i;
}
- private static HashSet processKeywordSubstringList(Hashtable<String,HashSet> kwToCptMap, String rootKw, String newWord, HashSet kwsh)
+ private static HashSet processKeywordSubstringList(HashMap<String,HashSet> kwToCptMap, String rootKw, String newWord, HashSet kwsh)
{
HashSet kwshNew = new HashSet();
@@ -145,7 +144,7 @@ private static HashSet processKeywordSubstringList(Hashtable<String,HashSet> kwT
* among the existing keyword set. This keyword has been
* canonicalized to lower-case!
*/
- private static void identifyMultiTokens(Hashtable kwToCptMap, String kw)
+ private static void identifyMultiTokens(HashMap<String,HashSet> kwToCptMap, String kw)
{
if (_log.isDebugEnabled()) _log.debug("IdentifyMultiTokens for " + kw);
@@ -247,7 +246,7 @@ private static void gen_JFLEX_RegExp(String kword, StringBuffer buf)
buf.append("\"");
}
- private static void gen_JFLEX_RegExps(Concept c, PrintWriter pw, Hashtable kwToCptMap)
+ private static void gen_JFLEX_RegExps(Concept c, PrintWriter pw, HashMap<String,HashSet> kwToCptMap)
{
if (_log.isDebugEnabled()) _log.debug("GJRE: Generating regexp for " + c.getName());
@@ -275,7 +274,7 @@ private static void gen_JFLEX_RegExps(Concept c, PrintWriter pw, Hashtable kwToC
}
}
- private static void processMatchedConcept(String token, String matchedText, int tokenPosn, Hashtable tokTable, PrintWriter pw)
+ private static void processMatchedConcept(String token, String matchedText, int tokenPosn, HashMap<String,Score> tokTable, PrintWriter pw)
{
// Increment match score of the matched concept and record information
// about where in the article it was found
@@ -784,7 +783,7 @@ public void gen_JFLEX_RegExps()
}
// Identify all keywords
- Hashtable<String,HashSet> kwToCptMap = new Hashtable<String,HashSet>();
+ HashMap<String,HashSet> kwToCptMap = new HashMap<String,HashSet>();
for (Iterator<Concept> e = getUsedConcepts(); e.hasNext(); ) {
Concept c = e.next();
Iterator<String> it = c.getKeywords();
@@ -806,16 +805,15 @@ public void gen_JFLEX_RegExps()
// "water privatisation" is present in one concept and "water" is
// present in another concept, when "water privatisation" is seen
// in the text, both the concepts should be triggered.
- for (Enumeration<String> e = kwToCptMap.keys(); e.hasMoreElements(); )
- identifyMultiTokens(kwToCptMap, e.nextElement());
+ for (String s: kwToCptMap.keySet())
+ identifyMultiTokens(kwToCptMap, s);
// Spit out regular tokens for concepts
for (Iterator<Concept> e = getUsedConcepts(); e.hasNext(); )
gen_JFLEX_RegExps(e.next(), pw, kwToCptMap);
// Spit out multi-tokens
- for (Enumeration<String> e = kwToCptMap.keys(); e.hasMoreElements(); ) {
- String kw = e.nextElement();
+ for (String kw: kwToCptMap.keySet()) {
HashSet hs = kwToCptMap.get(kw);
if (hs.size() > 1)
genMultiToken_JFLEX_RegExp(pw, kw, hs);
@@ -927,7 +925,7 @@ public void compileScanners(String workDir)
* @param numTokens number of tokens encountered
* @param tokTable the table of recognized tokens/concepts
*/
- public void classifyArticle(NewsItem ni, int numTokens, Hashtable tokTable)
+ public void classifyArticle(NewsItem ni, int numTokens, HashMap tokTable)
{
int matchScore = 0;
ArrayList<Category> matchedCats = new ArrayList<Category>();
@@ -958,7 +956,7 @@ public void classifyArticle(NewsItem ni, int numTokens, Hashtable tokTable)
* Fetch the news item that is stored in 'newsItemFileName', examine the tokens
* in 'tokTable', and classify the news item accordingly.
*/
- private void classifyArticle(String newsItemFileName, Hashtable tokTable, Hashtable newsTable, List allArts, List unclassifiedArts)
+ private void classifyArticle(String newsItemFileName, HashMap tokTable, HashMap newsTable, List allArts, List unclassifiedArts)
{
NewsItem ni = (NewsItem)newsTable.get(newsItemFileName);
if (ni == null) {
@@ -988,7 +986,7 @@ private void initScanner(Reader r, String workDir) throws Exception
}
}
- private int scanNewsItem(PrintWriter pw, Hashtable tokTable) throws Exception
+ private int scanNewsItem(PrintWriter pw, HashMap<String,Score> tokTable) throws Exception
{
_scannerInUse = true;
int numTokens = 0;
@@ -1108,7 +1106,7 @@ private void scanAndClassifyNewsItems(Feed f, Collection<NewsItem> newsItems, bo
Reader r = null;
try {
- Hashtable tokTable = new Hashtable();
+ HashMap<String,Score> tokTable = new HashMap<String,Score>();
r = ni.getReader();
initScanner(r, workDir);
int numTokens = scanNewsItem(pw, tokTable);
@@ -1271,7 +1269,7 @@ public static void main(String[] args)
Reader r = new java.io.FileReader(args[1]);
PrintWriter pw = new PrintWriter(args[0] + ".tokens");
i.initScanner(r, null);
- i.scanNewsItem(pw, new Hashtable());
+ i.scanNewsItem(pw, new HashMap<String,Score>());
r.close();
pw.close();
}

0 comments on commit 2b588fb

Please sign in to comment.