scripref 0.15.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +9 -0
- data/Rakefile +0 -10
- data/lib/scripref/basic_methods.rb +3 -1
- data/lib/scripref/bookname.rb +6 -4
- data/lib/scripref/bookorder.rb +20 -0
- data/lib/scripref/const_reader.rb +2 -1
- data/lib/scripref/english.rb +10 -6
- data/lib/scripref/formatter.rb +5 -4
- data/lib/scripref/german.rb +17 -13
- data/lib/scripref/include.rb +3 -1
- data/lib/scripref/parser.rb +17 -15
- data/lib/scripref/passage.rb +39 -45
- data/lib/scripref/pipelining.rb +2 -1
- data/lib/scripref/processor.rb +3 -2
- data/lib/scripref.rb +5 -2
- data/regtest/formatter.rb +2 -2
- data/regtest/formatter.yml +192 -192
- data/regtest/parser.yml +105 -105
- data/regtest/processor.yml +265 -265
- data/scripref.gemspec +17 -31
- data/test/test_bookname.rb +4 -2
- data/test/test_english.rb +16 -14
- data/test/test_formatter.rb +54 -52
- data/test/test_german.rb +12 -10
- data/test/test_helper.rb +3 -1
- data/test/test_integration.rb +3 -1
- data/test/test_parser.rb +66 -64
- data/test/test_passage.rb +7 -18
- data/test/test_pipelining.rb +3 -1
- data/test/test_processor.rb +20 -18
- metadata +11 -12
- data/.aspell.pws +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18851c425f1c4a9504ede784a43a46d80a668c9059bc000d6f866b6ce3a5ffe2
|
4
|
+
data.tar.gz: e7cdaa42c34785fd755dc747247ea100ca757c9fed062cca691060c8c5288c3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01c5874544e15524587022c02e5e3002fa170f07889248f1937410671f94e03db239ec8fd5cfd47db8dee687c7b41b9ba56a4fb8fd12ebffb6f050b3a64eb2c3
|
7
|
+
data.tar.gz: 1745d52b620f5b71e9f12627a9b797f668f160e914de8869ab05c692218b87567aa08ff4eae6b2d04e9cad36dd43c1d868d5c8ac4f4b47cfcfeb19e41eea1063
|
data/Changelog
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
1.1.0
|
2
|
+
Adapt German abbreviations.
|
3
|
+
|
4
|
+
1.0.0
|
5
|
+
Major release with following two incompatible changes:
|
6
|
+
Use OSIS abbreviations for books.
|
7
|
+
Remove Passage#+ and Passage#-. This methods seems not to be so useful.
|
8
|
+
Further a new module Bookorder is introduced.
|
9
|
+
|
1
10
|
0.15.0
|
2
11
|
Add some more abbreviations for German book names.
|
3
12
|
|
data/Rakefile
CHANGED
@@ -2,19 +2,9 @@ require 'rim/tire'
|
|
2
2
|
require 'rim/regtest'
|
3
3
|
require 'rim/version'
|
4
4
|
|
5
|
-
$:.unshift File.dirname(__FILE__) + '/lib'
|
6
|
-
require 'scripref'
|
7
|
-
|
8
5
|
Rim.setup do
|
9
|
-
name 'scripref'
|
10
|
-
authors 'Jan Friedrich'
|
11
|
-
email 'janfri26@gmail.com'
|
12
|
-
homepage 'https://github.com/janfri/scripref'
|
13
|
-
version Scripref::VERSION
|
14
|
-
summary 'Library for parsing scripture references in real texts.'
|
15
6
|
if feature_loaded? 'rim/irb'
|
16
7
|
irb_requires %w(scripref scripref/include scripref/pipelining)
|
17
8
|
end
|
18
|
-
ruby_version '>=2.5.0'
|
19
9
|
test_warning false
|
20
10
|
end
|
data/lib/scripref/bookname.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module Scripref
|
4
5
|
|
5
6
|
class Bookname
|
6
7
|
|
7
|
-
attr_reader :names, :abbrevs
|
8
|
+
attr_reader :osis_id, :names, :abbrevs
|
8
9
|
|
9
|
-
def initialize names
|
10
|
+
def initialize osis_id:, names:, abbrevs:
|
11
|
+
@osis_id = osis_id
|
10
12
|
@names = Array(names)
|
11
13
|
@abbrevs = Array(abbrevs)
|
12
14
|
end
|
@@ -20,7 +22,7 @@ module Scripref
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def to_s
|
23
|
-
@
|
25
|
+
@osis_id
|
24
26
|
end
|
25
27
|
|
26
28
|
alias to_str to_s
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Scripref
|
5
|
+
|
6
|
+
# Constants of different orderings of bible books using standardized IDs
|
7
|
+
# (see https://wiki.crosswire.org/OSIS_Book_Abbreviations)
|
8
|
+
module Bookorder
|
9
|
+
|
10
|
+
# Canonical order (the default order without any apocryphal books)
|
11
|
+
CANONICAL = %i[
|
12
|
+
Gen Exod Lev Num Deut Josh Judg Ruth 1Sam 2Sam 1Kgs 2Kgs 1Chr 2Chr Ezra
|
13
|
+
Neh Esth Job Ps Prov Eccl Song Isa Jer Lam Ezek Dan Hos Joel Amos Obad
|
14
|
+
Jonah Mic Nah Hab Zeph Hag Zech Mal Matt Mark Luke John Acts Rom 1Cor
|
15
|
+
2Cor Gal Eph Phil Col 1Thess 2Thess 1Tim 2Tim Titus Phlm Heb Jas 1Pet
|
16
|
+
2Pet 1John 2John 3John Jude Rev
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/scripref/english.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
3
4
|
require 'scripref/const_reader'
|
4
5
|
|
5
6
|
module Scripref
|
@@ -31,7 +32,10 @@ module Scripref
|
|
31
32
|
END
|
32
33
|
|
33
34
|
# Array of book names.
|
34
|
-
BOOK_NAMES =
|
35
|
+
BOOK_NAMES = Bookorder::CANONICAL.zip(book_names, book_abbrevs).map {|osis_book_id, names, abbrevs| Bookname.new(osis_id: osis_book_id, names: names, abbrevs: abbrevs)}
|
36
|
+
|
37
|
+
# Map of OSIS book ID to instance of Bookname
|
38
|
+
OSIS_BOOK_ID_TO_BOOK_NAME = Bookorder::CANONICAL.zip(BOOK_NAMES).map {|id, n| [id, n]}.to_h
|
35
39
|
|
36
40
|
# Separator between chapter and verse.
|
37
41
|
CV_SEPARATOR = ':'
|
@@ -73,9 +77,9 @@ module Scripref
|
|
73
77
|
POSTFIX_MORE_FOLLOWING_VERSES_RE = /ff\b\s*/o
|
74
78
|
|
75
79
|
# Check if book has only one chapter
|
76
|
-
# @param
|
77
|
-
def book_has_only_one_chapter?
|
78
|
-
[
|
80
|
+
# @param osis_id OSIS-ID of the book
|
81
|
+
def book_has_only_one_chapter? osis_id
|
82
|
+
%i[Obad Phlm 2John 3John Jude].include?(osis_id)
|
79
83
|
end
|
80
84
|
|
81
85
|
# Regular expression to match punctuation marks
|
data/lib/scripref/formatter.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module Scripref
|
4
5
|
|
@@ -27,9 +28,9 @@ module Scripref
|
|
27
28
|
end
|
28
29
|
|
29
30
|
# Formats a book
|
30
|
-
# @param
|
31
|
-
def format_book
|
32
|
-
|
31
|
+
# @param osis_book_id OSIS-ID for book
|
32
|
+
def format_book osis_book_id
|
33
|
+
osis_book_id_to_book_name[osis_book_id].send @bookformat
|
33
34
|
end
|
34
35
|
|
35
36
|
# Formats a chapter
|
data/lib/scripref/german.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
3
4
|
require 'scripref/const_reader'
|
4
5
|
|
5
6
|
module Scripref
|
@@ -19,19 +20,22 @@ module Scripref
|
|
19
20
|
END
|
20
21
|
|
21
22
|
book_abbrevs = <<-END.strip.split(/,\s*/).map {|e| e.split('|')}
|
22
|
-
1.
|
23
|
-
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
# Array of book names.
|
34
|
-
BOOK_NAMES =
|
35
|
+
BOOK_NAMES = Bookorder::CANONICAL.zip(book_names, book_abbrevs).map {|osis_book_id, names, abbrevs| Bookname.new(osis_id: osis_book_id, names: names, abbrevs: abbrevs)}
|
36
|
+
|
37
|
+
# Map of OSIS book ID to instance of Bookname
|
38
|
+
OSIS_BOOK_ID_TO_BOOK_NAME = Bookorder::CANONICAL.zip(BOOK_NAMES).map {|id, n| [id, n]}.to_h
|
35
39
|
|
36
40
|
# Separator between chapter and verse.
|
37
41
|
CV_SEPARATOR = ','
|
@@ -73,9 +77,9 @@ module Scripref
|
|
73
77
|
POSTFIX_MORE_FOLLOWING_VERSES_RE = /ff\b\s*/o
|
74
78
|
|
75
79
|
# Check if book has only one chapter
|
76
|
-
# @param
|
77
|
-
def book_has_only_one_chapter?
|
78
|
-
[
|
80
|
+
# @param osis_id OSIS-ID of the book
|
81
|
+
def book_has_only_one_chapter? osis_id
|
82
|
+
%i[Obad Phlm 2John 3John Jude].include?(osis_id)
|
79
83
|
end
|
80
84
|
|
81
85
|
# Regular expression to match punctuation marks
|
data/lib/scripref/include.rb
CHANGED
data/lib/scripref/parser.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: false
|
3
|
+
|
2
4
|
require 'scripref/basic_methods'
|
3
5
|
require 'strscan'
|
4
6
|
|
@@ -35,7 +37,7 @@ module Scripref
|
|
35
37
|
def b1
|
36
38
|
s = scan(book_re) or return nil
|
37
39
|
@text << s
|
38
|
-
@b1 = @b2 =
|
40
|
+
@b1 = @b2 = abbrev2osis_book_id(s)
|
39
41
|
@c1 = @v1 = @c2 = @v2 = nil
|
40
42
|
|
41
43
|
if pass_sep
|
@@ -108,7 +110,7 @@ module Scripref
|
|
108
110
|
def b2
|
109
111
|
s = scan(book_re) or return nil
|
110
112
|
@text << s
|
111
|
-
@b2 =
|
113
|
+
@b2 = abbrev2osis_book_id(s)
|
112
114
|
@c2 = @v2 = nil
|
113
115
|
|
114
116
|
if pass_sep
|
@@ -237,10 +239,10 @@ module Scripref
|
|
237
239
|
@a1 = @a2 = nil
|
238
240
|
end
|
239
241
|
|
240
|
-
def
|
242
|
+
def abbrev2osis_book_id str
|
241
243
|
s = str.strip
|
242
244
|
s.sub! /\.$/, ''
|
243
|
-
|
245
|
+
str2osis_book_id(s) or str2osis_book_id(abbrev2book(s))
|
244
246
|
end
|
245
247
|
|
246
248
|
def abbrev2book str
|
@@ -250,7 +252,7 @@ module Scripref
|
|
250
252
|
pattern = s.chars.map {|c| Regexp.escape(c) << '[^#]*'}.join
|
251
253
|
re = /(?<=#)#{pattern}(?=#)/
|
252
254
|
names = @books_str.scan(re)
|
253
|
-
uniq_numbers = names.map {|n|
|
255
|
+
uniq_numbers = names.map {|n| str2osis_book_id(n)}.uniq
|
254
256
|
if uniq_numbers.size != 1
|
255
257
|
unscan
|
256
258
|
give_up format("Abbreviation %s is ambiguous it matches %s!", s, names.join(', '))
|
@@ -258,23 +260,23 @@ module Scripref
|
|
258
260
|
names.first
|
259
261
|
end
|
260
262
|
|
261
|
-
def
|
262
|
-
unless @
|
263
|
-
@
|
264
|
-
book_names.
|
263
|
+
def init_str2osis_book_id
|
264
|
+
unless @str2osis_book_id
|
265
|
+
@str2osis_book_id = {}
|
266
|
+
book_names.each do |bn|
|
265
267
|
bn.names.each do |n|
|
266
|
-
@
|
268
|
+
@str2osis_book_id[n] = bn.osis_id
|
267
269
|
end
|
268
270
|
bn.abbrevs.each do |n|
|
269
|
-
@
|
271
|
+
@str2osis_book_id[n] = bn.osis_id
|
270
272
|
end
|
271
273
|
end
|
272
274
|
end
|
273
275
|
end
|
274
276
|
|
275
|
-
def
|
276
|
-
|
277
|
-
@
|
277
|
+
def str2osis_book_id str
|
278
|
+
init_str2osis_book_id
|
279
|
+
@str2osis_book_id[str]
|
278
280
|
end
|
279
281
|
|
280
282
|
def inspect
|
data/lib/scripref/passage.rb
CHANGED
@@ -1,66 +1,27 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
module Scripref
|
3
5
|
|
4
6
|
Passage = Struct.new(:text, :b1, :c1, :v1, :b2, :c2, :v2, :a1, :a2, keyword_init: true) do
|
5
7
|
|
6
8
|
include Comparable
|
7
9
|
|
8
|
-
def + other
|
9
|
-
to_a.zip(other.to_a).map {|a, b| a + b}
|
10
|
-
end
|
11
|
-
|
12
|
-
def - other
|
13
|
-
to_a.zip(other.to_a).map {|a, b| b - a}
|
14
|
-
end
|
15
|
-
|
16
10
|
def to_a
|
17
11
|
[b1, c1, v1, b2, c2, v2]
|
18
12
|
end
|
19
13
|
|
20
14
|
def <=> other
|
21
15
|
return unless other.kind_of? Passage
|
22
|
-
self.
|
23
|
-
end
|
24
|
-
|
25
|
-
# Returns a copy which is comparable, that means
|
26
|
-
# all values are numeric.
|
27
|
-
# This is a heuristic approach.
|
28
|
-
def make_comparable max: 999, ff: 3
|
29
|
-
self.dup.make_comparable! max: max, ff: ff
|
30
|
-
end
|
31
|
-
|
32
|
-
# Makes the Passage instance comparable, that means
|
33
|
-
# all values are numeric.
|
34
|
-
# This is a heuristic approach.
|
35
|
-
def make_comparable! max: 999, ff: 3
|
36
|
-
self.b1 ||= 1
|
37
|
-
self.c1 ||= 1
|
38
|
-
self.v1 ||= 1
|
39
|
-
self.b2 ||= max
|
40
|
-
self.c2 ||= max
|
41
|
-
self.v2 ||= max
|
42
|
-
if self.v2 == :f
|
43
|
-
self.v2 = self.v1 + 1
|
44
|
-
end
|
45
|
-
if self.v2 == :ff
|
46
|
-
self.v2 = self.v1 + ff
|
47
|
-
end
|
48
|
-
self
|
49
|
-
end
|
50
|
-
|
51
|
-
# Checks if the instance is comparable, that means
|
52
|
-
# all values are numeric and so the <=> method
|
53
|
-
# can be applied.
|
54
|
-
def comparable?
|
55
|
-
to_a.map {|e| Numeric === e}.uniq == [true]
|
16
|
+
self.to_numeric_array <=> other.to_numeric_array
|
56
17
|
end
|
57
18
|
|
58
19
|
# Returns true if the instance and the given passage overlap.
|
59
20
|
# That means both has at least one verse in common.
|
60
21
|
def overlap? passage
|
61
22
|
fail ArgumentError, 'value must be a passage' unless passage.kind_of? Passage
|
62
|
-
a = self.
|
63
|
-
b = passage.
|
23
|
+
a = self.to_numeric_array
|
24
|
+
b = passage.to_numeric_array
|
64
25
|
[a[0..2] <=> b[3..5], b[0..2] <=> a[3..5]].max < 1
|
65
26
|
end
|
66
27
|
|
@@ -74,7 +35,40 @@ module Scripref
|
|
74
35
|
[b2, c2, v2]
|
75
36
|
end
|
76
37
|
|
38
|
+
def to_numeric_array max: 999, ff: 3
|
39
|
+
_b1 = Passage.book_id2num[b1]
|
40
|
+
_c1 = c1 || 1
|
41
|
+
_v1 = v1 || 1
|
42
|
+
_b2 = Passage.book_id2num[b2]
|
43
|
+
_c2 = c2 || max
|
44
|
+
_v2 = v2 || max
|
45
|
+
if _v2 == :f
|
46
|
+
_v2 = _v1 + 1
|
47
|
+
end
|
48
|
+
if _v2 == :ff
|
49
|
+
_v2 = _v1 + ff
|
50
|
+
end
|
51
|
+
[_b1, _c1, _v1, _b2, _c2, _v2]
|
52
|
+
end
|
53
|
+
|
77
54
|
alias to_s text
|
55
|
+
|
56
|
+
@book_id2num = {}
|
57
|
+
osis_book_ids = %i[
|
58
|
+
Gen Exod Lev Num Deut Josh Judg Ruth 1Sam 2Sam 1Kgs 2Kgs 1Chr 2Chr Ezra
|
59
|
+
Neh Esth Job Ps Prov Eccl Song Isa Jer Lam Ezek Dan Hos Joel Amos Obad
|
60
|
+
Jonah Mic Nah Hab Zeph Hag Zech Mal Matt Mark Luke John Acts Rom 1Cor
|
61
|
+
2Cor Gal Eph Phil Col 1Thess 2Thess 1Tim 2Tim Titus Phlm Heb Jas 1Pet
|
62
|
+
2Pet 1John 2John 3John Jude Rev
|
63
|
+
]
|
64
|
+
osis_book_ids.each_with_index do |book_id, i|
|
65
|
+
@book_id2num[book_id] = i+1
|
66
|
+
end
|
67
|
+
|
68
|
+
class << self
|
69
|
+
attr_reader :book_id2num
|
70
|
+
end
|
71
|
+
|
78
72
|
end
|
79
73
|
|
80
74
|
end
|
data/lib/scripref/pipelining.rb
CHANGED
data/lib/scripref/processor.rb
CHANGED
data/lib/scripref.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'delegate'
|
3
5
|
|
4
6
|
module Scripref
|
5
7
|
|
6
|
-
VERSION = '
|
8
|
+
VERSION = '1.1.0'
|
7
9
|
|
8
10
|
autoload :Bookname, 'scripref/bookname'
|
11
|
+
autoload :Bookorder, 'scripref/bookorder'
|
9
12
|
autoload :English, 'scripref/english'
|
10
13
|
autoload :Formatter, 'scripref/formatter'
|
11
14
|
autoload :German, 'scripref/german'
|