Sha256: c533fea51b91d1958e07f994f542d026b7d5799b5ead6cd2f9796c91be0b877f

Contents?: true

Size: 1.02 KB

Versions: 6

Compression:

Stored size: 1.02 KB

Contents

require File.dirname(__FILE__) + '/../../spec_helper'

module Semantic
  describe Transform::TFIDF do

    def matrix(matrix)
      Linalg::DMatrix.rows(matrix)
    end

    tiny_matrix = Linalg::DMatrix.rows([[0.0, 1.0, 0.0],
    [1.0, 0.0, 1.0]])

    describe "term frequency / inverse document frequency transform" do

      it "should find the number of times each term occurs" do
        Transform::TFIDF.should_receive(:number_of_documents_with_term).with(0, matrix([[1]])).and_return(2)

        Transform::TFIDF.transform(matrix([[1]]))
      end

      it "should ignore counting terms with 0 weighting" do
        Transform::TFIDF.should_not_receive(:number_of_documents_with_term)

        Transform::TFIDF.transform(matrix([[0,0],[0,0]]))
      end

      it "should calculate term frequency * inverse document freuency" do
        transformed_matrix = Transform::TFIDF.transform matrix([[1,1],[0,1]])

        transformed_matrix.to_s.should == Linalg::DMatrix.columns([[0, 0],[0, 0.346574]]).to_s
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
josephwilk-rsemantic-0.1.0 spec/semantic/transform/tf_idf_transform_spec.rb
josephwilk-rsemantic-0.1.1 spec/semantic/transform/tf_idf_transform_spec.rb
josephwilk-rsemantic-0.1.2 spec/semantic/transform/tf_idf_transform_spec.rb
josephwilk-rsemantic-0.1.3 spec/semantic/transform/tf_idf_transform_spec.rb
josephwilk-semantic-0.1.0 spec/semantic/transform/tf_idf_transform_spec.rb
rsemantic-0.1.3 spec/semantic/transform/tf_idf_transform_spec.rb