event_nlp 0.1.0
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
- checksums.yaml.gz.sig +1 -0
- data/lib/event_nlp.rb +157 -0
- data.tar.gz.sig +0 -0
- metadata +108 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9d9b15778895f2a01d0c3b972ba1436f9073fd6c
|
4
|
+
data.tar.gz: 95eeb58ca3736fa353d0e961ce2f8d67b575d231
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d284092bbd265392a53d4f137b89bb0b414589fe35f0e29a8ca61e1b895eafbb85207f81fd817ce94debe6a6a75bb2a59567e1ccd84f78301b4bddfc386ce6e4
|
7
|
+
data.tar.gz: 7d2f3f486ff172b0704d474a15f5d3a94128958505f9c1573783d35fd4a20328c75a20b692fb81cdcf3d33d83ae3a337c485ae6749a9029f437e2c040bd3f33f
|
checksums.yaml.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
�3b?"XeG�0OPj��E�!}�}j�aiT��@��3��c{]�f���*�3��jη���0;����+��2�ećv\����������-����G6���Fx�*�������7d����/���5�~��~ ��w���0�T6J�ori�Ť�tF�4���,�H"rhc�A��J��'�ps�OqL�p�����w��O�0`���`��[ osMx��jm�;(� ��tj �ԓƾ��ɚ
|
data/lib/event_nlp.rb
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: event_nlp.rb
|
4
|
+
|
5
|
+
require 'chronic'
|
6
|
+
require 'app-routes'
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
class EventNlp
|
11
|
+
include AppRoutes
|
12
|
+
|
13
|
+
|
14
|
+
def initialize()
|
15
|
+
|
16
|
+
super()
|
17
|
+
@params = {}
|
18
|
+
expressions(@params)
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def expressions(params)
|
25
|
+
|
26
|
+
|
27
|
+
# some event every 2 weeks
|
28
|
+
# some event every 2 weeks at 6am starting from 14th Jan
|
29
|
+
# some event every 2 weeks at 6am starting from 18th Feb until 28th Oct
|
30
|
+
# some event every 2nd Monday (starting 7th Nov 2016)
|
31
|
+
# some event every 2nd Monday (starting 7th Nov until 3rd Dec)
|
32
|
+
|
33
|
+
|
34
|
+
starting = /(?:\(?\s*starting (\d+\w2} \w+\s*\w*)(?: until (.*))?\s*\))?/
|
35
|
+
weekday = Date::DAYNAMES.join('|').downcase
|
36
|
+
months = (Date::MONTHNAMES[1..-1] + Date::ABBR_MONTHNAMES[1..-1])
|
37
|
+
.join('|').downcase
|
38
|
+
|
39
|
+
|
40
|
+
get /^(.*)(every \w+ \w+(?: at (\d+am) )?)\s*#{starting}/ do \
|
41
|
+
|title, recurring, time, raw_date, end_date|
|
42
|
+
|
43
|
+
input = params[:input]
|
44
|
+
|
45
|
+
d = Chronic.parse(raw_date)
|
46
|
+
|
47
|
+
if recurring =~ /day|week/ then
|
48
|
+
|
49
|
+
|
50
|
+
if d < @now then
|
51
|
+
|
52
|
+
new_date = CronFormat.new(ChronicCron.new(recurring)\
|
53
|
+
.to_expression, d).to_time
|
54
|
+
input.gsub!(raw_date, new_date\
|
55
|
+
.strftime("#{new_date.day.ordinal} %b %Y"))
|
56
|
+
d = new_date
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
#puts [0, title, recurring, time, raw_date, end_date].inspect
|
63
|
+
{title: title, recurring: recurring, date: d, end_date: end_date}
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
# some meeting 3rd thursday of the month at 7:30pm
|
68
|
+
# some meeting First thursday of the month at 7:30pm
|
69
|
+
get /(.*)\s+(\w+ \w+day of (?:the|every) month at .*)/ do
|
70
|
+
|title, recurring|
|
71
|
+
|
72
|
+
#puts [1, title, recurring].inspect
|
73
|
+
{ title: title, recurring: recurring }
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
# hall 2 friday at 11am
|
78
|
+
get /(.*)\s+(#{weekday})\s+at\s+(.*)/i do |title, raw_day, time|
|
79
|
+
|
80
|
+
d = Chronic.parse(raw_day + ' ' + time)
|
81
|
+
|
82
|
+
#puts [1.5, title, raw_day].inspect
|
83
|
+
{ title: title, date: d }
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
# e.g. 21/05/2017 Forum meetup at Roundpeg from 2pm
|
88
|
+
get /^(\d+\/\d+\/\d+)\s+(.*)(?: from|at)\s+(\d+[ap]m)/ do
|
89
|
+
|raw_date, title, raw_time|
|
90
|
+
|
91
|
+
d = Chronic.parse(raw_date + ' ' +
|
92
|
+
raw_time, :endian_precedence => :little)
|
93
|
+
recurring = nil
|
94
|
+
|
95
|
+
#puts [3, title, raw_date].inspect
|
96
|
+
{ title: title, date: d }
|
97
|
+
end
|
98
|
+
|
99
|
+
# hall 2 friday at 11am
|
100
|
+
# some important day 24th Mar
|
101
|
+
|
102
|
+
with_date = "(.*)\\s+(\\d\+\s*(?:st|nd|rd|th)?\\s+(?:#{months}))"
|
103
|
+
alt_pattern = '([^\d]+)\s+(\d+[^\*]+)(\*)?'
|
104
|
+
|
105
|
+
get /#{with_date}|#{alt_pattern}\s*(\*)$/i do |title, raw_date, annualar|
|
106
|
+
|
107
|
+
d = Chronic.parse(raw_date)
|
108
|
+
|
109
|
+
recurring = nil
|
110
|
+
|
111
|
+
if annualar then
|
112
|
+
|
113
|
+
recurring = 'yearly'
|
114
|
+
if d < @now then
|
115
|
+
d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
#puts [2, title, raw_date].inspect
|
120
|
+
{ title: title, date: d, recurring: recurring }
|
121
|
+
end
|
122
|
+
|
123
|
+
# 27-Mar@1436 some important day
|
124
|
+
get /(\d[^\s]+)\s+([^\*]+)(\*)?/ do |raw_date, title, annualar|
|
125
|
+
|
126
|
+
d = Chronic.parse(raw_date, :endian_precedence => :little)
|
127
|
+
recurring = nil
|
128
|
+
|
129
|
+
if annualar then
|
130
|
+
|
131
|
+
recurring = 'yearly'
|
132
|
+
if d < @now then
|
133
|
+
d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
#puts [3, title, raw_date].inspect
|
139
|
+
{ title: title, date: d, recurring: recurring }
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
# e.g. 04-Aug@12:34
|
146
|
+
get '*' do |s|
|
147
|
+
puts 's: ' + s.inspect
|
148
|
+
'pattern unrecognised'
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
alias parse run_route
|
155
|
+
|
156
|
+
|
157
|
+
end
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: event_nlp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
|
14
|
+
YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
|
15
|
+
8ixkARkWAmV1MB4XDTE3MDUwNzE0NTg0OVoXDTE4MDUwNzE0NTg0OVowSDESMBAG
|
16
|
+
A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZ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3OTs6j+vsUBIwCb/Ki17Z4YULtRaGg7I8nTjTrHIIJ0yNm
|
32
|
+
kbRihMTezaC+4A==
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2017-05-07 00:00:00.000000000 Z
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: chronic
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0.10'
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.10.2
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0.10'
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.10.2
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: app-routes
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0.1'
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 0.1.19
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - "~>"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0.1'
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.1.19
|
76
|
+
description:
|
77
|
+
email: james@jamesrobertson.eu
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- lib/event_nlp.rb
|
83
|
+
homepage: https://github.com/jrobertson/event_nlp
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.6.8
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: 'Parses a calendar event for date, time, and description e.g. hall 2 friday
|
107
|
+
at 11am #=> {:title=>"hall 2", :date=>2017-05-12 11:...}'
|
108
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|