spec/string_spec.rb in text_nlp-0.0.2 vs spec/string_spec.rb in text_nlp-0.0.3
- old
+ new
@@ -15,22 +15,41 @@
text.should eq "TOTO".downcase
normalizer.should_not_receive(:normalize).with(text)
text.normalize.should eq "TOTO".downcase
end
+ it "should normalize the receiver string" do
+ text = "TOTO"
+ normalizer = double()
+ String.normalizer = normalizer
+ normalizer.stub(:normalize) { |txt| txt.downcase }
+ text.normalize!
+ text.should eq "TOTO".downcase
+ text.normalized.should be_true
+ end
+
it "should call tokenizer" do
text = "TOTO"
tokenizer = double()
String.tokenizer = tokenizer
tokenizer.should_receive(:tokenize).with(text)
text.tokenize
end
- it "should call translator" do
+ it "should call translator / translators" do
text = "TOTO"
- translator = double()
- translator.should_receive(:translate).with(text)
- text.translate(translator)
+ transformer1 = double()
+ transformer1.should_receive(:transform).with(text)
+ text.transform(transformer1)
+ transformer1 = double()
+ transformer1.stub(:transform) { |text| text.tr("T","U") }
+ transformer2 = double()
+ transformer2.stub(:transform) { |text| text.tr("O","A") }
+ transformer1.should_receive(:transform).with("TOTO")
+ transformer2.should_receive(:transform).with("UOUO")
+ text = text.transform(transformer1,transformer2)
+ text.should eq "UAUA"
+ text.transform([transformer1,transformer2])
end
it "should compute similarity" do
"il fait chaud".similarity("il fait chaud").should eq 1.0
"il fait chaud".similarity("putin c nul ici").should eq 0.0
\ No newline at end of file