event_nlp 0.6.0 → 0.6.3
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/event_nlp.rb +60 -4
- data.tar.gz.sig +0 -0
- metadata +3 -4
- 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: ed04654bfc6e7e852dcce5fc00c55b1428f2bb7468f1bd1934895dab9239403c
|
4
|
+
data.tar.gz: 9df3b5db5d7f473766b27efe0c2da3e599b4061e98fb5eec851c6570600f14a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 958c73c2bd2eed4a4937c8f8a269d758a92cc632ab366c78f00ee23cb19d6923bf99587fb53c649983397866bd5d55f2d34c7cb5d5656ebf61ace1e1ade83d4b
|
7
|
+
data.tar.gz: 6445772034c43de1489b0d8749ce53608554784f56d8bf20a7c58bf0938a87591d0ec80e4515a4bb787217bfd334d4f7844d1f39c2eddfc90c0b403eed0edd1e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/event_nlp.rb
CHANGED
@@ -7,12 +7,11 @@ require 'ostruct'
|
|
7
7
|
require 'app-routes'
|
8
8
|
|
9
9
|
|
10
|
-
|
11
10
|
module Ordinals
|
12
11
|
|
13
12
|
refine Integer do
|
14
13
|
def ordinal
|
15
|
-
self.to_s + ( (10
|
14
|
+
self.to_s + ( self.between?(10,20) ? 'th' :
|
16
15
|
%w{ th st nd rd th th th th th th }[self % 10] )
|
17
16
|
end
|
18
17
|
end
|
@@ -37,7 +36,11 @@ class EventNlp
|
|
37
36
|
|
38
37
|
end
|
39
38
|
|
40
|
-
def parse(
|
39
|
+
def parse(raws)
|
40
|
+
|
41
|
+
s = filter_irregular(raws)
|
42
|
+
|
43
|
+
#-----------------------------------------------------------
|
41
44
|
|
42
45
|
@params[:input] = s
|
43
46
|
r = run_route(s)
|
@@ -48,8 +51,60 @@ class EventNlp
|
|
48
51
|
|
49
52
|
end
|
50
53
|
|
54
|
+
# returns an Array object of dates, projected from a recurring event
|
55
|
+
#
|
56
|
+
def project(s, year: Time.now.year)
|
57
|
+
|
58
|
+
r = parse s
|
59
|
+
dates = []
|
60
|
+
now = @now
|
61
|
+
|
62
|
+
while r.date.year == year.to_i do
|
63
|
+
|
64
|
+
dates << r.date
|
65
|
+
@now = r.date + 1
|
66
|
+
r = parse(r.input)
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
@now = now
|
71
|
+
return dates
|
72
|
+
|
73
|
+
end
|
74
|
+
|
51
75
|
private
|
52
76
|
|
77
|
+
def filter_irregular(raws)
|
78
|
+
|
79
|
+
# catch irregular expressions and interpret them in advance
|
80
|
+
#
|
81
|
+
# e.g. Cafe meeting Thursday every 2 weeks =>
|
82
|
+
# Cafe meeting every 2nd Thursday
|
83
|
+
#
|
84
|
+
weekdays2 = (Date::DAYNAMES + Date::ABBR_DAYNAMES).join('|').downcase
|
85
|
+
pattern = /(?<day>#{weekdays2}) every (?<n>\d) weeks/i
|
86
|
+
found = raws.match(pattern)
|
87
|
+
|
88
|
+
if found then
|
89
|
+
s2 = "every %s %s" % [found[:n].to_i.ordinal, found[:day]]
|
90
|
+
s = raws.sub(pattern, s2)
|
91
|
+
end
|
92
|
+
|
93
|
+
# e.g. "Cafe meeting 14th Monthly" =>
|
94
|
+
# Cafe meeting on the 14th of every month
|
95
|
+
#
|
96
|
+
found = raws.match(/(?<title>.*)\s+(?<day>\w+)(?:st|nd|rd|th) monthly/i)
|
97
|
+
|
98
|
+
if found then
|
99
|
+
s = "%s on the %s of every month" % [found[:title],
|
100
|
+
found[:day].to_i.ordinal]
|
101
|
+
end
|
102
|
+
|
103
|
+
puts 'filter_irregular - s: ' + s.inspect if @debug
|
104
|
+
return s || raws
|
105
|
+
|
106
|
+
end
|
107
|
+
|
53
108
|
def expressions(params)
|
54
109
|
|
55
110
|
starting = /(?:\(?\s*starting (\d+\w{2} \w+\s*\w*)(?: until (.*))?\s*\))?/
|
@@ -70,7 +125,7 @@ class EventNlp
|
|
70
125
|
|
71
126
|
# e.g. electricity bill on the 28th of every month
|
72
127
|
|
73
|
-
get /(.*) on the (#{days}) of every (#{periods})/ do |title, day, recurring|
|
128
|
+
get /(.*) on the (#{days}) of every (#{periods})/i do |title, day, recurring|
|
74
129
|
|
75
130
|
|
76
131
|
raw_d = Chronic.parse(day)
|
@@ -87,6 +142,7 @@ class EventNlp
|
|
87
142
|
|
88
143
|
end
|
89
144
|
|
145
|
+
#
|
90
146
|
|
91
147
|
get /^(.*)\s+(every \d\w+ \w+#{times}\s*#{starting})/ do \
|
92
148
|
|title, recurring, time, raw_date, end_date|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event_nlp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
w8lJ+I6Lqqr5GpsweOnEHW4w200sMRD40u8qmGHrqirihL2KrwTD6A9UObvA5AxZ
|
36
36
|
4Z4EPvKg+3jsK9Gv3GGSLdrD
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2022-
|
38
|
+
date: 2022-04-02 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: chronic_cron
|
@@ -103,8 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
|
-
|
107
|
-
rubygems_version: 2.7.10
|
106
|
+
rubygems_version: 3.2.22
|
108
107
|
signing_key:
|
109
108
|
specification_version: 4
|
110
109
|
summary: 'Parses a calendar event for date, time, and description e.g. hall 2 friday
|
metadata.gz.sig
CHANGED
Binary file
|