Skip to content
michael chrisco edited this page Aug 21, 2015 · 16 revisions

Matrix Transforms Supported

  • Latent semantic analysis (LSA)
    search = RSemantic::Search.new(documents, :transforms => [:LSA])
  • Term frequency – inverse document frequency (TFIDF)
    search = RSemantic::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 RSemantic
  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 = RSemantic::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 = RSemantic::Search.new(documents, :verbose => true)

#Defaults to performing :TFIDF and then :LSA
search = RSemantic::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"])
Clone this wiki locally