Commit 11914abb authored by Coraline Ehmke's avatar Coraline Ehmke

Stemming support for LOD

parent 53b5b57f
require 'uea-stemmer'
class Snuffle::LatentObject
include PoroPlus
......@@ -15,7 +17,8 @@ class Snuffle::LatentObject
"your", "good", "some", "could", "them", "see", "other", "than", "then",
"now", "look", "only", "come", "its", "over", "think", "also", "back", "else",
"after", "use", "two", "how", "our", "work", "first", "well", "way", "even",
"new", "want", "because", "any", "these", "give", "day", "most", "us", "call"
"new", "want", "because", "any", "these", "give", "day", "most", "us", "call",
"create", "edit", "new", "delete", "destroy", "update"
]
def self.from(nodes)
......@@ -30,8 +33,10 @@ class Snuffle::LatentObject
end
def self.extract_candidates(methods)
stemmer = UEAStemmer.new
methods.map(&:method_name).inject({}) do |words, method_name|
atoms = method_name.split('_') - STOPWORDS
atoms = atoms.map{|atom| stemmer.stem(atom.to_s)}
atoms.each{ |word| words[word] ||= []; words[word] << method_name }
words
end
......
module Snuffle
VERSION = "0.12.2"
VERSION = "0.13.0"
end
......@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "rouge"
spec.add_dependency "text-table"
spec.add_dependency "haml"
spec.add_dependency "uea-stemmer"
spec.add_development_dependency "bundler", "~> 1.6"
spec.add_development_dependency "rake"
......
......@@ -13,6 +13,22 @@ class Song
metadata[:playlist]
end
def artist_name?
self.artist && self.artist.name
end
def helpers
[helper]
end
def helper
Helper.new
end
def artist_name
artis_name? || "Unknown"
end
def can_be_downloaded?
metadata[:download]
end
......
......@@ -2,6 +2,7 @@ require 'spec_helper'
describe Snuffle::LatentObject do
let(:program_1) { Snuffle::SourceFile.new(path_to_file: "spec/fixtures/program_1.rb") }
let(:program_2) { Snuffle::SourceFile.new(path_to_file: "spec/fixtures/latent_object_fixture.rb") }
describe ".from" do
......@@ -24,14 +25,19 @@ describe Snuffle::LatentObject do
describe ".potential_objects_with_methods" do
let(:results) { Snuffle::LatentObject.potential_objects_with_methods(program_2.nodes) }
let(:results_set_1) { Snuffle::LatentObject.potential_objects_with_methods(program_1.nodes) }
let(:results_set_2) { Snuffle::LatentObject.potential_objects_with_methods(program_2.nodes) }
it "finds repeated words " do
expect(results.keys).to eq(["user"])
it "finds repeated words" do
expect(results_set_2.keys).to eq(["user"])
end
it "finds words by stem" do
expect(results_set_1['helper']).to eq(["helpers", "helper"])
end
it "finds methods that repeated words appear in" do
expect(results['user']).to eq(["user_name", "user_address", "user_email"])
expect(results_set_2['user']).to eq(["user_name", "user_address", "user_email"])
end
end
......
......@@ -3,6 +3,7 @@ require 'pry'
describe Snuffle::SourceFile do
let(:program_1) { Snuffle::SourceFile.new(path_to_file: "spec/fixtures/program_1.rb") }
let(:program_2) { Snuffle::SourceFile.new(path_to_file: "spec/fixtures/program_2.rb") }
let(:program_3) { Snuffle::SourceFile.new(path_to_file: "spec/fixtures/program_3.rb") }
let(:program_4) { Snuffle::SourceFile.new(path_to_file: "spec/fixtures/program_4.rb") }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment