shookach 0.0.1 → 0.0.2
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/lib/shookach/indexer.rb +36 -34
- data/lib/shookach/railtie.rb +1 -1
- data/lib/shookach/searcher.rb +4 -2
- data/lib/shookach.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 865cd6643ebbfc5adc8f873a9c7f9b7e5a91fb5f719f03985541aa6cbcd7ef3d
|
|
4
|
+
data.tar.gz: 35c647ccc636e9441cd2df6d5c1dcc0ccb19eb38cd10b1520b5ee0594940b3d0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aeabad7c1dcd7daed2824662243d27f84ab9d7bc320b4df51bae527a321d56814e5e51135a92cc59aa8c29f664fddaa2c1717c8cbf52fd7e8baf7a7377995f4d
|
|
7
|
+
data.tar.gz: d8aca686d11a684a45f8f0c45b9e4515ec6fad2f9f8d1cc320ccfbba655b5c84e0445c8da9068be0d953bb06653e41bf0125c27dc89d64420a347f009fbef86e
|
data/lib/shookach/indexer.rb
CHANGED
|
@@ -1,52 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
module Shookach
|
|
2
|
+
class Indexer
|
|
3
|
+
def initialize(library_path, output_path)
|
|
4
|
+
@library_path = library_path
|
|
5
|
+
create_index_file(output_path)
|
|
6
|
+
end
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
def call
|
|
9
|
+
write_dir_indexes
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
@output_file.close
|
|
12
|
+
end
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
private
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
def create_index_file(path)
|
|
17
|
+
Dir.mkdir(path) unless File.exists?(path)
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
@output_file = File.open("#{path}indexes#{Time.now.strftime('%Y%m%d%H%M%S')}.yml", 'w')
|
|
20
|
+
end
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
def write_dir_indexes
|
|
23
|
+
puts "Indexing directory: #{@library_path}"
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
Dir.foreach(@library_path) do |filename|
|
|
26
|
+
next if filename == '.' || filename == '..'
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
write_file_indexes(filename)
|
|
29
|
+
end
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
puts "Output file: #{@output_file.path}"
|
|
32
|
+
end
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
def write_file_indexes(filename)
|
|
35
|
+
puts "Indexing file: #{filename}"
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
@file = File.open("#{@library_path}/#{filename}", 'r')
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
sentences_arr.each_with_index do |sentence, s_index|
|
|
40
|
+
words = sentence.split(' ')
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
words.each_with_index do |word, w_index|
|
|
43
|
+
@output_file.write("#{word}:\r file: #{filename}\r sentence: #{s_index}\r word: #{w_index}\n")
|
|
44
|
+
end
|
|
43
45
|
end
|
|
44
|
-
end
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
@file.close
|
|
48
|
+
end
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
def sentences_arr
|
|
51
|
+
@file.read().gsub(',', ' ').gsub(/\n|\r/, ' ').split(/\.\s*/)
|
|
52
|
+
end
|
|
51
53
|
end
|
|
52
54
|
end
|
data/lib/shookach/railtie.rb
CHANGED
data/lib/shookach/searcher.rb
CHANGED
data/lib/shookach.rb
CHANGED
|
@@ -2,15 +2,15 @@ require 'shookach/indexer'
|
|
|
2
2
|
require 'shookach/searcher'
|
|
3
3
|
require 'shookach/railtie' if defined?(Rails)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
module Shookach
|
|
6
6
|
def self.index(options = {})
|
|
7
7
|
@options = default_configs.merge(options)
|
|
8
8
|
|
|
9
|
-
Indexer.new(@options[:library_path], @options[:output_path]).call
|
|
9
|
+
Shookach::Indexer.new(@options[:library_path], @options[:output_path]).call
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def self.search
|
|
13
|
-
#
|
|
13
|
+
# Shookach::Searcher.new
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
private
|