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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5fd6a1b23e62042749f8cce80d87af6fb330212b192bd60a593a3cee6441de0e
4
- data.tar.gz: a3bbb9361865709d77b455b85f371929e91f29371fe3ed98a5fbd844e7fee3d1
3
+ metadata.gz: 1aefccf9a3e66b75245de27255b58f8d6f1e988263ec9f50599659bba92fb9ee
4
+ data.tar.gz: def447233c8586a549e3263fc6517ce37e84b8a08432a1e4f24bd5744d8029e0
5
5
  SHA512:
6
- metadata.gz: 6fdc2c7d1b02a0008d8f8a11b20aa26d6e78b2fb25b185f5213eb74b7a10569ba0c014cfcc189c71fe91c9d5b9019325c899a00d1a771e9a89b3032f415e20eb
7
- data.tar.gz: eede7d74a9a1e21efcc022e4792bb07bc4006ac306c97dc81a7d297757d160e461cb1944838c9e73d32fd4df0b34c874252fb913972b8efa91432464c05f384c
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 'rxfhelper'
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 = RXFHelper.read(obj).first
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
- File.write filename, @h.sort.to_h.to_yaml
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, _ = RXFHelper.read(raw_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, _ = RXFHelper.read(raw_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.1.9
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
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwH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lA3+7JPKsQX3pXD9fvB1UoDjlq
33
- 2WxByXLsLaXyguSwnONHhJRg9BpzzaK6ovztQzenjYZMVG7TpoHcxa4kucpK+zxB
34
- nn243c2e6s2GTK+PGlsJoSfxhIlxeQMfvi+Jkbtr1kNSu+SKFt1TkL8TaTdJ7CNj
35
- okm7UBOgnw1k05vu6nv459XCUeIFRegIYJ+P+mI15c8WMWOSdLK7NoU3qYil6Pgd
36
- VWIRHmtajxS0oRQe/0SeVorH
28
+ BgkqhkiG9w0BAQsFAAOCAYEAR7voLOl17Bq9FHhHJ8V/M6UqCwjoMRuNkVwjrjHj
29
+ kJAk4cxgxKvdEGyBOPETvL4NtaEIQk5E+bOhpv4z9vShPgJdh8eZBTiXOBEyfDLE
30
+ +NbxJxT15Ndi7nnWZ7Shjq0lh5tnKFtVG+su1Gxbxw6Q67EV8p+WB08i98YxQ/Rx
31
+ a0OtJ4E0+BM3wyUf5VZZlZdUiDFU6/XGIN3EzHwj/koUQaZKwTBlhiGWXw9WKbUL
32
+ 82wm7bmqVD6wmKrKswmjv8Rk299/XsutkXZUNuENQghYxaMW94809R6gc9BJu5HU
33
+ zmVRfgEddyGqIt54IpuH1L20ggh3yJhBMePZRNhU4JpcSJeO383MTRrXHft0lrCP
34
+ HMkEsRk6i0/T2rtSpfjJlkR4UhlfXTlkK28SXABYRteFALwHK0Y5cMyl8RbDEiPp
35
+ A2jeePyrfaR7oaEcMysAqLkt0TsponTcp0R+tdNpgA5flDyl5htca12fCGoqpM9h
36
+ u9fFJ3bpBEj+P7q6043p1TWh
37
37
  -----END CERTIFICATE-----
38
- date: 2020-06-20 00:00:00.000000000 Z
38
+ date: 2022-02-23 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
- name: rxfhelper
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: '1.0'
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: '1.0'
56
+ version: '0.2'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.2.4
60
60
  description:
61
- email: james@jamesrobertson.eu
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.0.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