Sha256: 69de9493f2e97242775b77c625b32f73af44dc80e53894e2ea40c74298cde6eb

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

require "spec_helper"

describe OpenNlp::SentenceDetector do
  subject { OpenNlp::SentenceDetector }

  let(:model) { OpenNlp::Model::SentenceDetector.new(File.join(FIXTURES_DIR, "en-sent.bin")) }

  describe "initialization" do
    it "should initialize with a valid model" do
      sent_detector = subject.new(model)
      sent_detector.should be_a(subject)
      sent_detector.j_instance.should be_a(subject.java_class)
    end

    it "should raise an ArgumentError without a valid model" do
      lambda { subject.new(nil) }.should raise_error(ArgumentError)
    end
  end

  describe "#detect" do
    let(:sent_detector) { subject.new(model) }

    it "should detect no sentences in an empty string" do
      sentences = sent_detector.detect("")
      sentences.should == []
    end

    it "should detect sentences in a string" do
      sentences = sent_detector.detect("The sky is blue. The Grass is green.")
      sentences.should == ["The sky is blue.", "The Grass is green."]
    end

    it "should raise an ArgumentError for a non-string" do
      lambda { sent_detector.detect(nil) }.should raise_error(ArgumentError)
    end
  end

  describe "#pos_detect" do
    let(:sent_detector) { subject.new(model) }

    it "should detect sentences in a string" do
      sentences = sent_detector.pos_detect("The sky is blue. The Grass is green.")
      sentences.should == [OpenNlp::Util::Span.new(0, 16), OpenNlp::Util::Span.new(17, 36)]
    end

    it "should raise an ArgumentError for a non-string" do
      expect { sent_detector.detect(nil) }.to raise_error(ArgumentError)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
open_nlp-0.0.7-java spec/sentence_detector_spec.rb