phrase_lookup 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/phrase_lookup.rb +59 -58
- data.tar.gz.sig +0 -0
- metadata +35 -35
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1aefccf9a3e66b75245de27255b58f8d6f1e988263ec9f50599659bba92fb9ee
|
4
|
+
data.tar.gz: def447233c8586a549e3263fc6517ce37e84b8a08432a1e4f24bd5744d8029e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35aaa7dfc6255ae42eab66f57653d1d908b7a143093063dd067a2b3db8f3d8ec1451f5a7cd9af2b91d9ec89fb52582328726d1070e725705bd2363548d8037d4
|
7
|
+
data.tar.gz: e0c01ec4b69bafe5a849b6045476ce1f27b57f49887fe63a72dfb4a0f37bae70d9152589932cf384e39c9c53658adaeb010f50a03934ba9e426e9e2e2a6b352b
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/phrase_lookup.rb
CHANGED
@@ -6,127 +6,128 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
require 'yaml'
|
9
|
-
require '
|
9
|
+
require 'rxfreadwrite'
|
10
10
|
|
11
11
|
|
12
12
|
class PhraseLookup
|
13
13
|
|
14
|
-
def initialize(obj=nil, debug: false)
|
15
|
-
|
14
|
+
def initialize(obj=nil, debug: false)
|
15
|
+
|
16
16
|
@debug = debug
|
17
17
|
|
18
18
|
@master = if obj then
|
19
|
-
|
19
|
+
|
20
20
|
if obj.is_a? String then
|
21
|
-
|
22
|
-
s =
|
23
|
-
|
21
|
+
|
22
|
+
s = RXFReader.read(obj).first
|
23
|
+
|
24
24
|
if s.lstrip =~ /^---/ then # it's YAML
|
25
|
-
|
25
|
+
|
26
26
|
Master.new( YAML.load(s))
|
27
|
-
|
27
|
+
|
28
28
|
elsif s =~ /: / # it's the contents of a log file
|
29
|
-
|
29
|
+
|
30
30
|
m = Master.new
|
31
31
|
m.create s
|
32
32
|
m
|
33
|
-
|
33
|
+
|
34
34
|
else # it's plain text
|
35
|
-
|
35
|
+
|
36
36
|
m = Master.new
|
37
37
|
m.create_from_txt s
|
38
38
|
m
|
39
|
-
|
39
|
+
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
elsif obj.is_a? Array
|
43
|
-
|
43
|
+
|
44
44
|
puts 'array detected' if @debug
|
45
|
-
|
45
|
+
|
46
46
|
m = Master.new
|
47
47
|
m.parse_array obj
|
48
48
|
m
|
49
|
-
|
49
|
+
|
50
50
|
else
|
51
51
|
Master.new obj
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
|
57
57
|
end
|
58
|
-
|
59
|
-
class Master
|
60
|
-
|
58
|
+
|
59
|
+
class Master
|
60
|
+
include RXFReadWriteModule
|
61
|
+
|
61
62
|
def initialize(h={})
|
62
63
|
|
63
64
|
@h = h
|
64
|
-
|
65
|
+
|
65
66
|
end
|
66
|
-
|
67
|
+
|
67
68
|
def create(s)
|
68
|
-
|
69
|
+
|
69
70
|
@h = parse_log(s)
|
70
|
-
|
71
|
+
|
71
72
|
end
|
72
|
-
|
73
|
+
|
73
74
|
def create_from_txt(s)
|
74
|
-
|
75
|
+
|
75
76
|
@h = parse(s)
|
76
|
-
|
77
|
-
end
|
78
|
-
|
77
|
+
|
78
|
+
end
|
79
|
+
|
79
80
|
def update(s)
|
80
81
|
|
81
82
|
parse_log(s).each {|k,v| @h.has_key?(k) ? @h[k] += v : @h[k] = v }
|
82
83
|
|
83
84
|
end
|
84
|
-
|
85
|
+
|
85
86
|
def save(filename='master.yaml')
|
86
|
-
|
87
|
+
FileX.write filename, @h.sort.to_h.to_yaml
|
87
88
|
end
|
88
|
-
|
89
|
+
|
89
90
|
def to_h()
|
90
91
|
@h.clone
|
91
|
-
end
|
92
|
-
|
92
|
+
end
|
93
|
+
|
93
94
|
def parse(raw_s)
|
94
|
-
|
95
|
-
s, _ =
|
96
|
-
|
95
|
+
|
96
|
+
s, _ = RXFReader.read(raw_s)
|
97
|
+
|
97
98
|
a = s.downcase.gsub(/\?/,'').lines.map(&:strip).compact
|
98
99
|
a.uniq.inject({}) {|r,x| r.merge x => a.count(x)}
|
99
|
-
|
100
|
-
end
|
101
|
-
|
100
|
+
|
101
|
+
end
|
102
|
+
|
102
103
|
def parse_array(a)
|
103
|
-
|
104
|
+
|
104
105
|
@h = a.map {|x| x.downcase.gsub(/\?/,'')}\
|
105
106
|
.inject({}) {|r,x| r.merge x => a.count(x)}
|
106
|
-
|
107
|
-
end
|
108
|
-
|
107
|
+
|
108
|
+
end
|
109
|
+
|
109
110
|
def parse_log(raw_s)
|
110
|
-
|
111
|
-
s, _ =
|
112
|
-
|
113
|
-
a = s.downcase.gsub(/\?/,'').lines.map do |x|
|
111
|
+
|
112
|
+
s, _ = RXFReader.read(raw_s)
|
113
|
+
|
114
|
+
a = s.downcase.gsub(/\?/,'').lines.map do |x|
|
114
115
|
phrase = x.strip[/(?<=: )[^|]+(?= )/i]
|
115
116
|
phrase.length < 50 ? phrase : nil if phrase
|
116
117
|
end.compact
|
117
|
-
|
118
|
+
|
118
119
|
a.uniq.inject({}) {|r,x| r.merge x => a.count(x)}
|
119
|
-
|
120
|
+
|
120
121
|
end
|
121
122
|
end
|
122
123
|
|
123
124
|
def lookup(s, limit: 10, search_tags: false)
|
124
|
-
|
125
|
+
|
125
126
|
return [] if s.empty?
|
126
|
-
|
127
|
+
|
127
128
|
h = @master.to_h
|
128
129
|
a = h.keys
|
129
|
-
|
130
|
+
|
130
131
|
a3 = if search_tags then
|
131
132
|
a.grep /\].*(?:\b#{s}\b|\b#{s}).*\|.*(?:\b#{s}\b|\b#{s})/i
|
132
133
|
else
|
@@ -137,12 +138,12 @@ class PhraseLookup
|
|
137
138
|
end
|
138
139
|
|
139
140
|
return a3.sort_by {|word| -h[word]}.map {|x| x.sub(/ +\|.*$/,'')}\
|
140
|
-
.uniq.take(limit)
|
141
|
-
|
141
|
+
.uniq.take(limit)
|
142
|
+
|
142
143
|
end
|
143
144
|
|
144
145
|
alias q lookup
|
145
|
-
|
146
|
+
|
146
147
|
def master()
|
147
148
|
@master
|
148
149
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phrase_lookup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -11,54 +11,54 @@ cert_chain:
|
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjIwMjIzMTkwMzI3WhcN
|
15
|
+
MjMwMjIzMTkwMzI3WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDoHnqj
|
17
|
+
TM2ZXYOTvfJh6HL3aANUTZYiHo5eRhZVHnbvkD3D696L1gK11Xoue3q1PF6QV/BP
|
18
|
+
PCz2uF1veQbL7Mt0l4r4RMEZDaKjUCurcVP1scFoUFV6JW44o/IBglek64Gbi7rC
|
19
|
+
RvdNn2W0oo6qum0a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QghYxaMW94809R6gc9BJu5HU
|
33
|
+
zmVRfgEddyGqIt54IpuH1L20ggh3yJhBMePZRNhU4JpcSJeO383MTRrXHft0lrCP
|
34
|
+
HMkEsRk6i0/T2rtSpfjJlkR4UhlfXTlkK28SXABYRteFALwHK0Y5cMyl8RbDEiPp
|
35
|
+
A2jeePyrfaR7oaEcMysAqLkt0TsponTcp0R+tdNpgA5flDyl5htca12fCGoqpM9h
|
36
|
+
u9fFJ3bpBEj+P7q6043p1TWh
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2022-02-23 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
|
-
name:
|
41
|
+
name: rxfreadwrite
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 1.0.0
|
47
44
|
- - "~>"
|
48
45
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
46
|
+
version: '0.2'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.2.4
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 1.0.0
|
57
54
|
- - "~>"
|
58
55
|
- !ruby/object:Gem::Version
|
59
|
-
version: '
|
56
|
+
version: '0.2'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.2.4
|
60
60
|
description:
|
61
|
-
email:
|
61
|
+
email: digital.robertson@gmail.com
|
62
62
|
executables: []
|
63
63
|
extensions: []
|
64
64
|
extra_rdoc_files: []
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
86
|
+
rubygems_version: 3.2.22
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: Returns a list of matching phrases from plain text
|
metadata.gz.sig
CHANGED
Binary file
|