izhitsa 0.0.1
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
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +23 -0
- data/README.md +40 -0
- data/lib/izhitsa/version.rb +5 -0
- data/lib/izhitsa.rb +126 -0
- metadata +95 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: '08132d3346333348e4d8b72c97e418085b469b36ed2016fcef1c2f4ed5fe6684'
|
|
4
|
+
data.tar.gz: 228ec5d725f940f941fd99c6f33999d85ae71dd786e208fa5bcc5add5fd7ab44
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d44d0b41dec799365b41ade0544f844bd8bfc03748e7bf9cdbdfb2c2865e22ab15777e86eb88263c3f1029128dd007293a2c5fb929d7c05a1b584ca613ac9cf8
|
|
7
|
+
data.tar.gz: d78adda526f286d8c7127425bf46bffbeddff8686d3defbf6a2b2f7449893d5ab712585db24aaee745f06c5ecc131aafe3f9e149e8c3facc680c9c9780b0c3dd
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Copyright (c) 2024 Vyacheslav Konovalov
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
data/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[](https://rubygems.org/gems/izhitsa)
|
|
2
|
+
[](https://github.com/palkan/izhitsa/actions)
|
|
3
|
+
[](https://github.com/K0Hb/izhitsa/actions)
|
|
4
|
+
|
|
5
|
+
# Ижица
|
|
6
|
+
|
|
7
|
+
Перевод современного русского текста на дореволюционную орфографию
|
|
8
|
+
|
|
9
|
+
## Установка
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
# Gemfile
|
|
13
|
+
gem "izhitsa"
|
|
14
|
+
```
|
|
15
|
+
А затем выполнить:
|
|
16
|
+
|
|
17
|
+
$ bundle install
|
|
18
|
+
|
|
19
|
+
Или установите его самостоятельно как:
|
|
20
|
+
|
|
21
|
+
$ gem install izhitsa
|
|
22
|
+
|
|
23
|
+
### Поддерживаемые Ruby версии
|
|
24
|
+
|
|
25
|
+
- Ruby (MRI) >= 2.7.0
|
|
26
|
+
- JRuby >= 9.3.0
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Использование
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
Izhitsa.convert('Главное, самому себе не лгите. Лгущий самому себе и собственную ложь свою слушающий до того доходит, что уж никакой правды ни
|
|
33
|
+
в себе, ни кругом не различает, а стало быть, входит в неуважение и к себе и к другим. Не уважая же никого, перестает любить, а чтобы, не имея любви, занять
|
|
34
|
+
себя и развлечь, предается страстям и грубым сладостям и доходит совсем до скотства в пороках своих, а все от беспрерывной лжи и людям и себе самом. «Братья Карамазовы»')
|
|
35
|
+
=> "Главное, самому себѣ нѣ лгитѣ. Лгущій самому себѣ и собствѣнную ложь свою слушающій до того доходитъ, что ужъ никакой правды ни в себѣ, ни кругомъ нѣ различаетъ, а стало быть, входитъ в неуваженіе и к себѣ и к другимъ. Не уважая жѣ никого, перестаетъ любить, а чтобы, нѣ имѣя любви, занять сѣбя и развлечь, предается страстямъ и грубымъ сладостямъ и доходитъ совсѣмъ до скотства в порокахъ своихъ, а всѣ отъ безпрерывной лжи и людямъ и себѣ самомъ. «Братья Карамазовы»"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Лицензия
|
|
39
|
+
|
|
40
|
+
Исходный код распространяется под лицензией [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/izhitsa.rb
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Izhitsa
|
|
4
|
+
ALL_LATTERS = %w[А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я]
|
|
5
|
+
UPPER_CONSONANT_LETTERS = %w[Б В Г Д Ж З К Л М Н П Р С Т Ф Х Ц Ч Ш Щ].freeze
|
|
6
|
+
LOWER_CONSONANT_LETTERS = %w[б в г д ж з к л м н п р с т ф х ц ч ш щ].freeze
|
|
7
|
+
UPPER_VOWEL_LETTERS = %w[А Е Ё И Й О У Ы Э Ю Я].freeze
|
|
8
|
+
LOWER_VOWEL_LETTERS = %w[а е ё и й о у ы э ю я].freeze
|
|
9
|
+
|
|
10
|
+
FITA_WORDS = %w[Агафья Анфимъ Афанасій Афина Варфоломей Голіафъ Евфимій Марфа Матфей Мефодій Нафанаилъ Парфенонъ Пифагоръ Руфь Саваофъ
|
|
11
|
+
Тимофей Эсфирь Іудифь Фаддей Фекла Фемида Фемистоклъ Феодоръ Федя Феодосій Феодосія Феодотъ Феофанъ Феофилъ Ферапонтъ Фома Фоминична
|
|
12
|
+
Афины Афонъ Вифанія Вифезда Вифинія Вифлеемъ Вифсаида Гефсиманія Голгофа Карфагенъ Коринфъ Марафонъ Парфія Парфенонъ Эфіопія Фаворъ
|
|
13
|
+
Феодосія Фермофилы Фессалія Фессалоники Фивы Фракія Коринфяне Парфяне Скифы Эфіопы Фиване Анафема Акафистъ Апофеозъ Апофегма Арифметика
|
|
14
|
+
Дифирамбъ Ефимоны Кафолическій Кафедра Кафизма Кифара Левіафанъ Логарифмъ Марафонъ Мифъ Мифологія Монофелитство Орфографія Орфоэпія
|
|
15
|
+
Пафосъ Рифма Эфиръ Фиміамъ Фита].freeze
|
|
16
|
+
|
|
17
|
+
IZHITSA_WORDS = %w[миро иподіаконъ ипостась символъ синодъ].freeze
|
|
18
|
+
|
|
19
|
+
# пишется .рѣ. && .лѣ.
|
|
20
|
+
IAT_WORDS = %w[апрель хлебъ].freeze
|
|
21
|
+
|
|
22
|
+
# иностранные слова, в которых ять не пишется
|
|
23
|
+
IAT_FOREIGN_WORDS = %w[ариѳметика математика алгебра литература метафора кинетика генетика реле].freeze
|
|
24
|
+
|
|
25
|
+
EGO_WORDS = %w[вашего всего его моего нашего него нечего ничего своего сего твоего чего].freeze
|
|
26
|
+
|
|
27
|
+
def self.convert(str)
|
|
28
|
+
return str unless str.is_a? String
|
|
29
|
+
|
|
30
|
+
each_all_words(str) do |word|
|
|
31
|
+
word = use_rule_1(word)
|
|
32
|
+
word = use_rule_2(word)
|
|
33
|
+
word = use_rule_3(word)
|
|
34
|
+
word = use_rule_4(word)
|
|
35
|
+
word = use_rule_5(word)
|
|
36
|
+
word = use_rule_6(word)
|
|
37
|
+
word = use_rule_7(word)
|
|
38
|
+
word = use_rule_8(word)
|
|
39
|
+
|
|
40
|
+
word
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
class << self
|
|
47
|
+
def each_all_words(text, &block)
|
|
48
|
+
text.gsub(/[а-яА-ЯёЁ]{2,}/) { |word| yield word }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def use_rule_1(word) # окончания на Ъ
|
|
52
|
+
return word unless word.downcase.end_with?(*LOWER_CONSONANT_LETTERS)
|
|
53
|
+
|
|
54
|
+
word.downcase.end_with?(*LOWER_CONSONANT_LETTERS)
|
|
55
|
+
|
|
56
|
+
x = (word[-1] == word[-1].upcase) ? "Ъ" : "ъ"
|
|
57
|
+
|
|
58
|
+
"#{word}#{x}"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def use_rule_2(word) # i
|
|
62
|
+
word.gsub(/(и)([#{UPPER_VOWEL_LETTERS}#{LOWER_VOWEL_LETTERS}])/, 'і\2')
|
|
63
|
+
.gsub(/(И)([#{UPPER_VOWEL_LETTERS}#{LOWER_VOWEL_LETTERS}])/, 'І\2')
|
|
64
|
+
.gsub(/(Й)([#{UPPER_VOWEL_LETTERS}#{LOWER_VOWEL_LETTERS}])/, 'І\2')
|
|
65
|
+
.gsub(/(й)([#{UPPER_VOWEL_LETTERS}#{LOWER_VOWEL_LETTERS}])/, 'і\2')
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def use_rule_3(word) # Фита(ѳ)
|
|
69
|
+
return word unless FITA_WORDS.include?(word.capitalize)
|
|
70
|
+
|
|
71
|
+
word.gsub("ф", "ѳ").gsub("Ф", "Ѳ")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def use_rule_4(word) # Ижица(ѵ)
|
|
75
|
+
return word unless IZHITSA_WORDS.include?(word.downcase)
|
|
76
|
+
|
|
77
|
+
word.gsub("и", "ѵ").gsub("и", "Ѵ")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def use_rule_5(word) # приставки
|
|
81
|
+
return word unless word.downcase.match?(/^(ис|вос|рас|рос|нис)с.*/) ||
|
|
82
|
+
word.downcase.start_with?("бес", "черес", "чрес")
|
|
83
|
+
|
|
84
|
+
word.sub("с", "з").sub("С", "З")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def use_rule_6(word) # окончание
|
|
88
|
+
return word if EGO_WORDS.include?(word.downcase)
|
|
89
|
+
|
|
90
|
+
if word.downcase.match?(/.*[жшчщ](его|егос)/)
|
|
91
|
+
word.sub("его", "аго").sub("ЕГО", "АГО").sub("егося", "агося").sub("ЕГОСЯ", "АГОСЯ")
|
|
92
|
+
elsif word.downcase.end_with?("его", "егося")
|
|
93
|
+
word.sub("его", "яго").sub("ЕГО", "ЯГО").sub("егося", "ягося").sub("ЕГОСЯ", "ЯГОСЯ")
|
|
94
|
+
else
|
|
95
|
+
word
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def use_rule_7(word) # Ять(ѣ)
|
|
100
|
+
# Дописать правила, самый сложный блок. TODO
|
|
101
|
+
return word if IAT_FOREIGN_WORDS.include?(word.downcase)
|
|
102
|
+
|
|
103
|
+
return word if word.downcase.count("ё") == 1 && word.downcase.count("е").zero?
|
|
104
|
+
|
|
105
|
+
return word if word.downcase.count("е") == 2 && word.downcase.match?(/(ере|еле)/) && !word.downcase.end_with?("ейшій", "ЕЙШІЙ", "еть", "ЕТЬ")
|
|
106
|
+
|
|
107
|
+
return word if word.downcase.count("е") == 1 && word.downcase.match?(/#{LOWER_CONSONANT_LETTERS}(ре|ле)/) &&
|
|
108
|
+
!IAT_WORDS.include?(word.downcase) && !word.downcase.end_with?("ейшій", "ЕЙШІЙ", "еть", "ЕТЬ") && !word.downcase.match?(/([#{LOWER_CONSONANT_LETTERS}])(е)$/)
|
|
109
|
+
return word if word.downcase.count("е") == 1 && word.downcase.start_with?("без", "бес") && !word.downcase.match?("бесъ")
|
|
110
|
+
return word if word.downcase.count("е") == 1 && word.end_with?("его")
|
|
111
|
+
|
|
112
|
+
word = word.gsub(/([#{LOWER_CONSONANT_LETTERS}])(е)/, '\1ѣ').gsub(/([#{UPPER_CONSONANT_LETTERS}])(Е)/, '\1Ѣ') if word.downcase.count("е") == 1
|
|
113
|
+
word = word.gsub(/([#{LOWER_CONSONANT_LETTERS}])(е)$/, '\1ѣ').gsub(/([#{UPPER_CONSONANT_LETTERS}])(Е)$/, '\1Ѣ')
|
|
114
|
+
word = word.gsub("ей", "ѣй").gsub("ЕЙ", "ѢЙ") if word.end_with?("ей", "ЕЙ")
|
|
115
|
+
word = word.gsub("ее", "ѣе").gsub("ЕЕ", "ѢЕ") if word.end_with?("ее", "ЕЕ")
|
|
116
|
+
word = word.gsub("ейшій", "ѣйшій").gsub("ЕЙШІЙ", "ѢЙШІЙ") if word.end_with?("ейшій", "ЕЙШІЙ")
|
|
117
|
+
word = word.gsub("еть", "ѣть").gsub("ЕТЬ", "ѢТЬ") if word.end_with?("еть", "ЕТЬ")
|
|
118
|
+
|
|
119
|
+
word
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def use_rule_8(word) # Ё
|
|
123
|
+
word.gsub("ё", "е").gsub("Ё", "Е")
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: izhitsa
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Vyacheslav Konovalov
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-02-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.15'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.15'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '13.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '13.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.9'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.9'
|
|
55
|
+
description: Example description
|
|
56
|
+
email:
|
|
57
|
+
- Vyacheslav Konovalov
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- CHANGELOG.md
|
|
63
|
+
- LICENSE.txt
|
|
64
|
+
- README.md
|
|
65
|
+
- lib/izhitsa.rb
|
|
66
|
+
- lib/izhitsa/version.rb
|
|
67
|
+
homepage: https://github.com/K0Hb/izhitsa
|
|
68
|
+
licenses:
|
|
69
|
+
- MIT
|
|
70
|
+
metadata:
|
|
71
|
+
bug_tracker_uri: https://github.com/K0Hb/izhitsa/issues
|
|
72
|
+
changelog_uri: https://github.com/K0Hb/izhitsa/blob/master/CHANGELOG.md
|
|
73
|
+
documentation_uri: https://github.com/K0Hb/izhitsa
|
|
74
|
+
homepage_uri: https://github.com/K0Hb/izhitsa
|
|
75
|
+
source_code_uri: https://github.com/K0Hb/izhitsa
|
|
76
|
+
post_install_message:
|
|
77
|
+
rdoc_options: []
|
|
78
|
+
require_paths:
|
|
79
|
+
- lib
|
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '2.7'
|
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
requirements: []
|
|
91
|
+
rubygems_version: 3.3.7
|
|
92
|
+
signing_key:
|
|
93
|
+
specification_version: 4
|
|
94
|
+
summary: Example description
|
|
95
|
+
test_files: []
|