Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Home

Gleb Mazovetskiy edited this page · 15 revisions
Clone this wiki locally

Matrix Transforms Supported

  • Latent semantic analysis (LSA)
    search = Semantic::Search.new(documents, :transforms => [:LSA])
  • Term frequency – inverse document frequency (TFIDF)
    search = Semantic::Search.new(documents, :transforms => [:TFIDF])

Custom Matrix transforms

All matrix transforms live in:

rsemantic/lib/semantic/transform/*

Add a new class for your transform here. It requires a single class method which is passed a matrix and it should return a matrix.

So as an example adding a PLSA transform our class would look like this:

module Semantic
  module Transform
    class PLSA

      def self.transform(matrix)
        matrix
      end      

    end
  end
end

And then to use the transform we pass the class name in as a symbol when creating the search object.

search = Semantic::Search.new(documents, :transforms => [:PLSA])

Search Usage

documents = ["The cat in the hat disabled", 
             "A cat is a fine pet ponies.", 
             "Do and cats make good pets.",
             "I haven't got a hat."]

#Log to stdout how the matrix gets built and transformed
search = Semantic::Search.new(documents, :verbose => true)

#Defaults to performing :TFIDF and then :LSA
search = Semantic::Search.new(documents)

#Find documents that are related to documents[0] with a ranking for how related they are.
puts search.related(0)

#Search documents for the word cat. 
#Returns a ranking for how relevant the matches where for each document.
puts search.search(["cat"])
Something went wrong with that request. Please try again.