我将如何在 Java 之类的东西中编写一个共现类,该类需要一个充满 n-gram 的文件并计算给定输入项的单词共现。
是否有任何库或包可以与 Lucene(索引)或类似 Hadoop 中 n-gram 列表上的 map-reduce 的东西一起使用..?
谢谢。
好的,假设您想在 ngram 文件中找到两个不同单词的共现......
这是伪代码式Java:
// Co-occurrence matrix
Hashmap<String,HashMap<String,Integer>> map = new HashMap();
// List of ngrams
ArrayList<ArrayList<String>> ngrams = ..... // assume we've loaded them into here already
// build the matrix
for(ArrayList<String> ngram:ngrams){
// Calculate word co-occurrence in ngram for all words
// result is an map strings-> count
// words in alphabetical order
Hashmap<String,<ArrayList<String>,Integer> wordCoocurrence = cooccurrence(ngram) // assume we have this
// then just join this with original
}
// and just query with words in alphabetic order
用 Pig 做这样的计数可能会很漂亮,但你可能比我更熟悉