historical_dating 1.4.0 → 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47c1a58ce160b759e2787853d78b7aa96428fe9e2f7076fdf96158a38664902f
4
- data.tar.gz: 236c5fadd1663f7516fa09f5504d2fc5227c0290a8739814da2ebc7e0cf1dd36
3
+ metadata.gz: 8d4c906bc72a0b96c769243f6b025b0f15b6d0e96293f0a2b715706f80ff00e7
4
+ data.tar.gz: db559bafccbefa59ed6b24ff8a3d5797e197f29a323860a405fab056fb959d94
5
5
  SHA512:
6
- metadata.gz: c9f810f66539567fa1cdc3f83e22106d533e94c6bb334d28ca884d1dcbf60e078835cd2a8b47f2490149cc7e4063cb76ff6f7d2078afdf13a4432f447a2300fb
7
- data.tar.gz: 6b5ce82213a10cb258cad1062eccc431aeed3444679062b3584b08771351f467c12d65209344a4677c9380365eda9dca2ef8898c9b49742a045893ac99507a0a
6
+ metadata.gz: 61d0cbd348f836dd2bfb9e1b07ea7c5042534bbdfdfb7d0333e97f8332548d53d7668ec2606582e37acaece60fc8558257c89b21dd6504b7d544828d5aa544a0
7
+ data.tar.gz: 7b72d6a0d078730008dede42c8df257c20fdd43221d80eab32c605abb2d44b5632a3ba901eeea72624b21bc0582ae536c0f0a4840a9649b13c32f41cea290a9b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- historical_dating (1.4.0)
4
+ historical_dating (1.5.0)
5
5
  activesupport (>= 3.0.0)
6
6
  parslet (~> 2.0.0)
7
7
 
@@ -15,4 +15,4 @@ module HistoricalDating::Api
15
15
  result = parser.transform(string)
16
16
  HistoricalDating::Range.new(result[:from], result[:to])
17
17
  end
18
- end
18
+ end
@@ -3,29 +3,68 @@ class HistoricalDating::Parser < Parslet::Parser
3
3
 
4
4
  rule(:zero){ str '0' }
5
5
  rule(:natural_number){ match['1-9'] >> match['0-9'].repeat }
6
+ rule(:two_digit_natural_number){ match['1-9'] >> match['0-9'].repeat(0,1) }
7
+ rule(:more_than_two_digit_natural_number){ match['1-9'] >> match['0-9'].repeat(2,nil) }
6
8
  rule(:positive_number){ zero | natural_number }
9
+ rule(:two_digit_positive_number){ zero | two_digit_natural_number }
10
+ rule(:more_than_two_digit_positive_number){ zero | more_than_two_digit_natural_number }
7
11
  rule(:minus){ match '-' }
8
12
  rule(:whole_number_without_zero){ natural_number | minus >> natural_number }
13
+ rule(:whole_number_with_zero){ positive_number | minus >> natural_number }
14
+ rule(:two_digit_whole_number_with_zero){ two_digit_positive_number | minus >> two_digit_natural_number }
15
+ rule(:more_than_two_digit_whole_number_with_zero){ more_than_two_digit_positive_number | minus >> more_than_two_digit_natural_number }
9
16
  rule(:whole_number){ positive_number | minus >> natural_number }
10
- rule(:day){ match['1-2'] >> match['0-9'] | str('3') >> match['0-1'] | match['1-9'] | str('0') >> match['1-9'] }
11
- rule(:month){ str('1') >> match['0-2'] | match['1-9'] | str('0') >> match['1-9'] }
12
17
 
13
18
  # Utility
14
19
 
15
20
  rule(:space){ str(' ').repeat(1, nil) }
21
+ rule(:prefix){ (str('von') | str('zwischen') | str('Zwischen')) >> space }
16
22
  rule(:christ){ str('Chr.') | str('Christus') }
17
- rule(:age){ str('v.') | str('vor') | str('n.') | str('nach') }
18
- rule(:acbc){ age >> space >> christ | str('BC') | str('AC') }
19
- rule(:century_string){ str('Jahrhundert') | str('Jh.') | str('Jhd') }
20
- rule(:approx){ str('ca.') | str('um') | str('circa') }
23
+ rule(:age_before){ str('v.') | str('vor') }
24
+ rule(:age_after){ str('n.') | str('nach') }
25
+ rule(:ac){
26
+ age_after >> space >> christ |
27
+ str('AC') |
28
+ str('Ac') |
29
+ str('Anno Domini') |
30
+ str('A. D.') |
31
+ str('AD')
32
+ }
33
+ rule(:bc){
34
+ age_before >> space >> christ |
35
+ str('BC') |
36
+ str('Bc')
37
+ }
38
+ rule(:acbc){
39
+ ac | bc
40
+ }
41
+ rule(:century_string){
42
+ str('Jahrhundert') |
43
+ str('Jhd.') |
44
+ str('jhd.') |
45
+ str('Jhd') |
46
+ str('jhd') |
47
+ str('Jh.') |
48
+ str('jh.') |
49
+ str('Jh') |
50
+ str('jh')
51
+ }
52
+ rule(:approx){ str('ca.') | str('Ca.') | str('ca') | str('um') | str('Um') | str('circa') }
21
53
  rule(:unknown){ str('?') }
54
+ rule(:to_characters){
55
+ str('bis') | str('-') | str('/') | str('und')
56
+ }
57
+ rule(:to_two_digit_year){
58
+ (space >> to_characters >> space) |
59
+ (to_characters >> space) |
60
+ (space >> to_characters) |
61
+ str('/')
62
+ }
22
63
  rule(:to){
23
- ((space >> (str('bis') | str('-') | str('/')) >> space) |
24
- str('-') |
25
- str('/'))
64
+ to_two_digit_year | str('-')
26
65
  }
27
- rule(:before){ str('vor') >> space }
28
- rule(:after){ str('nach') >> space }
66
+ rule(:before){ (str('vor') | str('Vor') | str('before')) >> space }
67
+ rule(:after){ (str('Nach') | str('nach') | str('ab') | str('after')) >> space }
29
68
  rule(:negate){ str('nicht') >> space }
30
69
  rule(:part){
31
70
  str('Anfang') |
@@ -44,41 +83,69 @@ class HistoricalDating::Parser < Parslet::Parser
44
83
 
45
84
  # Dating
46
85
 
86
+ rule(:day){ match['1-2'] >> match['0-9'] | str('3') >> match['0-1'] | match['1-9'] | str('0') >> match['1-9'] }
87
+ rule(:month){ (str('0') >> match['1-9']) | (str('1') >> match['0-2']) | match['1-9'] }
88
+ rule(:two_digit_year){ (approx >> space).maybe.as(:approx) >> two_digit_whole_number_with_zero.as(:num) >> (space >> acbc).maybe.as(:acbc) }
89
+ rule(:more_than_two_digit_year){ (approx >> space).maybe.as(:approx) >> more_than_two_digit_whole_number_with_zero.as(:num) >> (space >> acbc).maybe.as(:acbc) }
90
+ rule(:year){ (approx >> space).maybe.as(:approx) >> whole_number_with_zero.as(:num) >> (space >> acbc).maybe.as(:acbc) }
47
91
  rule(:century){
48
92
  (approx >> space).maybe.as(:approx) >>
49
- positive_number.as(:num) >> str('.').as(:cd) >>
50
- (space >> century_string.as(:cs) >> (space >> acbc).maybe.as(:acbc)).maybe
93
+ natural_number.as(:num) >>
94
+ ((str('.').as(:cd) >> (space >> century_string.as(:cs) >> (space >> acbc).maybe.as(:acbc)).maybe) |
95
+ (space >> century_string.as(:cs) >> (space >> acbc).maybe.as(:acbc)))
96
+ }
97
+ rule(:century_number){
98
+ (approx >> space).maybe.as(:approx) >>
99
+ natural_number.as(:num) >>
100
+ (space >> century_string).maybe.as(:cs) >>
101
+ (space >> acbc).maybe.as(:acbc)
51
102
  }
52
- rule(:year){ (approx >> space).maybe.as(:approx) >> whole_number_without_zero.as(:num) >> (space >> acbc).maybe.as(:acbc) }
53
103
  rule(:century_part){ part.as(:part) >> space >> positive_number.as(:num) >> str('.') >> space >> century_string.as(:cs) >> (space >> acbc).maybe.as(:acbc) }
54
- rule(:european_date){ day.as(:day) >> str('.') >> month.as(:month) >> str('.') >> whole_number.as(:yearnum) }
55
- rule(:machine_date){ whole_number.as(:yearnum) >> (str('.') | str('-')) >> month.as(:month) >> (str('.') | str('-')) >> day.as(:day) }
104
+ rule(:european_date){
105
+ (day.as(:day) >> (str('.') | str('-')) >>
106
+ month.as(:month) >>
107
+ (str('.') | str('-')) >>
108
+ whole_number.as(:yearnum)) |
109
+ (month.as(:month) >>
110
+ (str('.') | str('-')) >>
111
+ whole_number.as(:yearnum))
112
+ }
113
+ rule(:machine_date){ whole_number.as(:yearnum) >> (str('.') | str('-')) >> month.as(:month) >> ((str('.') | str('-')) >> day.as(:day)).maybe }
56
114
  rule(:date){ european_date | machine_date }
57
115
  rule(:date_interval){ date.as(:from) >> to >> date.as(:to) }
58
- rule(:century_interval){ century.as(:from) >> to >> century.as(:to) }
116
+ rule(:century_interval){
117
+ prefix.maybe >>
118
+ (century.as(:from) | century_number.as(:from)) >>
119
+ to >>
120
+ century.as(:to)
121
+ }
59
122
  rule(:before_year){ negate.maybe.as(:not) >> before >> year.as(:date) }
60
123
  rule(:after_year){ negate.maybe.as(:not) >> after >> year.as(:date) }
61
124
  rule(:year_interval){
62
- year.as(:from) >> to >> (year | unknown).as(:to) |
63
- (year | unknown).as(:from) >> to >> year.as(:to)
125
+ prefix.maybe >>
126
+ (year | unknown).as(:from) >>
127
+ ((to >>
128
+ (more_than_two_digit_year | unknown).as(:to)) |
129
+ (to_two_digit_year >>
130
+ two_digit_year.as(:to)))
64
131
  }
65
132
  rule(:before_century){ before >> century.as(:century) }
66
133
 
67
134
  rule(:interval){
68
135
  before_year.as(:before_year) |
69
- after_year.as(:after_year) |
70
- date_interval.as(:date_interval) |
71
- century_interval.as(:century_interval) |
72
- year_interval.as(:year_interval) |
73
- before_century.as(:before_century)
136
+ after_year.as(:after_year) |
137
+ date_interval.as(:date_interval) |
138
+ century_interval.as(:century_interval) |
139
+ year_interval.as(:year_interval) |
140
+ before_century.as(:before_century)
74
141
  }
75
142
 
76
143
  rule(:dating){
77
144
  interval.as(:interval) |
78
- century_part.as(:century_part) |
79
- century.as(:century) |
80
- date.as(:date) |
81
- year.as(:year)
145
+ century_part.as(:century_part) |
146
+ century.as(:century) |
147
+ date.as(:date) |
148
+ year.as(:year)
82
149
  }
83
150
 
84
151
  root(:dating)
@@ -1,11 +1,19 @@
1
1
  class HistoricalDating::PreTransform < Parslet::Transform
2
2
  rule(from: subtree(:from), to: subtree(:to)) do
3
- if to[:acbc] && (to[:acbc].match(/(vor|v.) (Chr.|Christus)/) || to[:acbc].match(/BC/))
3
+ bc = to[:acbc] && (to[:acbc].match(/(vor|v.) (Chr.|Christus)/) || to[:acbc].match(/B(C|c)/))
4
+
5
+ if bc
4
6
  from[:acbc] = to[:acbc]
5
7
  end
6
8
 
7
- if to[:num].to_s.size == 2 && to[:cs].nil?
8
- # e.g.: 1890/91
9
+ # To detect the first range of e.g.: 2. - 3. Jhd, :acbc key is needed.
10
+ # TODO: Find a better solution.
11
+ if from.is_a?(Hash) && to.is_a?(Hash) && !from.key?(:acbc) && to.key?(:acbc) && !to[:acbc]
12
+ from[:acbc] = nil
13
+ end
14
+
15
+ if !bc && to[:num].to_s.size == 2 && to[:cs].nil?
16
+ # for e.g.: 1890/91 but not for e.g.: 150 - 60 v. Chr.
9
17
  to[:num] = (from[:num].to_i / 100).to_s + to[:num]
10
18
  end
11
19
 
@@ -14,18 +22,28 @@ class HistoricalDating::PreTransform < Parslet::Transform
14
22
 
15
23
  # detect century by :cd and add :cs
16
24
  rule(num: simple(:num), approx: simple(:approx), acbc: simple(:acbc), cd: simple(:cd)) do |data|
17
- data.delete :cd
18
- data.merge(
19
- cs: 'Jahrhundert'
20
- )
25
+ if data[:cd]
26
+ data.delete :cd
27
+ data.merge(
28
+ cs: 'Jahrhundert'
29
+ )
30
+ else
31
+ data.delete :cd
32
+ data
33
+ end
21
34
  end
22
35
 
23
36
  # detect century by :cd and add :cs
24
37
  rule(num: simple(:num), approx: simple(:approx), cd: simple(:cd)) do |data|
25
- data.delete :cd
26
- data.merge(
27
- cs: 'Jahrhundert'
28
- )
38
+ if data[:cd]
39
+ data.delete :cd
40
+ data.merge(
41
+ cs: 'Jahrhundert'
42
+ )
43
+ else
44
+ data.delete :cd
45
+ data
46
+ end
29
47
  end
30
48
 
31
49
  # remove :cd if :cs already present (with acbc)
@@ -39,4 +57,10 @@ class HistoricalDating::PreTransform < Parslet::Transform
39
57
  data.delete :cd
40
58
  data
41
59
  end
60
+
61
+ # remove :prefix
62
+ rule(prefix: simple(:prefix)) do |data|
63
+ data.delete :prefix
64
+ data
65
+ end
42
66
  end
@@ -15,7 +15,7 @@ class HistoricalDating::Transform < Parslet::Transform
15
15
  when "4. Viertel" then [75, 0]
16
16
  end
17
17
 
18
- if acbc.nil? || acbc.match(/(nach|n.) (Chr.|Christus)/) || acbc.match(/AC/)
18
+ if HistoricalDating::Transform.ac?(acbc)
19
19
  {
20
20
  :from => Date.new((num.to_i - 1) * 100 + modifier.first, 1, 1),
21
21
  :to => Date.new((num.to_i - 1) * 100 + 99 - modifier.last, 12, 31)
@@ -29,7 +29,7 @@ class HistoricalDating::Transform < Parslet::Transform
29
29
  end
30
30
 
31
31
  rule(:num => simple(:num), :approx => simple(:approx), :acbc => simple(:acbc), :cs => simple(:cs)) do
32
- result = if acbc.nil? || acbc.match(/(nach|n.) (Chr.|Christus)/) || acbc.match(/AC/)
32
+ result = if HistoricalDating::Transform.ac?(acbc)
33
33
  {
34
34
  :from => Date.new((num.to_i - 1) * 100, 1, 1),
35
35
  :to => Date.new((num.to_i - 1) * 100 + 99, 12, 31)
@@ -52,7 +52,7 @@ class HistoricalDating::Transform < Parslet::Transform
52
52
  rule(:num => simple(:num), :approx => simple(:approx), :acbc => simple(:acbc)) do
53
53
  modifier = (approx ? 5 : 0)
54
54
 
55
- if acbc.nil? || acbc.match(/(nach|n.) (Chr.|Christus)/) || acbc.match(/AC/)
55
+ if HistoricalDating::Transform.ac?(acbc)
56
56
  {
57
57
  :from => Date.new(num.to_i - modifier, 1, 1),
58
58
  :to => Date.new(num.to_i + modifier, 12, 31)
@@ -76,6 +76,13 @@ class HistoricalDating::Transform < Parslet::Transform
76
76
  }
77
77
  end
78
78
 
79
+ rule(:month => simple(:month), :yearnum => simple(:yearnum)) do
80
+ {
81
+ :from => Date.new(yearnum.to_i, month.to_i, 1),
82
+ :to => Date.new(yearnum.to_i, month.to_i, -1),
83
+ }
84
+ end
85
+
79
86
  rule(:date => {:from => simple(:from), :to => simple(:to)}) do
80
87
  {:from => from, :to => to}
81
88
  end
@@ -136,6 +143,10 @@ class HistoricalDating::Transform < Parslet::Transform
136
143
  end
137
144
  end
138
145
 
146
+ def self.ac?(acbc)
147
+ acbc.nil? || acbc.match(/(nach|n.) (Chr.|Christus)/) || acbc.match(/AC|Ac|Anno Domini|A. D.|AD/)
148
+ end
149
+
139
150
  def self.open_start(year)
140
151
  return {
141
152
  from: Date.new(year - distance(year), 1, 1),
@@ -1,3 +1,3 @@
1
1
  module HistoricalDating
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: historical_dating
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moritz Schepp
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-23 00:00:00.000000000 Z
11
+ date: 2020-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet