本文介绍了词关联计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的java。我需要在句子中互相计数字关联。例如,对于句子Dog is a Dog and Cat is a Cat,最终关联计数将是$
第一行:Dog-Dog(0),Dog-is(2) a(2)狗和(1),狗 - 猫(2)

I am new to java. I need to count word associations with each other in a sentence. For example, for the sentence, "Dog is a Dog and Cat is a Cat", the final association count will be-The first row: Dog-Dog(0), Dog-is(2), Dog-a(2) Dog-and(1), Dog-Cat(2)

等。

它是一种开发关联矩阵。关于如何开发的任何建议?

It is kind of developing an association matrix. Any suggestion on how that can be developed?

推荐答案

感谢Roman。我可以分割句子中的单词 -

Thanks Roman. I can split the words from the sentences-

String sentence=null;
    String target="Dog is a Dog and Cat is a Cat";
    int index = 0;
    Locale currentLocale = new Locale ("en","US");
    BreakIterator wordIterator = BreakIterator.getWordInstance(currentLocale);
    //Creating the sentence iterator
    BreakIterator bi = BreakIterator.getSentenceInstance();
    bi.setText(target);

    while (bi.next() != BreakIterator.DONE) {

        sentence = target.substring(index, bi.current());
        System.out.println(sentence);
        wordIterator.setText(sentence);
        int start = wordIterator.first();
        int end = wordIterator.next();

        while (end!=BreakIterator.DONE){

            String word = sentence.substring(start,end);
             if (Character.isLetterOrDigit(word.charAt(0))) {

                System.out.println(word);

             }//if (Character.isLetterOrDigit(word.charAt(0)))

             start = end;
             end = wordIterator.next();
        }//while (end!=BreakIterator.DONE)
        index = bi.current();
    }  //  while (bi.next() != BreakIterator.DONE)

没有得到你的其他两点。谢谢。

But did not get your other two points. Thanks.

这篇关于词关联计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 20:50