Skip to content

Instantly share code, notes, and snippets.

@kamoo1
Last active August 29, 2015 14:18
Show Gist options
  • Save kamoo1/bea1b90b847edb64c8ff to your computer and use it in GitHub Desktop.
Save kamoo1/bea1b90b847edb64c8ff to your computer and use it in GitHub Desktop.
JWNL WordNet dictionary to map with usage count
Use mapped WordNet dictionary can boost speed alot, in JWNL there is an convert method that can create mapped dictionary files, however there it does not support usage count.
#To convert dictionary to map#
In Windows:
java -cp jwnl.jar;utilities.jar;commons-logging.jar net.didion.jwnl.utilities.DictionaryToMap <destination directory> <property file>
In unix-like systems:
java -cp jwnl.jar:utilities.jar:commons-logging.jar net.didion.jwnl.utilities.DictionaryToMap <destination directory> <property file>
#Make your own usage map#
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class WNUsageCountMap {
Map<String, Integer> countMap;
public static void main(String[] args) {
WNUsageCountMap cm = new WNUsageCountMap("index.sense");
System.out.println(cm.getUseageCount("sea%1:17:00::"));
}
WNUsageCountMap(String path){
System.err.println("Loading count map..");
countMap = new HashMap<String, Integer>();
try {
BufferedReader br = new BufferedReader(new FileReader(path));
String line;
while( (line = br.readLine()) != null ){
String[] tkns = line.split(" ");
String senseKey = tkns[0];
int count = Integer.parseInt(tkns[3]);
countMap.put(senseKey, count);
}
br.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public int getUseageCount(String senseKey) {
return this.countMap.get(senseKey);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment