louismullie / open-nlp

Ruby bindings to the OpenNLP Java toolkit.
Other
91 stars 11 forks source link

Span with Sentence detection #3

Closed yoshie902a closed 11 years ago

yoshie902a commented 11 years ago

Hi, firstly, thanks for the hard work on the wrapper!

Just one quick question. What is the syntax to do this...

Span sentences[] = sentenceDetector.sentDetect(" First sentence. Second sentence. ");

I need to input a sentence and get the sentence boundaries points as an index of start and stop locations.

I also need the sentences...

string sentences[] = sentenceDetector.sentDetect(" First sentence. Second sentence. ");

Looking through your examples, I was not too sure about sentence detection in this manner. Sorry if this is a basic question. I'm new to this. You examples, could have even shown it, but might be misunderstanding them.

thanks you!

louismullie commented 11 years ago

Hi,

Here's how:

text = "Put your sentences here."
segmenter = OpenNLP::SentenceDetectorME.new
sentences = segmenter.sent_pos_detect(text)

sentences.each do |sentence|
  start = sentence.get_start
  stop  = sentence.get_end-1
  str   = text[start..stop]
end

Cheers,

Louis