You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@opennlp.apache.org by "Prachi Prakash (JIRA)" <ji...@apache.org> on 2017/12/31 11:32:00 UTC

[jira] [Updated] (OPENNLP-1176) opennlp.tools.ngram.NGramGenerator.java

     [ https://issues.apache.org/jira/browse/OPENNLP-1176?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Prachi Prakash updated OPENNLP-1176:
------------------------------------
    Description: 
Hello All,

I am new to opennlp and was looking to NGramGenerator.java where I found this piece of code which creates a list of n-grams from a list of words or characters. 
for (int i = 0; i < input.size() - (n - 2); i++) {
      final StringBuilder sb = new StringBuilder();
      if ((i + n) <= input.size()) {
        for (int x = i; x < (n + i); x++) {
          sb.append(input.get(x));
          sb.append(separator);
        }
        String gram = sb.toString();
        gram = gram.substring(0, gram.lastIndexOf(separator));
        outGrams.add(gram);
      }
    }

which can be modified to 
for (int i = 0; i < input.size() - (n - 1); i++) {
      final StringBuilder sb = new StringBuilder();
      
      for (int x = i; x < (n + i); x++) {
        sb.append(input.get(x));
        sb.append(separator);
      }
      String gram = sb.toString();
      gram = gram.substring(0, gram.lastIndexOf(separator));
      outGrams.add(gram);
      
    }
which will save some comparison can anyone please guide this is not being done.

Thanks,
Prachi Prakash 

  was:
Hello All,

I am new to opennlp and was looking to NGramGenerator.java where I found this piece of code which creates a list of n-grams from a list of words or characters. 

for (int i = 0; i < input.size() - (n - 1); i++) {
      final StringBuilder sb = new StringBuilder();
      
      for (int x = i; x < (n + i); x++) {
        sb.append(input.get(x));
        sb.append(separator);
      }
      String gram = sb.toString();
      gram = gram.substring(0, gram.lastIndexOf(separator));
      outGrams.add(gram);
      
    }
which can be modified to 
for (int i = 0; i < input.size() - (n - 1); i++) {
      final StringBuilder sb = new StringBuilder();
      
      for (int x = i; x < (n + i); x++) {
        sb.append(input.get(x));
        sb.append(separator);
      }
      String gram = sb.toString();
      gram = gram.substring(0, gram.lastIndexOf(separator));
      outGrams.add(gram);
      
    }
which will save some comparison can anyone please guide this is not being done.

Thanks,
Prachi Prakash 


> opennlp.tools.ngram.NGramGenerator.java 
> ----------------------------------------
>
>                 Key: OPENNLP-1176
>                 URL: https://issues.apache.org/jira/browse/OPENNLP-1176
>             Project: OpenNLP
>          Issue Type: Question
>            Reporter: Prachi Prakash
>            Priority: Trivial
>
> Hello All,
> I am new to opennlp and was looking to NGramGenerator.java where I found this piece of code which creates a list of n-grams from a list of words or characters. 
> for (int i = 0; i < input.size() - (n - 2); i++) {
>       final StringBuilder sb = new StringBuilder();
>       if ((i + n) <= input.size()) {
>         for (int x = i; x < (n + i); x++) {
>           sb.append(input.get(x));
>           sb.append(separator);
>         }
>         String gram = sb.toString();
>         gram = gram.substring(0, gram.lastIndexOf(separator));
>         outGrams.add(gram);
>       }
>     }
> which can be modified to 
> for (int i = 0; i < input.size() - (n - 1); i++) {
>       final StringBuilder sb = new StringBuilder();
>       
>       for (int x = i; x < (n + i); x++) {
>         sb.append(input.get(x));
>         sb.append(separator);
>       }
>       String gram = sb.toString();
>       gram = gram.substring(0, gram.lastIndexOf(separator));
>       outGrams.add(gram);
>       
>     }
> which will save some comparison can anyone please guide this is not being done.
> Thanks,
> Prachi Prakash 



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)