trigrams
我在使用 Java时遇到了一些问题。我的程序目前可以bigrams
正常工作,但是当我尝试实现该方法的相同结构并对其进行更改以trigrams
使其似乎无法正常工作时。我希望在trigrams
中获得所有可能的单词组合arraylist
,例如
Original = [eye, test, find, free, nhs]
Trigram = [eye test find, 2, eye test free, 3, eye test nhs, 4, eye find free, 3, eye find nhs, 4, eye free nhs, 5, etc...]
这些数字决定了第一个单词和最后一个单词之间的距离,并且应该得到 3 中的每个单词组合arraylist
。这目前适用于bigrams
...
Original = [eye, test, find, free, nhs]
Bigram = [eye test, 1, eye find, 2, eye free, 3, eye nhs, 4, test find, 1, test free, 2, test nhs, 3, find free, 1, etc..]
以下是方法
public ArrayList<String> bagOfWords;
public ArrayList<String> bigramList = new ArrayList<String>();
public ArrayList<String> trigramList = new ArrayList<String>();
public void trigram() throws FileNotFoundException{
PrintWriter tg = new PrintWriter(new File(trigramFile));
// CREATES THE TRIGRAM
for (int i = 0; i < bagOfWords.size() - 1; i++) {
for (int j = 1; j < bagOfWords.size() - 1; j++) {
for(int k = j + 1; k < bagOfWords.size(); k++){
int distance = (k - i);
if (distance < 4){
trigramList.add(bagOfWords.get(i) + " " + bagOfWords.get(j) + " " + bagOfWords.get(k) + ", " + distance);
}
}
}
}
public void bigram() throws FileNotFoundException{
// CREATES THE BIGRAM
PrintWriter bg = new PrintWriter(new File(bigramFile));
for (int i = 0; i < bagOfWords.size() - 1; i++) {
for (int j = i + 1; j < bagOfWords.size(); j++) {
int distance = (j - i);
if (distance < 4){
bigramList.add(bagOfWords.get(i) + " " + bagOfWords.get(j) + ", " + distance);
}
}
}
谁能帮我改变trigram()
方法以创建适合trigram
我需要的方法?谢谢你的帮助。