diviner 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/diviner.gemspec +3 -3
- data/lib/deviner/match.rb +15 -5
- data/test/helper.rb +2 -3
- data/test/test_diviner.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b394c94e959d168855fbdd58a40e2785acff6e5
|
4
|
+
data.tar.gz: c188f6c5c2d71aa2e33cfda62f04953b9437290c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8386e140b2cc549e5ba8c443d233abfb44a0ee90dfd2058f178fef00eef8341aaa1c3b811673ffb4d697b72e0cc9e2c3bee4b372ee26e7e521e9866c2f70045a
|
7
|
+
data.tar.gz: f3a1c90770ca1c9dff3b11616306d37a71adb1d573d1cb7fa66ee0f3dcc1b2082aea78988d7031cd5104c054a4c442dfba926fb72e124f6e1bccc97a3973c20b
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/diviner.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: diviner 0.1.
|
5
|
+
# stub: diviner 0.1.3 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "diviner"
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.3"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Ferhat Ziba"]
|
14
|
-
s.date = "2016-06-
|
14
|
+
s.date = "2016-06-14"
|
15
15
|
s.description = "It matches from a list of categories the right category to a Product."
|
16
16
|
s.email = "fero.ziba@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
data/lib/deviner/match.rb
CHANGED
@@ -62,6 +62,10 @@ module Deviner
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
result = result.reject{ |x| x[:value] != highest_value}
|
66
|
+
puts "ACHTUNG"
|
67
|
+
puts result
|
68
|
+
|
65
69
|
return selected_category
|
66
70
|
|
67
71
|
end
|
@@ -81,24 +85,30 @@ module Deviner
|
|
81
85
|
query = prepare_query(query)
|
82
86
|
return cache[query] if cache[query] != nil
|
83
87
|
search = Picky::Search.new @index
|
84
|
-
|
88
|
+
subqueries = query.split(" ")
|
89
|
+
total = 0
|
90
|
+
for subquery in subqueries
|
91
|
+
result = search.search(query)
|
92
|
+
total+=result.total
|
93
|
+
end
|
85
94
|
if options[:has_parent]
|
86
95
|
parent = category.send(options[:parent_method])
|
87
96
|
else
|
88
97
|
parent = nil
|
89
98
|
end
|
90
|
-
cache[query] =
|
99
|
+
cache[query] = total + score(parent)
|
91
100
|
end
|
92
101
|
|
93
102
|
def prepare_query query
|
94
|
-
query.gsub(",", "
|
95
|
-
gsub("&", "
|
103
|
+
query.gsub(",", " ").
|
104
|
+
gsub("&", " ").
|
96
105
|
gsub("ü", "ue").
|
97
106
|
gsub("ö", "oe").
|
98
107
|
gsub("ä", "ae").
|
99
108
|
gsub("Ü", "Ue").
|
100
109
|
gsub("Ö", "Oe").
|
101
|
-
gsub("Ä", "Ae")
|
110
|
+
gsub("Ä", "Ae").
|
111
|
+
gsub(" ", " ")
|
102
112
|
end
|
103
113
|
|
104
114
|
end
|
data/test/helper.rb
CHANGED
@@ -67,15 +67,14 @@ taxonomies.each_line do |line|
|
|
67
67
|
stack.pop
|
68
68
|
end
|
69
69
|
|
70
|
+
stack = [] if names.length == 1
|
71
|
+
|
70
72
|
parent = stack.last
|
71
73
|
category = TestCategory.new(names.last,parent)
|
72
74
|
stack.push(category)
|
73
75
|
@categories << category
|
74
76
|
end
|
75
77
|
|
76
|
-
|
77
|
-
puts @categories
|
78
|
-
|
79
78
|
class MyTestCategory
|
80
79
|
|
81
80
|
def self.categories=(categories)
|
data/test/test_diviner.rb
CHANGED
@@ -21,4 +21,18 @@ class TestDiviner < Test::Unit::TestCase
|
|
21
21
|
matcher.model(model, keys)
|
22
22
|
assert_equal "Massageöle", matcher.match(MyTestCategory.categories).name
|
23
23
|
end
|
24
|
+
|
25
|
+
should "find more complex testcase" do
|
26
|
+
Product = Struct.new :id, :name, :description, :categories
|
27
|
+
keys = [:name, :description, :categories]
|
28
|
+
weights = {categories: 3, name: 2, description: 1}
|
29
|
+
model = Product.new(1, "HiPP Gemüserisotto mit zarter Bio-Pute, 250 g",
|
30
|
+
"HiPP Gemüserisotto mit zarter Bio-Pute enthält schonend dampfgegarte Zutaten mit kindgerechter Würzung und Omega-3 Fettsäuren aus Bio-Rapsöl. Die Mahlzeit ist geeignet für eine sichere und ausgewogene Ernährung Ihres Babys ab dem12. Monat. mit Stückchenfürs Kauenlernen salzreduziert glutenfrei ohne Zusatz von Aromen, Konservierungsstoffen, Farbstoffen, Verdickungsmitteln",
|
31
|
+
"Baby & Kind Babynahrung Kindernahrung Beikost")
|
32
|
+
matcher = Deviner::Match.new(weights)
|
33
|
+
matcher.model(model, keys)
|
34
|
+
assert_equal "Babynahrung", matcher.match(MyTestCategory.categories).name
|
35
|
+
end
|
36
|
+
|
37
|
+
|
24
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diviner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ferhat Ziba
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-stemmer
|