我将如何编写一个类似于Java的共同出现类,其中包含一个充满n-gram的文件并计算给定输入项的单词共生。
是否有任何与Lucene一起使用的图书馆或软件包(索引)或类似于Hadoop中n-gram列表的map-reduce ...?
感谢。
答案 0 :(得分:2)
好的,假设您想在ngrams文件中找到两个不同单词的共现....
这是伪代码-theh 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
做这样的计数可能与猪相当,但你可能比我更熟悉