when_exe 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE.ja.txt +8 -21
- data/LICENSE.txt +5 -27
- data/README.md +25 -79
- data/bin/.pryrc +9 -0
- data/bin/make_ttl.rb +3 -2
- data/bin/make_ttl.rb.config +3 -3
- data/lib/when_exe.rb +101 -5
- data/lib/when_exe/basictypes.rb +47 -16
- data/lib/when_exe/calendarnote.rb +27 -18
- data/lib/when_exe/calendartypes.rb +12 -50
- data/lib/when_exe/coordinates.rb +37 -391
- data/lib/when_exe/ephemeris.rb +53 -14
- data/lib/when_exe/ephemeris/eclipse.rb +8 -8
- data/lib/when_exe/ephemeris/moon.rb +333 -333
- data/lib/when_exe/ephemeris/notes.rb +29 -17
- data/lib/when_exe/ephemeris/phase_table.rb +825 -0
- data/lib/when_exe/ephemeris/term_table.rb +603 -0
- data/lib/when_exe/events.rb +1888 -0
- data/lib/when_exe/google_api.rb +26 -31
- data/lib/when_exe/icalendar.rb +129 -12
- data/lib/when_exe/inspect.rb +5 -5
- data/lib/when_exe/linkeddata.rb +43 -23
- data/lib/when_exe/locales/akt.rb +63 -0
- data/lib/when_exe/locales/encoding_conversion.rb +134 -134
- data/lib/when_exe/locales/iast.rb +90 -90
- data/lib/when_exe/locales/locale.rb +88 -18
- data/lib/when_exe/locales/transliteration_table.rb +62 -62
- data/lib/when_exe/mini_application.rb +14 -8
- data/lib/when_exe/namespace.rb +42 -0
- data/lib/when_exe/parts/enumerator.rb +16 -5
- data/lib/when_exe/parts/geometric_complex.rb +52 -2
- data/lib/when_exe/parts/method_cash.rb +229 -224
- data/lib/when_exe/parts/resource.rb +65 -35
- data/lib/when_exe/parts/timezone.rb +25 -34
- data/lib/when_exe/region/balinese.rb +5 -3
- data/lib/when_exe/region/chinese.rb +39 -11
- data/lib/when_exe/region/chinese/calendars.rb +1016 -1016
- data/lib/when_exe/region/chinese/epochs.rb +7 -7
- data/lib/when_exe/region/chinese/notes.rb +3 -3
- data/lib/when_exe/region/chinese/twins.rb +134 -11
- data/lib/when_exe/region/dee.rb +4 -4
- data/lib/when_exe/region/discordian.rb +1 -1
- data/lib/when_exe/region/geologicalage.rb +139 -128
- data/lib/when_exe/region/hanke_henry.rb +4 -4
- data/lib/when_exe/region/indian.rb +77 -8
- data/lib/when_exe/region/international_fixed.rb +3 -3
- data/lib/when_exe/region/islamic.rb +1 -1
- data/lib/when_exe/region/japanese.rb +12 -8
- data/lib/when_exe/region/japanese/calendars.rb +397 -397
- data/lib/when_exe/region/japanese/eclipses.rb +1194 -1194
- data/lib/when_exe/region/japanese/epochs.rb +8 -4
- data/lib/when_exe/region/japanese/location.rb +93 -0
- data/lib/when_exe/region/japanese/nihon_shoki.rb +70 -70
- data/lib/when_exe/region/japanese/notes.rb +57 -18
- data/lib/when_exe/region/japanese/residues.rb +33 -11
- data/lib/when_exe/region/japanese/twins.rb +27 -14
- data/lib/when_exe/region/japanese/weeks.rb +7 -7
- data/lib/when_exe/region/korean.rb +384 -384
- data/lib/when_exe/region/location.rb +40 -0
- data/lib/when_exe/region/martian.rb +1 -1
- data/lib/when_exe/region/mayan.rb +2 -2
- data/lib/when_exe/region/roman.rb +2 -2
- data/lib/when_exe/region/ryukyu.rb +101 -101
- data/lib/when_exe/region/saudi_arabian.rb +57 -0
- data/lib/when_exe/region/shire.rb +1 -1
- data/lib/when_exe/region/world.rb +3 -3
- data/lib/when_exe/region/zoroastrian.rb +1 -1
- data/lib/when_exe/spatial.rb +611 -0
- data/lib/when_exe/timestandard.rb +9 -7
- data/lib/when_exe/tmobjects.rb +34 -2
- data/lib/when_exe/tmposition.rb +225 -1322
- data/lib/when_exe/tmptypes.rb +1279 -0
- data/lib/when_exe/tmreference.rb +42 -7
- data/lib/when_exe/version.rb +3 -3
- data/test/events/example-datasets +6 -0
- data/test/events/history-dataset.csv +22 -0
- data/test/events/japanese-holiday-index.csv +28 -0
- data/test/events/japanese-holiday.csv +94 -0
- data/test/events/japanese-holiday.ttl +948 -0
- data/test/events/make_events_ttl.rb +18 -0
- data/test/events/mori_wikichoshi.csv +14 -0
- data/test/events/ndl_koyomi.csv +220 -0
- data/test/events/ndl_koyomi_index.csv +44 -0
- data/test/events/primeminister-dataset.csv +19 -0
- data/test/events/shogun-dataset.csv +22 -0
- data/test/events/test-history-dataset-edge-sparql.csv +26 -0
- data/test/events/test-history-dataset-edge.csv +27 -0
- data/test/events/test-history-dataset-sparql.csv +22 -0
- data/test/events/test-history-dataset.csv +23 -0
- data/test/events/test-history-events-edge.ttl +89 -0
- data/test/events/test-history-events.csv +6 -0
- data/test/examples/JapanHolidays.ics +2 -2
- data/test/examples/JapanHolidaysRFC6350.ics +3 -3
- data/test/examples/Residue.m17n +2 -2
- data/test/examples/Spatial.m17n +3 -3
- data/test/examples/Terms.m17n +3 -3
- data/test/scripts/8.ext.rb +6 -6
- data/test/scripts/8.rb +6 -6
- data/test/scripts/geometric_complex.rb +41 -41
- data/test/scripts/korea.rb +59 -59
- data/test/scripts/thai.rb +36 -36
- data/test/test.rb +6 -0
- data/test/test/basictypes.rb +431 -431
- data/test/test/calendarnote.rb +86 -86
- data/test/test/calendartypes.rb +97 -97
- data/test/test/coordinates.rb +399 -397
- data/test/test/ephemeris.rb +115 -115
- data/test/test/ephemeris/moon.rb +14 -14
- data/test/test/ephemeris/planets.rb +14 -14
- data/test/test/ephemeris/sun.rb +14 -14
- data/test/test/events.rb +32 -0
- data/test/test/google_api.rb +45 -32
- data/test/test/inspect.rb +153 -153
- data/test/test/parts.rb +488 -488
- data/test/test/region/armenian.rb +20 -20
- data/test/test/region/bahai.rb +58 -58
- data/test/test/region/balinese.rb +34 -34
- data/test/test/region/chinese.rb +229 -229
- data/test/test/region/christian.rb +226 -226
- data/test/test/region/coptic.rb +27 -27
- data/test/test/region/discordian.rb +20 -20
- data/test/test/region/french.rb +33 -33
- data/test/test/region/geologicalage.rb +17 -17
- data/test/test/region/indian.rb +14 -1
- data/test/test/region/iran.rb +54 -54
- data/test/test/region/islamic.rb +64 -54
- data/test/test/region/japanese.rb +281 -261
- data/test/test/region/jewish.rb +63 -63
- data/test/test/region/m17n.rb +21 -21
- data/test/test/region/mayan.rb +17 -16
- data/test/test/region/reforms.rb +2 -2
- data/test/test/region/residue.rb +7 -7
- data/test/test/region/shire.rb +58 -58
- data/test/test/region/swedish.rb +45 -45
- data/test/test/region/thai.rb +116 -116
- data/test/test/region/tibetan.rb +30 -30
- data/test/test/region/vietnamese.rb +102 -102
- data/test/test/region/zoroastrian.rb +58 -58
- data/test/test/timestandard.rb +81 -81
- data/test/test/tmobjects.rb +402 -402
- data/test/test/tmposition.rb +66 -4
- data/test/test/tmreference.rb +157 -157
- metadata +36 -93
data/lib/when_exe/google_api.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
=begin
|
3
|
-
Copyright (C) 2015 Takashi SUGA
|
3
|
+
Copyright (C) 2015-2021 Takashi SUGA
|
4
4
|
|
5
5
|
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
6
|
=end
|
@@ -8,7 +8,8 @@
|
|
8
8
|
#
|
9
9
|
# GoogleAPI の Calendar API v3 への対応
|
10
10
|
#
|
11
|
-
# see {
|
11
|
+
# see {Ruby Quickstart https://developers.google.com/calendar/quickstart/ruby}
|
12
|
+
# see {Simple REST client for version V3 of the Calendar API https://googleapis.dev/ruby/google-apis-calendar_v3/v0.1.0/}
|
12
13
|
#
|
13
14
|
module When::GoogleAPI
|
14
15
|
|
@@ -17,15 +18,9 @@ module When::GoogleAPI
|
|
17
18
|
#
|
18
19
|
class Calendar
|
19
20
|
|
20
|
-
# APIClient のインスタンス
|
21
|
-
#
|
22
|
-
# @return [Google::APIClient]
|
23
|
-
#
|
24
|
-
attr_reader :client
|
25
|
-
|
26
21
|
# Calendar API のインスタンス
|
27
22
|
#
|
28
|
-
# @return [Google::
|
23
|
+
# @return [Google::Apis::CalendarV3::CalendarService]
|
29
24
|
#
|
30
25
|
attr_reader :service
|
31
26
|
|
@@ -45,24 +40,19 @@ module When::GoogleAPI
|
|
45
40
|
#
|
46
41
|
# GoogleAPI の Calendar を生成する
|
47
42
|
#
|
48
|
-
# @param [Google::
|
49
|
-
# @param [Google::APIClient::API] service
|
43
|
+
# @param [Google::Apis::CalendarV3::CalendarService] service
|
50
44
|
# @param [String] calendar_id
|
51
45
|
#
|
52
|
-
def list(
|
46
|
+
def list(service, calendar_id)
|
53
47
|
events = []
|
54
|
-
result =
|
55
|
-
:parameters => {'calendarId' => calendar_id}})
|
48
|
+
result = service.list_events(calendar_id)
|
56
49
|
loop do
|
57
|
-
events += result.
|
58
|
-
page_token = result.
|
50
|
+
events += result.items.map {|event| event.to_h}
|
51
|
+
page_token = result.next_page_token
|
59
52
|
break unless page_token
|
60
|
-
result =
|
61
|
-
:parameters => {'calendarId' => calendar_id,
|
62
|
-
'pageToken' => page_token}})
|
53
|
+
result = service.list_events(calendar_id, page_token: page_token)
|
63
54
|
end
|
64
55
|
calendar = new(events)
|
65
|
-
calendar.instance_variable_set(:@client, client)
|
66
56
|
calendar.instance_variable_set(:@service, service)
|
67
57
|
calendar.instance_variable_set(:@calendar_id, calendar_id)
|
68
58
|
calendar
|
@@ -87,7 +77,7 @@ module When::GoogleAPI
|
|
87
77
|
#
|
88
78
|
def initialize(events)
|
89
79
|
@events = events.map {|event|
|
90
|
-
next nil unless event[
|
80
|
+
next nil unless event[:status] == 'confirmed'
|
91
81
|
When::V::Event.new(event)
|
92
82
|
}.compact
|
93
83
|
end
|
@@ -114,15 +104,18 @@ class When::V::Event
|
|
114
104
|
iprops = {}
|
115
105
|
gprops.each_pair do |key, value|
|
116
106
|
case key
|
117
|
-
when
|
118
|
-
iprops['summary'] = value
|
119
|
-
when 'start', 'end'
|
107
|
+
when :start, :end
|
120
108
|
date = 'VALUE=DATE'
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
109
|
+
if value.key?(:date)
|
110
|
+
date += ':' + value[:date].strftime('%Y%m%d')
|
111
|
+
else
|
112
|
+
date += '-TIME'
|
113
|
+
date += ':' + value[:date_time].strftime('%Y%m%dT%H%M%S')
|
114
|
+
date += value[:date_time].strftime('%z') unless value[:time_zone]
|
115
|
+
end
|
116
|
+
date.sub!(':', ";TZID=#{value[:time_zone]}:") if value.key?(:time_zone)
|
117
|
+
iprops['dt' + key.to_s] = date
|
118
|
+
when :recurrence
|
126
119
|
value.map do |line|
|
127
120
|
tag, rule = line.split(':', 2)
|
128
121
|
tag.downcase!
|
@@ -132,8 +125,10 @@ class When::V::Event
|
|
132
125
|
iprops[tag] = rule
|
133
126
|
end
|
134
127
|
end
|
135
|
-
when
|
128
|
+
when :i_cal_uid
|
136
129
|
iprops['uid'] = value
|
130
|
+
when Symbol
|
131
|
+
iprops[key.to_s] = value
|
137
132
|
end
|
138
133
|
end
|
139
134
|
iprops
|
@@ -144,7 +139,7 @@ class When::V::Event
|
|
144
139
|
|
145
140
|
# Hash からの属性読み込み
|
146
141
|
def _parse_from_code(options)
|
147
|
-
if options.key?(
|
142
|
+
if options.key?(:start)
|
148
143
|
@google_api_props = options
|
149
144
|
options = self.class.gcal2ical(options)
|
150
145
|
end
|
data/lib/when_exe/icalendar.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
=begin
|
3
|
-
Copyright (C) 2011-
|
3
|
+
Copyright (C) 2011-2021 Takashi SUGA
|
4
4
|
|
5
5
|
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
6
|
=end
|
@@ -528,6 +528,17 @@ module When::V
|
|
528
528
|
'resources', 'rdate']]
|
529
529
|
# Classes = [V::Root, V::Alarm]
|
530
530
|
|
531
|
+
RegisteredNotes = {
|
532
|
+
'term' => 'SolarTerms',
|
533
|
+
'phase' => 'LunarPhases',
|
534
|
+
'easter' => 'Christian',
|
535
|
+
'christmas' => 'Christian'
|
536
|
+
}
|
537
|
+
|
538
|
+
RegisteredNoteMethods = /\A(#{RegisteredNotes.keys.sort.reverse.join('|')})/
|
539
|
+
|
540
|
+
DayOfWeek = %w(SU MO TU WE TH FR SA)
|
541
|
+
|
531
542
|
class << self
|
532
543
|
include When::Parts::Resource::Pool
|
533
544
|
|
@@ -563,7 +574,102 @@ module When::V
|
|
563
574
|
#
|
564
575
|
# @return [When::TM::IntervalLength]
|
565
576
|
def default_until
|
566
|
-
@default_until ||= 1000*When::TM::Duration::YEAR
|
577
|
+
@default_until ||= 1000*(When::TM::Duration::YEAR / When::TM::Duration::DAY)
|
578
|
+
end
|
579
|
+
|
580
|
+
# ISO8601へ埋め込まれた指定に対応する iterator を生成する
|
581
|
+
#
|
582
|
+
# @param [When::TM::TemporalPosition] base イベントの始点
|
583
|
+
# @param [When::TM::Duration] duration イベントの期間
|
584
|
+
# @param [Hash] delayed_options 遅延適用するオブジェクト変換オプション
|
585
|
+
#
|
586
|
+
# @return [When::Parts::Enumerator]
|
587
|
+
#
|
588
|
+
def iterator_for_ISO8601(base, duration, delayed_options)
|
589
|
+
duration.to_s =~ /\A-?P(\d+)([YM])\z/
|
590
|
+
event_options = {'rrule'=>
|
591
|
+
case $2
|
592
|
+
when 'Y' ; {'FREQ'=>'YEARLY', 'INTERVAL'=>$1.to_i}
|
593
|
+
when 'M' ; {'FREQ'=>'MONTHLY', 'INTERVAL'=>$1.to_i}
|
594
|
+
else ; duration ? {'FREQ'=>duration.set_repeat(false).abs} : {'FREQ'=>'YEARLY'}
|
595
|
+
end
|
596
|
+
}
|
597
|
+
residue_options = delayed_options[:residue]
|
598
|
+
frame_len = base.frame.indices.length
|
599
|
+
if residue_options
|
600
|
+
event_options['rrule'].update(_byyear(residue_options.delete(frame_len-2))) if residue_options[frame_len-2]
|
601
|
+
event_options['rrule'].update(_byday(residue_options.delete(frame_len) )) if residue_options[frame_len]
|
602
|
+
delayed_options.delete(:residue)
|
603
|
+
end
|
604
|
+
if base.precision == When::MONTH && event_options['rrule']['FREQ'] == 'YEARLY'
|
605
|
+
event_options['rrule'].update({'BYMONTH'=>base[When::MONTH]})
|
606
|
+
base = base.floor if event_options['rrule']['BYMONTHDAY']
|
607
|
+
end
|
608
|
+
case base
|
609
|
+
when When::TM::TemporalPosition ; event_options.update({'dtstart' =>base})
|
610
|
+
else ; event_options.update({'dtstart' =>base.first,
|
611
|
+
'duration' =>base.last-base.first})
|
612
|
+
end
|
613
|
+
event_options['duration'] = delayed_options.delete(:duration) if delayed_options[:duration]
|
614
|
+
behavior_options = {'1st'=>delayed_options.delete(:first) || "don't care"}
|
615
|
+
behavior_options[:delayed] = delayed_options unless delayed_options.empty?
|
616
|
+
behavior_options[:direction] = :reverse if duration && duration.sign < 0
|
617
|
+
return new(event_options).enum_for(event_options['dtstart'], behavior_options)
|
618
|
+
end
|
619
|
+
|
620
|
+
private
|
621
|
+
|
622
|
+
# オブジェクト変換オプションの遅延適用のBYYEAR要素
|
623
|
+
#
|
624
|
+
def _byyear(operation)
|
625
|
+
{'BYYEAR'=>_to_ical_hash(When.Residue(operation), 'year', 4)}
|
626
|
+
end
|
627
|
+
|
628
|
+
# オブジェクト変換オプションの遅延適用のBYDAY要素
|
629
|
+
#
|
630
|
+
def _byday(operation)
|
631
|
+
return {'BYDAY'=>_to_ical_hash(operation, 'day', 11)} if operation.kind_of?(When::Coordinates::Residue)
|
632
|
+
|
633
|
+
residues = []
|
634
|
+
result = {}
|
635
|
+
byday = {}
|
636
|
+
|
637
|
+
# イベント、日付
|
638
|
+
operation.split('&').each do |element|
|
639
|
+
element.strip!
|
640
|
+
case element
|
641
|
+
when RegisteredNoteMethods ; byday.update({nil=>element})
|
642
|
+
when /\A(.+?)#(.+)\z/ ; byday.update({$1=>$2})
|
643
|
+
when /\A[-+,\d]+\z/ ; result['BYMONTHDAY'] = element
|
644
|
+
else ; residues << element
|
645
|
+
end
|
646
|
+
end
|
647
|
+
|
648
|
+
# 剰余類
|
649
|
+
unless residues.empty?
|
650
|
+
residue = residues.join('&')
|
651
|
+
if residue =~ /\A[-+]?\d*(MO|TU|WE|TH|FR|SA|SU)\z/
|
652
|
+
result['BYWEEKDAY'] = residue
|
653
|
+
else
|
654
|
+
resource = When.Residue(residue)
|
655
|
+
if resource
|
656
|
+
byday.update(_to_ical_hash(resource, 'day', 11))
|
657
|
+
else
|
658
|
+
result['BYWEEKDAY'] = residue
|
659
|
+
end
|
660
|
+
end
|
661
|
+
end
|
662
|
+
|
663
|
+
result['BYDAY'] = byday unless byday.empty?
|
664
|
+
return result
|
665
|
+
end
|
666
|
+
|
667
|
+
# 剰余のハッシュ化
|
668
|
+
def _to_ical_hash(residue, unit, offset)
|
669
|
+
operation = ''
|
670
|
+
operation << "#{residue.carry < 0 ? residue.carry : residue.carry+1}*" if residue.shifted
|
671
|
+
operation << "#{(residue.remainder-offset+residue.units[unit]) % residue.divisor}"
|
672
|
+
{residue.divisor=>operation}
|
567
673
|
end
|
568
674
|
end
|
569
675
|
|
@@ -941,13 +1047,13 @@ module When::V
|
|
941
1047
|
super
|
942
1048
|
|
943
1049
|
@child.each do |prop|
|
944
|
-
@dtstart = prop.dtstart if (@dtstart
|
1050
|
+
@dtstart = prop.dtstart if (@dtstart.nil? || prop.dtstart < @dtstart)
|
945
1051
|
@dtstop = prop.dtstop unless (prop.dtstop.kind_of?(When::TimeValue) &&
|
946
1052
|
@dtstop.kind_of?(When::TimeValue) &&
|
947
1053
|
prop.dtstop <= @dtstop)
|
948
1054
|
[prop.tzoffsetfrom, prop.tzoffsetto].each do |tz|
|
949
|
-
@daylight = tz if (@daylight
|
950
|
-
@standard = tz if (@standard
|
1055
|
+
@daylight = tz if (@daylight.nil? || tz.universal_time < @daylight.universal_time)
|
1056
|
+
@standard = tz if (@standard.nil? || tz.universal_time > @standard.universal_time)
|
951
1057
|
end
|
952
1058
|
end
|
953
1059
|
@tz_difference = @standard.universal_time - @daylight.universal_time
|
@@ -1001,7 +1107,7 @@ module When::V
|
|
1001
1107
|
date = prop.enum_for(current_time, direction, 1).succ
|
1002
1108
|
if (date)
|
1003
1109
|
diff = (date.universal_time - current_time).abs
|
1004
|
-
if (minimum
|
1110
|
+
if (minimum.nil? || minimum > diff)
|
1005
1111
|
event = date
|
1006
1112
|
minimum = diff
|
1007
1113
|
end
|
@@ -1065,6 +1171,7 @@ module When::V
|
|
1065
1171
|
@options = When::Parts::Enumerator._options(args)
|
1066
1172
|
@exdate = @options.delete(:exdate)
|
1067
1173
|
@exevent = @options.delete(:exevent)
|
1174
|
+
@delayed = @options.delete(:delayed)
|
1068
1175
|
@parent, @rule, @dtstart, @duration, *rest = args
|
1069
1176
|
@dtstart = When.when?(@dtstart)
|
1070
1177
|
@rule = self.class._decode_rule(@rule, @dtstart) if (@rule.kind_of?(String))
|
@@ -1267,7 +1374,7 @@ module When::V
|
|
1267
1374
|
position = rule[(by_part == 'BYYEAR') ? 'YEARPOS' : 'DAYPOS'][ref]
|
1268
1375
|
start = rule[(by_part == 'BYYEAR') ? 'YEARST' : 'DAYST' ][ref]
|
1269
1376
|
rule[by_part][ref] = ((ref.to_i==0) ? Logic::Enumerator :
|
1270
|
-
Logic::Residue).new(by_part, list, position, ref, start)
|
1377
|
+
Logic::Residue).new(by_part, list, position, ref, start, dtstart)
|
1271
1378
|
end
|
1272
1379
|
end
|
1273
1380
|
end
|
@@ -1295,7 +1402,7 @@ module When::V
|
|
1295
1402
|
if (dtstart && dtstart.has_time?)
|
1296
1403
|
['HOUR', 'MINUTE', 'SECOND'].each do |part|
|
1297
1404
|
by_part = 'BY' + part
|
1298
|
-
if (rule[by_part]
|
1405
|
+
if (rule[by_part].nil? && freq_index && freq_index < PostFreqIndex[by_part])
|
1299
1406
|
base = dtstart[PostFreqIndex[by_part]]
|
1300
1407
|
rule[by_part] = Logic.const_get(part.capitalize).new(by_part, base) unless (base == 0)
|
1301
1408
|
end
|
@@ -1457,7 +1564,7 @@ module When::V
|
|
1457
1564
|
end
|
1458
1565
|
|
1459
1566
|
# @private
|
1460
|
-
def initialize(by_part, list, position, ref, start)
|
1567
|
+
def initialize(by_part, list, position, ref, start, dtstart)
|
1461
1568
|
@by_part = by_part
|
1462
1569
|
divisor = When::Coordinates::Pair._en_number(ref)
|
1463
1570
|
@list = list.split(/,/).map {|w|
|
@@ -1497,7 +1604,7 @@ module When::V
|
|
1497
1604
|
nth, spec, period = ord
|
1498
1605
|
shift = (period[PostFreqIndex[@by_part]] != 0)
|
1499
1606
|
raise ArgumentError, "n*e+/-s format not permitted" if (nth || shift) && @freq_index >= When::DAY
|
1500
|
-
if (nth
|
1607
|
+
if (nth.nil? || nth>0)
|
1501
1608
|
enum = @ref.enum_for(lower_bound, :forward, {:event=>spec})
|
1502
1609
|
else
|
1503
1610
|
enum = @ref.enum_for(higher_bound, :reverse, {:event=>spec})
|
@@ -1519,9 +1626,19 @@ module When::V
|
|
1519
1626
|
end
|
1520
1627
|
|
1521
1628
|
# @private
|
1522
|
-
def initialize(by_part, list, position, ref, start)
|
1629
|
+
def initialize(by_part, list, position, ref, start, dtstart)
|
1523
1630
|
@by_part = by_part
|
1524
|
-
@ref
|
1631
|
+
@ref =
|
1632
|
+
if ref
|
1633
|
+
When.Resource(ref, '_n:')
|
1634
|
+
else
|
1635
|
+
method = list[/\A[^-+\d]+/]
|
1636
|
+
if dtstart.frame.note.respond_to?(method)
|
1637
|
+
dtstart.frame.note
|
1638
|
+
else
|
1639
|
+
When.Resource(When::V::Event::RegisteredNotes[method], '_n:')
|
1640
|
+
end
|
1641
|
+
end
|
1525
1642
|
@start = start
|
1526
1643
|
@list = list.split(/,/).map {|w|
|
1527
1644
|
raise ArgumentError, "The #{by_part} rule format error" unless w =~ /\A(([-+]?\d+)\*)?(.+?)([-+]\d+)?\z/
|
data/lib/when_exe/inspect.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
=begin
|
3
|
-
Copyright (C) 2011-
|
3
|
+
Copyright (C) 2011-2021 Takashi SUGA
|
4
4
|
|
5
5
|
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
6
|
=end
|
@@ -75,7 +75,7 @@ module When
|
|
75
75
|
# @return [String] to_h 結果を JSON文字列化したもの
|
76
76
|
#
|
77
77
|
def to_json(options={})
|
78
|
-
options[:method] = :to_m17n unless options.key?(:method)
|
78
|
+
options[:method] = :to_m17n unless options.respond_to?(:key?) && options.key?(:method)
|
79
79
|
JSON.dump(to_h(options))
|
80
80
|
end
|
81
81
|
|
@@ -603,7 +603,7 @@ module When
|
|
603
603
|
form_options[:method] = :to_m17n unless form_options.key?(:method)
|
604
604
|
persistence = options.delete(:persistence) if options.kind_of?(Hash)
|
605
605
|
retrieved = When::CalendarNote::NotesContainer.retrieve(persistence, self.to_i)
|
606
|
-
return retrieved
|
606
|
+
return retrieved if retrieved
|
607
607
|
When::CalendarNote::NotesContainer.register(_m17n_form(_notes(options), form_options), persistence, self.to_i)
|
608
608
|
end
|
609
609
|
|
@@ -773,7 +773,7 @@ module When
|
|
773
773
|
# @return [String]
|
774
774
|
#
|
775
775
|
def _to_uri(date)
|
776
|
-
(date.gsub(
|
776
|
+
(date.gsub(/%/, '@').sub(/(\d{2}:\d{2}:\d{2})\.(\d+)/, '\1%2E\2').gsub(/\./, '-') + caret_frame).
|
777
777
|
gsub(When::Parts::Resource::IRIEncode) {|c| When::Parts::Resource::IRIEncodeTable[c]}
|
778
778
|
end
|
779
779
|
|
@@ -1460,7 +1460,7 @@ module When
|
|
1460
1460
|
# 出力に使用する clk_time の作成
|
1461
1461
|
def _clk_time_for_inspect(precision)
|
1462
1462
|
return @clk_time unless precision && precision > When::DAY
|
1463
|
-
base = self + When::TM::
|
1463
|
+
base = self + When::TM::PeriodDuration.new(0.5, precision)
|
1464
1464
|
base.clk_time.clk_time[When::HOUR] = @clk_time.clk_time[When::HOUR] + 1 unless self.to_i == base.to_i
|
1465
1465
|
return base.clk_time
|
1466
1466
|
end
|
data/lib/when_exe/linkeddata.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
=begin
|
3
|
-
Copyright (C) 2014-
|
3
|
+
Copyright (C) 2014-2021 Takashi SUGA
|
4
4
|
|
5
5
|
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
6
|
=end
|
@@ -15,6 +15,7 @@ module When
|
|
15
15
|
|
16
16
|
Schema = {
|
17
17
|
'reference' => "Locale#reference-instance_method",
|
18
|
+
'dbpedia' => "Locale#dbpedia-instance_method",
|
18
19
|
'label' => "BasicTypes/M17n#label-instance_method",
|
19
20
|
'prev' => "TM/TemporalPosition#prev-instance_method",
|
20
21
|
'succ' => "TM/TemporalPosition#succ-instance_method",
|
@@ -23,7 +24,6 @@ module When
|
|
23
24
|
'coordinate' => "TM/CalDate#cal_date-instance_method",
|
24
25
|
'sdn' => "TM/CalDate#to_i-instance_method",
|
25
26
|
'calendarEra' => "TM/CalDate#calendar_era-instance_method",
|
26
|
-
'referenceEvent' => "TM/Clock#reference_event-instance_method",
|
27
27
|
'referenceTime' => "TM/Clock#reference_time-instance_method",
|
28
28
|
'utcReference' => "TM/Clock#utc_reference-instance_method",
|
29
29
|
'dateBasis' => "TM/Clock#date_basis-instance_method",
|
@@ -40,12 +40,19 @@ module When
|
|
40
40
|
'latitude' => "Coordinates/Spatial#latitude-instance_method",
|
41
41
|
'altitide' => "Coordinates/Spatial#latitude-instance_method",
|
42
42
|
'event' => "CalendarNote#event-instance_method",
|
43
|
+
'note' => "CalendarNote/NoteElement",
|
44
|
+
'id' => "Events/Event#id-instance_method",
|
45
|
+
'group' => "Events/Event#group-instance_method",
|
46
|
+
'start' => "Events/Range#start-instance_method",
|
47
|
+
'until' => "Events/Range#until-instance_method",
|
48
|
+
'west' => "Coordinates/Spatial/Range#west-instance_method",
|
49
|
+
'east' => "Coordinates/Spatial/Range#east-instance_method",
|
50
|
+
'south' => "Coordinates/Spatial/Range#south-instance_method",
|
51
|
+
'north' => "Coordinates/Spatial/Range#north-instance_method",
|
52
|
+
'bottom' => "Coordinates/Spatial/Range#bottom-instance_method",
|
53
|
+
'top' => "Coordinates/Spatial/Range#top-instance_method"
|
43
54
|
}
|
44
55
|
|
45
|
-
XSD = 'http://www.w3.org/2001/XMLSchema'
|
46
|
-
RDFS = 'http://www.w3.org/2000/01/rdf-schema#'
|
47
|
-
RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
|
48
|
-
|
49
56
|
#
|
50
57
|
# @private
|
51
58
|
#
|
@@ -85,8 +92,9 @@ module When
|
|
85
92
|
def schema(iri=nil)
|
86
93
|
ts = base_uri.sub(/When\/$/, 'ts#')
|
87
94
|
hash =
|
88
|
-
{'@context'=>{'ts' => ts},
|
89
|
-
'@graph' => Schema.keys.map {|id| {'@id'=>'ts:'+id, '
|
95
|
+
{'@context'=>{'rdf'=>When::Namespace::RDF, 'ts' => ts},
|
96
|
+
'@graph' => Schema.keys.map {|id| {'@id'=>'ts:'+id, 'rdf:type'=>{'@id'=>'rdf:Property'},
|
97
|
+
'ts:reference'=>{'@id'=>DocRoot + Schema[id]}}}
|
90
98
|
}
|
91
99
|
bless(hash, iri || ts[0..-2])
|
92
100
|
end
|
@@ -117,7 +125,7 @@ module When
|
|
117
125
|
JSON.generate(jsonld_hash)
|
118
126
|
else
|
119
127
|
array = JSON::LD::API.toRdf(jsonld_hash)
|
120
|
-
graph =
|
128
|
+
graph = RDF::Graph.new << array
|
121
129
|
args = [writer]
|
122
130
|
args << {:prefixes=>prefixes} if prefixes
|
123
131
|
graph.dump(*args)
|
@@ -162,13 +170,13 @@ module When
|
|
162
170
|
def namespace_prefixes(*resources)
|
163
171
|
base = base_uri.sub(/When\/$/, '')
|
164
172
|
resources.inject({
|
165
|
-
'xsd' => [XSD],
|
166
|
-
'rdf' => [RDF],
|
167
|
-
'rdfs' => [RDFS],
|
168
|
-
'owl' => [
|
169
|
-
'dc' => [
|
170
|
-
'dcq' => [
|
171
|
-
'dct' => [
|
173
|
+
'xsd' => [When::Namespace::XSD ],
|
174
|
+
'rdf' => [When::Namespace::RDF ],
|
175
|
+
'rdfs' => [When::Namespace::RDFS],
|
176
|
+
'owl' => [When::Namespace::OWL ],
|
177
|
+
'dc' => [When::Namespace::DC ],
|
178
|
+
'dcq' => [When::Namespace::DCQ ],
|
179
|
+
'dct' => [When::Namespace::DCT ],
|
172
180
|
# 'tp' => [base + 'tp/'],
|
173
181
|
'ts' => [base + 'ts#']
|
174
182
|
}) {|namespace, resource|
|
@@ -315,6 +323,8 @@ module When
|
|
315
323
|
hash[key] = value if /^@/ =~ key.to_s
|
316
324
|
end
|
317
325
|
hash[RDF + 'type'] = {'@id'=>base + 'ts/' + self.class.to_s.gsub(/::/, '/')}
|
326
|
+
hash[RDFS + 'subPropertyOf'] = {'@id'=>base + 'ts#note'} if kind_of?(When::CalendarNote::NoteElement) ||
|
327
|
+
kind_of?(When::Parts::Resource) && /\/notes\// =~ iri && !leaf?
|
318
328
|
if options[:context]
|
319
329
|
options[:prefixes] ||= When::Parts::Resource.namespace_prefixes
|
320
330
|
context = hash['@context'] || {}
|
@@ -369,18 +379,20 @@ module When
|
|
369
379
|
# namespace を prefix にコンパクト化する
|
370
380
|
#
|
371
381
|
def compact_namespace_to_prefix(source, prefixes, context=nil)
|
382
|
+
return source.map {|element| compact_namespace_to_prefix(element, prefixes, context)} if source.kind_of?(Array)
|
372
383
|
return source unless prefixes
|
373
384
|
prefixes.each_pair do |key, value|
|
374
|
-
Array(value).each do |
|
375
|
-
|
376
|
-
|
385
|
+
Array(value).each do |namespace|
|
386
|
+
namespace = namespace.sub(/([a-z0-9])\z/i, '\1#')
|
387
|
+
start = source.index(namespace)
|
388
|
+
body = source[namespace.length..-1]
|
377
389
|
return key + ':' + body if start == 0 && body !~ /[:#\/]/
|
378
390
|
end
|
379
391
|
end
|
380
392
|
return source unless context
|
381
393
|
source =~ /\A((.+)([:#\/]))([^:#\/]+)\z/
|
382
394
|
namespace, item = $1.to_s, $4
|
383
|
-
if namespace =~ /^
|
395
|
+
if namespace =~ /^Ahttps?:\/\/([^.]+)\.wikipedia\.org/
|
384
396
|
prefix = "wiki_#{$1}"
|
385
397
|
elsif namespace && namespace.index(When::Parts::Resource.base_uri) == 0
|
386
398
|
label = begin When.Resource(namespace.sub(/::\z/, '')) rescue return source end
|
@@ -421,7 +433,8 @@ module When
|
|
421
433
|
hash = {}
|
422
434
|
hash[RDFS + 'label'] = names.keys.map {|key| key=='' ? names[key] : {'@language'=>key, '@value'=>names[key]}}
|
423
435
|
hash[ts + 'label'] = label
|
424
|
-
hash[ts + 'reference'] = link.values.map {|ref| {'@id'=>ref}}
|
436
|
+
hash[ts + 'reference'] = link.values.uniq.map {|ref| {'@id'=>ref}}
|
437
|
+
hash[ts + 'dbpedia'] = link.values.uniq.map {|ref| Locale._dbpedia(ref)}.compact.map {|uri| {'@id'=>uri}}
|
425
438
|
hash
|
426
439
|
end
|
427
440
|
end
|
@@ -458,7 +471,7 @@ module When
|
|
458
471
|
#
|
459
472
|
def to_uri_linkeddata(*args)
|
460
473
|
date, frame = _to_uri(to_s(*args)).split('^^', 2)
|
461
|
-
frame += '_' if
|
474
|
+
frame += '_' if /\d\z/ =~ frame
|
462
475
|
date = "#{frame}(#{date})" if frame
|
463
476
|
When::Parts::Resource.base_uri.sub(/When\/$/, 'tp/') + date
|
464
477
|
end
|
@@ -562,7 +575,14 @@ module When
|
|
562
575
|
value =_value_str(note[:note], note[:value])
|
563
576
|
end
|
564
577
|
id = compact_namespace_to_prefix(value, options[:prefixes], context)
|
565
|
-
|
578
|
+
if id.kind_of?(Array)
|
579
|
+
(0...id.length).each do |i|
|
580
|
+
id[i] = {'@id'=>id[i]} unless id[i] == value[i] && id[i] !~ /:\/\//
|
581
|
+
end
|
582
|
+
else
|
583
|
+
id = {'@id'=>id} unless id == value && id !~ /:\/\//
|
584
|
+
end
|
585
|
+
hash[compact_namespace_to_prefix(_note_str(note[:note]), options[:prefixes], context)] = id
|
566
586
|
end
|
567
587
|
hash
|
568
588
|
end
|