Search code examples
nlpstanford-nlpn-grampos-tagger

CoreNLP API for N-grams?


Does CoreNLP have an API for getting unigrams, bigrams, trigrams, etc.?

For example, I have a string "I have the best car ". I would love to get:

I
I have
the
the best
car

based on the string I am passing.


Solution

  • If you are coding in Java, check out getNgrams* functions in the StringUtils class in CoreNLP.

    You can also use CollectionUtils.getNgrams (which is what StringUtils class uses too)