filtra 0.0.1
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 +7 -0
- data/.gitignore +0 -0
- data/LICENSE +19 -0
- data/README.md +20 -0
- data/filtra.gemspec +15 -0
- data/lib/Filtra/text.rb +18 -0
- data/lib/filtra.rb +22 -0
- data/makefile +2 -0
- data/tests/filtra_test.rb +25 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ccc63236a847c7b4c2347971bfe34c9f1d626ffd
|
4
|
+
data.tar.gz: 07314242e0e61a2c2ca4864595c19ff465eecfe9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 028302d2483b95f9d1cdd5ef5dcd1b6473c3e6396df55782345bc2c69573973436280a20888cc0afb224d32229b4515816c898b9b6850ae215ab3bf64a29e4fd
|
7
|
+
data.tar.gz: 056aa38ab2ad934be534801f89b02866c9352a93a66237f8b759f8662fabfd81ae24da1ff1b8198ff9c074d86d8fda7b01b8a9cf3c7f7d2a3c3ed12497bf7c6b
|
data/.gitignore
ADDED
File without changes
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2012 Julián Porta
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Filtra
|
2
|
+
====
|
3
|
+
|
4
|
+
Filtra filters arrays of tokens to be indexed.
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
|
9
|
+
Filtra filters arrays of tokens to be indexed by [Busca](https://github.com/Porta/busca), the simple redis search. The basic filtering options include downcasing and stemming (using [fast-stemmer](https://github.com/romanbsd/fast-stemmer))
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
As usual, you can install it using rubygems.
|
14
|
+
|
15
|
+
```
|
16
|
+
$ gem install filtra
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
data/filtra.gemspec
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "filtra"
|
5
|
+
s.version = "0.0.1"
|
6
|
+
s.summary = "Filtra filters an array of tokens to be indexed"
|
7
|
+
s.description = "Filtra filters an array of tokens or words so they can be indexed by Busca, the simple redis search"
|
8
|
+
s.authors = ["Julián Porta"]
|
9
|
+
s.email = ["julian@porta.sh"]
|
10
|
+
s.homepage = "https://github.com/Porta/filtra"
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.license = "MIT"
|
13
|
+
s.add_development_dependency "cutest", '~>1.2'
|
14
|
+
s.add_runtime_dependency "fast-stemmer", '~>1.0'
|
15
|
+
end
|
data/lib/Filtra/text.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Filtra
|
2
|
+
module Text
|
3
|
+
require 'fast-stemmer'
|
4
|
+
|
5
|
+
def self.call(words, opts)
|
6
|
+
out = []
|
7
|
+
keep_case = opts[:keep_case] || false
|
8
|
+
stem = opts[:stem] || false
|
9
|
+
# keep case
|
10
|
+
# stemm
|
11
|
+
words.each do |word|
|
12
|
+
word.downcase! unless keep_case
|
13
|
+
out.push( stem ? word.stem : word)
|
14
|
+
end
|
15
|
+
out.uniq
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/filtra.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
class Filtra
|
2
|
+
|
3
|
+
Dir[File.dirname(__FILE__) + '/Filtra/*.rb'].each {|file| require file }
|
4
|
+
|
5
|
+
attr_reader :filtro
|
6
|
+
|
7
|
+
def initialize(filtro = Filtra::Text, opts = {})
|
8
|
+
if filtro.respond_to?(:call)
|
9
|
+
@filtro = filtro
|
10
|
+
@opts = opts
|
11
|
+
else
|
12
|
+
@filtro = Filtra::Text
|
13
|
+
@opts = filtro
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(words)
|
18
|
+
@filtro.call(words, @opts)
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
end
|
data/makefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path("../lib/filtra", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
|
4
|
+
test "Filtra::Text should filter, stem and keep case some words" do
|
5
|
+
filtro = Filtra.new(stem: true, keep_case: true)
|
6
|
+
words = %w(Running fishes Among the coast line coast)
|
7
|
+
result = filtro.call(words)
|
8
|
+
assert_equal result, %w(Run fish Among the coast line)
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
test "Filtra::Text should filter, stem and downcase some words" do
|
13
|
+
filtro = Filtra.new(stem: true)
|
14
|
+
words = %w(Running fishes Among the Coast line coast)
|
15
|
+
result = filtro.call(words)
|
16
|
+
assert_equal result, %w(run fish among the coast line)
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
test "Filtra::Text should filter and downcase some words" do
|
21
|
+
filtro = Filtra.new(keep_case: true)
|
22
|
+
words = %w(Running fishes Among the Coast line coast)
|
23
|
+
result = filtro.call(words)
|
24
|
+
assert_equal result, %w(Running fishes Among the Coast line coast)
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: filtra
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Julián Porta
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cutest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fast-stemmer
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
description: Filtra filters an array of tokens or words so they can be indexed by
|
42
|
+
Busca, the simple redis search
|
43
|
+
email:
|
44
|
+
- julian@porta.sh
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- filtra.gemspec
|
53
|
+
- lib/Filtra/text.rb
|
54
|
+
- lib/filtra.rb
|
55
|
+
- makefile
|
56
|
+
- tests/filtra_test.rb
|
57
|
+
homepage: https://github.com/Porta/filtra
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.4.6
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Filtra filters an array of tokens to be indexed
|
81
|
+
test_files: []
|