我将如何着手编写一个类似 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 做这样的计数可能很不错,但你可能比我更熟悉
关于lucene - 单词共现 - 在一组 n-gram 中找到一个术语的共现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6510338/