when_exe 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/lib/when_exe.rb +89 -3
  3. data/lib/when_exe/basictypes.rb +37 -7
  4. data/lib/when_exe/calendarnote.rb +18 -13
  5. data/lib/when_exe/calendartypes.rb +3 -9
  6. data/lib/when_exe/coordinates.rb +23 -373
  7. data/lib/when_exe/ephemeris.rb +7 -7
  8. data/lib/when_exe/ephemeris/notes.rb +0 -14
  9. data/lib/when_exe/events.rb +1851 -0
  10. data/lib/when_exe/icalendar.rb +121 -4
  11. data/lib/when_exe/linkeddata.rb +29 -18
  12. data/lib/when_exe/locales/akt.rb +63 -0
  13. data/lib/when_exe/locales/locale.rb +60 -11
  14. data/lib/when_exe/mini_application.rb +14 -8
  15. data/lib/when_exe/namespace.rb +42 -0
  16. data/lib/when_exe/parts/enumerator.rb +13 -2
  17. data/lib/when_exe/parts/geometric_complex.rb +51 -1
  18. data/lib/when_exe/parts/method_cash.rb +15 -10
  19. data/lib/when_exe/parts/resource.rb +47 -29
  20. data/lib/when_exe/region/chinese.rb +4 -3
  21. data/lib/when_exe/region/chinese/calendars.rb +4 -4
  22. data/lib/when_exe/region/chinese/epochs.rb +6 -6
  23. data/lib/when_exe/region/chinese/notes.rb +3 -3
  24. data/lib/when_exe/region/chinese/twins.rb +6 -6
  25. data/lib/when_exe/region/islamic.rb +1 -1
  26. data/lib/when_exe/region/japanese.rb +4 -4
  27. data/lib/when_exe/region/japanese/eclipses.rb +2 -2
  28. data/lib/when_exe/region/japanese/location.rb +93 -0
  29. data/lib/when_exe/region/japanese/notes.rb +29 -11
  30. data/lib/when_exe/region/japanese/residues.rb +1 -1
  31. data/lib/when_exe/region/japanese/twins.rb +18 -6
  32. data/lib/when_exe/region/location.rb +40 -0
  33. data/lib/when_exe/region/martian.rb +1 -1
  34. data/lib/when_exe/region/ryukyu.rb +1 -1
  35. data/lib/when_exe/spatial.rb +611 -0
  36. data/lib/when_exe/timestandard.rb +3 -3
  37. data/lib/when_exe/tmobjects.rb +32 -0
  38. data/lib/when_exe/tmposition.rb +211 -1318
  39. data/lib/when_exe/tmptypes.rb +1265 -0
  40. data/lib/when_exe/tmreference.rb +35 -0
  41. data/lib/when_exe/version.rb +3 -3
  42. data/test/events/example-datasets +7 -0
  43. data/test/events/history-dataset.csv +22 -0
  44. data/test/events/japanese-holiday-index.csv +28 -0
  45. data/test/events/japanese-holiday.csv +77 -0
  46. data/test/events/japanese-holiday.ttl +778 -0
  47. data/test/events/make_events_ttl.rb +18 -0
  48. data/test/events/mori_wikichoshi.csv +14 -0
  49. data/test/events/ndl_koyomi.csv +220 -0
  50. data/test/events/ndl_koyomi_index.csv +44 -0
  51. data/test/events/primeminister-dataset.csv +19 -0
  52. data/test/events/shogun-dataset.csv +22 -0
  53. data/test/events/test-history-dataset-edge-sparql.csv +26 -0
  54. data/test/events/test-history-dataset-edge.csv +27 -0
  55. data/test/events/test-history-dataset-sparql.csv +22 -0
  56. data/test/events/test-history-dataset.csv +23 -0
  57. data/test/events/test-history-events-edge.ttl +89 -0
  58. data/test/events/test-history-events.csv +6 -0
  59. data/test/examples/Terms.m17n +1 -1
  60. data/test/test.rb +6 -0
  61. data/test/test/coordinates.rb +2 -2
  62. data/test/test/events.rb +32 -0
  63. data/test/test/region/japanese.rb +20 -0
  64. data/test/test/region/m17n.rb +2 -2
  65. data/test/test/region/mayan.rb +6 -6
  66. data/test/test/tmposition.rb +63 -1
  67. metadata +26 -2
@@ -232,9 +232,6 @@ module When
232
232
  calendars[0] ||= When::Gregorian
233
233
  result = dates.map {|date|
234
234
  date = When.when?(date)
235
- opts = {}
236
- opts[:location] = date.location if date.location
237
- opts[:clock ] = date.clock if date.respond_to?(:clock) && date.clock
238
235
  list = calendars.dup
239
236
  (0...calendars.size).to_a.reverse.each do |i|
240
237
  case list[i]
@@ -257,15 +254,13 @@ module When
257
254
 
258
255
  if methods.size == 0
259
256
  list.map {|calendar|
260
- calendar.kind_of?(Class) ?
261
- yield(calendar.new(date, opts.dup)) :
262
- yield(calendar.^(calendar.rate_of_clock == date.time_standard.rate_of_clock ? date.to_i : date, opts))
257
+ yield(date_for_calendar(calendar, date, options))
263
258
  }
264
259
  else
265
260
  list.map {|calendar|
266
- date_for_calendar = calendar.^(calendar.rate_of_clock == date.time_standard.rate_of_clock ? date.to_i : date, opts)
261
+ date_for_cal = date_for_calendar(calendar, date, options)
267
262
  methods.map {|method|
268
- date_for_calendar.send(method[0].to_sym, method[1], &block)
263
+ date_for_cal.send(method[0].to_sym, method[1], &block)
269
264
  }
270
265
  }
271
266
  end
@@ -274,6 +269,17 @@ module When
274
269
  return result
275
270
  end
276
271
 
272
+ # 当該 Calendar or CalendarEra の TemporalPosition を生成
273
+ def date_for_calendar(calendar, date, options)
274
+ opts = {}
275
+ opts[:location] = date.location if date.location
276
+ opts[:clock ] = calendar.rate_of_clock == 1.0 ? options[:clock] :
277
+ calendar.time_basis if date.respond_to?(:clock)
278
+ calendar.kind_of?(Class) ?
279
+ calendar.new(date, opts) :
280
+ calendar.^([calendar.rate_of_clock,date.time_standard.rate_of_clock].uniq == [1.0] ? date.to_i : date, opts)
281
+ end
282
+
277
283
  # JSONで通信するために Symbol を String に変換する
278
284
  def _to_string(source)
279
285
  case source
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2015 Takashi SUGA
4
+
5
+ You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
6
+ =end
7
+
8
+ module When
9
+ module Namespace
10
+
11
+ # XML Schema Definition
12
+ XSD = 'http://www.w3.org/2001/XMLSchema'
13
+
14
+ # Resource Description Framework
15
+ RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
16
+
17
+ # Resource Description Framework Schema
18
+ RDFS = 'http://www.w3.org/2000/01/rdf-schema#'
19
+
20
+ # RDF 1.1 Concepts and Abstract Syntax
21
+ RDFC = 'http://www.w3.org/TR/rdf11-concepts/#'
22
+
23
+ # Web Ontology Language
24
+ OWL = 'http://www.w3.org/2002/07/owl#'
25
+
26
+ # Dublin Core
27
+ DC = 'http://purl.org/dc/elements/1.1/'
28
+
29
+ # Dublin Core Terms
30
+ DCQ = 'http://purl.org/dc/terms/'
31
+
32
+ # Dublin Core Types
33
+ DCT = 'http://purl.org/dc/dcmitype/'
34
+
35
+ # Friend of a Friend
36
+ FOAF = 'http://xmlns.com/foaf/0.1/'
37
+
38
+ # RDF Site Summary
39
+ RSS = 'http://purl.org/rss/1.0/'
40
+
41
+ end
42
+ end
@@ -188,7 +188,7 @@ module When::Parts
188
188
  # [ false - ない ]
189
189
  #
190
190
  def has_next?
191
- return (@count_limit != 0) && (@current != nil)
191
+ return (@count_limit != 0) && !@current.nil?
192
192
  end
193
193
 
194
194
  #
@@ -238,7 +238,17 @@ module When::Parts
238
238
  @count += 1
239
239
  _exclude(@current) if @current
240
240
  end
241
- return value
241
+ @delayed && value.respond_to?(:apply_delayed_options) ?
242
+ value.apply_delayed_options(@delayed) :
243
+ value
244
+ end
245
+
246
+ # 終端要素は含む
247
+ #
248
+ # @return [Boolean]
249
+ #
250
+ def exclude_end
251
+ false
242
252
  end
243
253
 
244
254
  # オブジェクトの生成
@@ -262,6 +272,7 @@ module When::Parts
262
272
  @options = self.class._options(args)
263
273
  @exdate = @options.delete(:exdate)
264
274
  @exevent = @options.delete(:exevent)
275
+ @delayed = @options.delete(:delayed)
265
276
  @parent, *rest = args
266
277
  _range(rest)
267
278
  _rewind
@@ -224,6 +224,56 @@ module When::Parts
224
224
  end
225
225
  end
226
226
 
227
+ # オブジェクト変換オプションの遅延適用
228
+ #
229
+ # @param [Hash] options 以下の通り
230
+ # @option options [Hash<Integrt=>When::Coordinates::Residue>] :residue
231
+ # @option options [When::TM::Clock] :clock
232
+ # @option options [Array <When::TM::Calendar>] :frame
233
+ #
234
+ # @return [When::Parts::GeometricComplex]
235
+ #
236
+ def apply_delayed_options(options)
237
+ last_node = nil
238
+ self.class.new(@node.map {|node|
239
+ point, flag, range = node
240
+ if range && last_node
241
+ [last_node + range, flag, range]
242
+ else
243
+ last_node = point.apply_delayed_options(options)
244
+ [last_node, flag]
245
+ end
246
+ }, @reverse)
247
+ end
248
+
249
+ # 平行移動(加算)
250
+ #
251
+ # @param [When::TM::Duration] duration
252
+ #
253
+ # @return [When::Parts::GeometricComplex]
254
+ #
255
+ def +(duration)
256
+ self.class.new(@node.map {|node|
257
+ new_node = node.dup
258
+ new_node[0] += duration
259
+ new_node
260
+ }, @reverse)
261
+ end
262
+
263
+ # 平行移動(減算)
264
+ #
265
+ # @param [When::TM::Duration] duration
266
+ #
267
+ # @return [When::Parts::GeometricComplex]
268
+ #
269
+ def +(duration)
270
+ self.class.new(@node.map {|node|
271
+ new_node = node.dup
272
+ new_node[0] -= duration
273
+ new_node
274
+ }, @reverse)
275
+ end
276
+
227
277
  # オブジェクトの生成
228
278
  #
229
279
  # @overload initialize(range, reverse=false)
@@ -288,7 +338,7 @@ module When::Parts
288
338
  first = [first, true]
289
339
  case last
290
340
  when Comparable ; last = [last, false]
291
- when When::TM::Duration ; last = [first[0] + last, false]
341
+ when When::TM::Duration ; last = [first[0] + last, false, last]
292
342
  when nil ; last = first
293
343
  else ; raise TypeError, "Irregal GeometricComplex Type for last element: #{last.class}"
294
344
  end
@@ -141,7 +141,7 @@ module When
141
141
  if ((name.to_s =~ /\A(_*)(.+?)_to_(.+)\z/) && respond_to?("#{$1}#{$3}_to_#{$2}_", true))
142
142
  prefix, from, to = $~[1..3]
143
143
  begin
144
- if (@_m_cash_lock_)
144
+ if @_m_cash_lock_
145
145
  return send("#{prefix}#{from}_to_#{to}_", *args, &block) unless @_m_cash_lock_.try_lock
146
146
  unlock = "ensure ; @_m_cash_lock_.locked? && @_m_cash_lock_.unlock"
147
147
  end
@@ -161,19 +161,21 @@ module When
161
161
  return inv
162
162
  #{unlock}
163
163
  end
164
+ rescue ThreadError
164
165
  end
165
166
  }
166
167
  end
167
168
  key = _key_simplefy(args)
168
169
  inv = send("#{prefix}#{from}_to_#{to}_", *args)
169
- @_m_cash_ ||= {}
170
- @_m_cash_["#{prefix}#{to}_to_#{from}"] ||= {}
171
- @_m_cash_["#{prefix}#{from}_to_#{to}"] ||= {}
170
+ @_m_cash_ ||= Hash.new {|hash,key| hash[key]={}}
172
171
  @_m_cash_["#{prefix}#{to}_to_#{from}"][_key_simplefy(inv)] = args
173
172
  @_m_cash_["#{prefix}#{from}_to_#{to}"][key] = inv
174
173
  return inv
175
174
  ensure
176
- @_m_cash_lock_ && @_m_cash_lock_.locked? && @_m_cash_lock_.unlock
175
+ begin
176
+ @_m_cash_lock_ && @_m_cash_lock_.locked? && @_m_cash_lock_.unlock
177
+ rescue ThreadError
178
+ end
177
179
  end
178
180
 
179
181
  else
@@ -181,7 +183,7 @@ module When
181
183
  respond = respond_to?("#{name}_setup", true)
182
184
  setup = respond ? "#{name}_setup(key, *args)" :
183
185
  "(@_m_cash_[\"#{name}\"][key] = #{name}_(*args))"
184
- if (@_m_cash_lock_)
186
+ if @_m_cash_lock_
185
187
  return send("#{name}_", *args, &block) unless @_m_cash_lock_.try_lock
186
188
  lock = " return #{name}_(*args) unless @_m_cash_lock_.try_lock"
187
189
  unlock = "ensure ; @_m_cash_lock_.locked? && @_m_cash_lock_.unlock"
@@ -196,18 +198,21 @@ module When
196
198
  return #{setup}
197
199
  #{unlock}
198
200
  end
201
+ rescue ThreadError
199
202
  end
200
203
  }
201
204
  key = _key_simplefy(args)
202
- @_m_cash_ ||= {}
203
- @_m_cash_["#{name}"] ||= {}
204
- if (respond)
205
+ @_m_cash_ ||= Hash.new {|hash,key| hash[key]={}}
206
+ if respond
205
207
  return send("#{name}_setup", key, *args)
206
208
  else
207
209
  return(@_m_cash_["#{name}"][key] ||= send("#{name}_", *args))
208
210
  end
209
211
  ensure
210
- @_m_cash_lock_ && @_m_cash_lock_.locked? && @_m_cash_lock_.unlock
212
+ begin
213
+ @_m_cash_lock_ && @_m_cash_lock_.locked? && @_m_cash_lock_.unlock
214
+ rescue ThreadError
215
+ end
211
216
  end
212
217
  end
213
218
  end
@@ -15,6 +15,8 @@ module When::Parts
15
15
  #
16
16
  module Resource
17
17
 
18
+ include When::Namespace
19
+
18
20
  # @private
19
21
  LabelProperty = nil
20
22
 
@@ -47,7 +49,7 @@ module When::Parts
47
49
  IRIEncode = /[#{IRIEncodeTable.keys.join('')}]/
48
50
 
49
51
  # @private
50
- IRIDecode = /#{IRIDecodeTable.keys.join('|')}/
52
+ IRIDecode = /#{IRIDecodeTable.keys.join('|')}/i
51
53
 
52
54
  # @private
53
55
  class ContentLine
@@ -198,6 +200,31 @@ module When::Parts
198
200
  end
199
201
  end
200
202
 
203
+ module Navigation
204
+ # 前のオブジェクト
205
+ #
206
+ # @return [When::Parts::Resource]
207
+ #
208
+ def prev
209
+ c = self
210
+ c = c.child[0] while c.child && c.child.size > 0
211
+ c = c._pool['.<-']
212
+ c = c.child[-1] while c && c.child && c.child.size > 0
213
+ c
214
+ end
215
+
216
+ # 次のオブジェクト
217
+ #
218
+ # @return [When::Parts::Resource]
219
+ #
220
+ def next
221
+ c = self
222
+ c = c.child[0] while c.child && c.child.size > 0
223
+ c._pool['.->']
224
+ end
225
+ alias :succ :next
226
+ end
227
+
201
228
  class << self
202
229
 
203
230
  include Pool
@@ -307,7 +334,7 @@ module When::Parts
307
334
  #
308
335
  # @param [String] iri International Resource Identifier
309
336
  # @param [String] namespace (デフォルトの名前空間, 指定がないときは名前空間を省略しない)
310
- # @param [Block] block オブジェクトが見つからない場合の代替処理
337
+ # @param [Block] block オブジェクトやパスが見つからない場合の代替処理
311
338
  #
312
339
  # @return [When::Parts::Resource]
313
340
  #
@@ -457,7 +484,7 @@ module When::Parts
457
484
 
458
485
  # @private
459
486
  def _decode(iri)
460
- iri = iri.gsub(When::Parts::Resource::IRIDecode) {|c| When::Parts::Resource::IRIDecodeTable[c]}
487
+ iri = iri.gsub(When::Parts::Resource::IRIDecode) {|c| When::Parts::Resource::IRIDecodeTable[c.upcase]}
461
488
  return iri unless iri =~ /%28/
462
489
 
463
490
  begin
@@ -515,7 +542,10 @@ module When::Parts
515
542
  return object if object
516
543
  OpenURI
517
544
  args = [path, "1".respond_to?(:force_encoding) ? 'r:utf-8' : 'r']
518
- args << {:ssl_verify_mode=>OpenSSL::SSL::VERIFY_NONE} if path =~ /\Ahttps:/
545
+ real_path = block_given? ? yield(path) : path
546
+ raise IOError, path + ': not ready' unless real_path
547
+ args = [real_path, "1".respond_to?(:force_encoding) ? 'r:utf-8' : 'r']
548
+ args << {:ssl_verify_mode=>OpenSSL::SSL::VERIFY_NONE} if real_path =~ /\Ahttps:/
519
549
  open(*args) do |file|
520
550
  resource = file.read
521
551
  case resource[0..5].upcase
@@ -525,6 +555,9 @@ module When::Parts
525
555
  when '<?XML '
526
556
  options['.'] = _xml(REXML::Document.new(_replace_tags(resource, replace)).root)
527
557
  options['.'][0].new(options)
558
+ when '# WHEN'
559
+ klass, rows = _csv(resource)
560
+ klass.new(path, rows, &block)
528
561
  else
529
562
  raise NoMethodError, 'JSON not supported' unless Object.const_defined?(:JSON)
530
563
  _internal(_json([JSON.parse(resource)]), replace, options)
@@ -683,6 +716,13 @@ module When::Parts
683
716
  json
684
717
  end
685
718
  end
719
+
720
+ # .csv フォーマットの読み込み
721
+ def _csv(csv)
722
+ rows = CSV.parse(csv)
723
+ klass = rows.shift.first[2..-1].strip.split('::').inject(Object) {|ns, sym| ns.const_get(sym)}
724
+ [klass, rows]
725
+ end
686
726
  end
687
727
 
688
728
  include Synchronize
@@ -731,12 +771,13 @@ module When::Parts
731
771
  # @return [Sring]
732
772
  #
733
773
  def iri(prefix=false)
774
+ return nil unless @_pool
734
775
  unless @iri
735
776
  root = @_pool['..']
736
777
  path = root.instance_of?(String) ? root : label.to_s
737
778
  if root.respond_to?(:iri)
738
779
  root_iri = root.iri
739
- path = root_iri + '::' + path if root_iri
780
+ path = root_iri + '::' + path.gsub(/[<>]/) {|char|'%' + char.ord.to_s(16)} if root_iri
740
781
  end
741
782
  @iri = path
742
783
  end
@@ -825,29 +866,6 @@ module When::Parts
825
866
  other.include?(self)
826
867
  end
827
868
 
828
- # 前のオブジェクト
829
- #
830
- # @return [When::Parts::Resource]
831
- #
832
- def prev
833
- c = self
834
- c = c.child[0] while c.child && c.child.size > 0
835
- c = c._pool['.<-']
836
- c = c.child[-1] while c && c.child && c.child.size > 0
837
- c
838
- end
839
-
840
- # 次のオブジェクト
841
- #
842
- # @return [When::Parts::Resource]
843
- #
844
- def next
845
- c = self
846
- c = c.child[0] while c.child && c.child.size > 0
847
- c._pool['.->']
848
- end
849
- alias :succ :next
850
-
851
869
  # オブジェクト包含階層の末端か?
852
870
  #
853
871
  # @return [Boolean]
@@ -871,7 +889,7 @@ module When::Parts
871
889
  return false unless leaf.equal?(root._pool[leaf.label])
872
890
  leaf = root
873
891
  end
874
- Resource._pool.value?(leaf)
892
+ Resource._pool.values.map {|resource| resource.object_id}.include?(leaf.object_id)
875
893
  end
876
894
 
877
895
  # When::BasicTypes::M17n の生成/参照
@@ -156,9 +156,9 @@ module When
156
156
  @repeat_count = @repeat_count.to_i
157
157
 
158
158
  # 太陽の盈縮表の生成
159
- # [先後數, 朓朒数, (立成b, 立成c)]
159
+ # [先後數, 朓朒数, (初率b, 別差c)]
160
160
  # ↓
161
- # [区間の始めの冬至からの経過日数, 朓朒数, 立成b, 立成c]
161
+ # [区間の始めの冬至からの経過日数, 朓朒数, 初率b, 別差c]
162
162
  @s = @s.map {|item| item.dup}
163
163
  if @rissei # 立成の計算・比較
164
164
  puts "\n ["+ @denominator.to_s + "]" if @rissei == @rissei.upcase
@@ -218,6 +218,7 @@ module When
218
218
  t02 / 2.0
219
219
  end
220
220
  r = v < 0 ? 12.0/(17*11) : 12.0/(16*11)
221
+ # 初率b, 別差c
221
222
  [v * r, (t12-t01) * r * r]
222
223
  end
223
224
 
@@ -660,7 +661,7 @@ module When
660
661
  @anomalistic_month_shift = @anomalistic_month_shift.to_f # 転應(暦元前近/遠地点通過から暦元天正冬至までの日数)
661
662
  @anomaly_method = @anomaly_method || 'a' # (経朔-定朔)の計算方法
662
663
  @anomaly_precision = (@anomaly_precision || 1.0E-5).to_f # c 方式 での収束判定誤差 / 日
663
- @solar_weight = @solar_weight || 0 # (経朔-定朔)の計算で用いる実行差での太陽盈縮の重み(0:非考慮,1:考慮)
664
+ @solar_weight = (@solar_weight || 0 ).to_i # (経朔-定朔)の計算で用いる実行差での太陽盈縮の重み(0:非考慮,1:考慮)
664
665
  @lunar_unit = @lunar_unit.to_f # 太陰遅速計算用招差法定数の時間の単位(限)
665
666
  @m = _rissei_j(@m) # 太陰遅速計算用招差法定数
666
667
  @s = _rissei_j(@s) # 太陽盈縮計算用招差法定数
@@ -386,8 +386,8 @@ module When
386
386
  # 北周・隋:: 大象暦 579 - 583
387
387
  # 隋:: 開皇暦 584 - 596
388
388
  # 隋・唐:: 大業暦 597 - 618
389
- # 唐:: 戊寅元暦 619 - 664
390
- # 唐・周:: 麟徳暦 665 - 728 総法 1340(小余の分母)
389
+ # 唐:: 戊寅元暦 619 - 665
390
+ # 唐・周:: 麟徳暦 666 - 728 総法 1340(小余の分母)
391
391
  # 唐:: 大衍暦 729 - 761 通法 3040( 〃 )
392
392
  # 唐:: 五紀暦 762 - 783 通法 1340( 〃 )
393
393
  # 唐:: 正元暦 784 - 806
@@ -530,8 +530,8 @@ module When
530
530
  # 『唐・日本における進朔に関する研究』(2013-10版)を使用する場合の朔閏表(一部修正あり)
531
531
  #
532
532
  # 隋・唐:: 大業暦 618
533
- # 唐:: 戊寅元暦 619 - 664
534
- # 唐・周:: 麟徳暦 665 - 728 総法 1340(小余の分母)
533
+ # 唐:: 戊寅元暦 619 - 665
534
+ # 唐・周:: 麟徳暦 666 - 728 総法 1340(小余の分母)
535
535
  # 唐:: 大衍暦 729 - 761 通法 3040( 〃 )
536
536
  # 唐:: 五紀暦 762 - 783 通法 1340( 〃 )
537
537
  # 唐:: 正元暦 784 - 806