mongolian 0.1.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +42 -0
- data/Rakefile +8 -0
- data/lib/mongolian/latin.rb +107 -0
- data/lib/mongolian/spellchecker.rb +88 -0
- data/lib/mongolian/stemmify.rb +14 -0
- data/lib/mongolian/tokenizer.rb +25 -0
- data/lib/mongolian/version.rb +5 -0
- data/lib/mongolian.rb +16 -0
- data/sig/mongolian.rbs +4 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b5ae047f3b8d5d37be63b5646bae637537a46f1a8402d9cb6bed1d95ea9f3135
|
4
|
+
data.tar.gz: 7e00183b681aa0a29119a5d3eadcb687546761bd3b9c78f8dc670f1dc869e7de
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b075ed85bfd720da5169e92b2e5c5ce6ce0a279ee7fb5fa8b137137bc6bcb6debd257efdac73751f63e1ccbb28bff533f2e764d71c427ae36c099173c595ca4e
|
7
|
+
data.tar.gz: 9ed88cc1be818a65e58a134dafca486faa1eeeed3325c460a86c3aac60990ebcd18848802164afd27e3ac79b2c611e73e14470ea2547f38521ffca60634f6042
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 hfl
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Mongolian
|
2
|
+
|
3
|
+
欢迎使用 Mongolian Gem!本 Gem 打包了一些蒙古文处理常用的操作,例如分词、蒙古文转换为拉丁转写等。
|
4
|
+
|
5
|
+
## 安装
|
6
|
+
|
7
|
+
安装 Gem 并添加到应用的 Gemfile 可以通过执行:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
bundle add mongolian
|
11
|
+
```
|
12
|
+
|
13
|
+
如果没有使用 bundler 管理依赖,可以通过:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
gem install mongolian
|
17
|
+
```
|
18
|
+
直接安装。
|
19
|
+
|
20
|
+
## 用法
|
21
|
+
|
22
|
+
1. 判断一个字符或者词是否包含蒙古文字符;
|
23
|
+
2. 蒙古文分词;
|
24
|
+
3. 蒙古文词干提取;
|
25
|
+
|
26
|
+
## 开发
|
27
|
+
|
28
|
+
查看代码库,运行 `bin/setup` 安装依赖库。运行 `rake test` 进行测试。运行 `bin/console` 启用提示互动体验程序功能。
|
29
|
+
|
30
|
+
本地安装 Gem,运行 `bundle exec rake install`。发布新版本,更新 `version.rb` 中的版本号,然后运行 `bundle exec rake release`,这将基于版本号创建一个 Git Tag,推送 Git 提交和创建 Tag,推送 `.gem` 文件到 [rubygems.org](https://rubygems.org)。
|
31
|
+
|
32
|
+
## 贡献
|
33
|
+
|
34
|
+
欢迎到 GitHub 的 https://github.com/hfl/mongolian 代码库提交问题报告和提交软件修正。
|
35
|
+
|
36
|
+
## 许可
|
37
|
+
|
38
|
+
本 Gem 基于[MIT 许可](https://opensource.org/licenses/MIT)分发。
|
39
|
+
|
40
|
+
## Code of Conduct
|
41
|
+
|
42
|
+
Everyone interacting in the Mongolian project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hfl/mongolian/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
module Mongolian
|
2
|
+
# 传统蒙古文很多时候需要对其进行拉丁转写,本程序对相关传统蒙古文词句进行转写转换
|
3
|
+
# 转换原则:
|
4
|
+
# 1. 仅针对传统蒙古文进行转换;
|
5
|
+
# 2. 传统蒙古文与拉丁转写字母一一对应;
|
6
|
+
# 3. 根据 Unicode 定义,转写不分阴阳形式;
|
7
|
+
|
8
|
+
# 转换传统蒙古文为拉丁转写
|
9
|
+
def m2l
|
10
|
+
mongolian_str = self.dup.to_str
|
11
|
+
mongolian_str = mongolian_str.gsub(/ᠠ/, "a")
|
12
|
+
mongolian_str = mongolian_str.gsub(/ᠡ/, "e")
|
13
|
+
mongolian_str = mongolian_str.gsub(/ᠢ/, "i")
|
14
|
+
mongolian_str = mongolian_str.gsub(/ᠣ/, "o")
|
15
|
+
mongolian_str = mongolian_str.gsub(/ᠤ/, "u")
|
16
|
+
mongolian_str = mongolian_str.gsub(/ᠥ/, "ö")
|
17
|
+
mongolian_str = mongolian_str.gsub(/ᠦ/, "ü")
|
18
|
+
mongolian_str = mongolian_str.gsub(/ᠧ/, "ë")
|
19
|
+
mongolian_str = mongolian_str.gsub(/ᠨ/, "n")
|
20
|
+
mongolian_str = mongolian_str.gsub(/ᠩ/, "ŋ")
|
21
|
+
mongolian_str = mongolian_str.gsub(/ᠪ/, "b")
|
22
|
+
mongolian_str = mongolian_str.gsub(/ᠫ/, "p")
|
23
|
+
mongolian_str = mongolian_str.gsub(/ᠬ/, "x")
|
24
|
+
mongolian_str = mongolian_str.gsub(/ᠭ/, "g")
|
25
|
+
mongolian_str = mongolian_str.gsub(/ᠮ/, "m")
|
26
|
+
mongolian_str = mongolian_str.gsub(/ᠯ/, "l")
|
27
|
+
mongolian_str = mongolian_str.gsub(/ᠰ/, "s")
|
28
|
+
mongolian_str = mongolian_str.gsub(/ᠱ/, "š")
|
29
|
+
mongolian_str = mongolian_str.gsub(/ᠲ/, "t")
|
30
|
+
mongolian_str = mongolian_str.gsub(/ᠳ/, "d")
|
31
|
+
mongolian_str = mongolian_str.gsub(/ᠴ/, "č")
|
32
|
+
mongolian_str = mongolian_str.gsub(/ᠵ/, "ǰ")
|
33
|
+
mongolian_str = mongolian_str.gsub(/ᠶ/, "y")
|
34
|
+
mongolian_str = mongolian_str.gsub(/ᠷ/, "r")
|
35
|
+
mongolian_str = mongolian_str.gsub(/ᠸ/, "w")
|
36
|
+
mongolian_str = mongolian_str.gsub(/ᠹ/, "f")
|
37
|
+
mongolian_str = mongolian_str.gsub(/ᠺ/, "k")
|
38
|
+
mongolian_str = mongolian_str.gsub(/ᠻ/, "ḳ")
|
39
|
+
mongolian_str = mongolian_str.gsub(/ᠼ/, "c")
|
40
|
+
mongolian_str = mongolian_str.gsub(/ᠽ/, "z")
|
41
|
+
mongolian_str = mongolian_str.gsub(/ᠾ/, "h")
|
42
|
+
mongolian_str = mongolian_str.gsub(/ᠿ/, "ž")
|
43
|
+
mongolian_str = mongolian_str.gsub(/ᡀ/, "lh")
|
44
|
+
mongolian_str = mongolian_str.gsub(/ᡁ/, "ẑ")
|
45
|
+
mongolian_str = mongolian_str.gsub(/ᡂ/, "ĉ")
|
46
|
+
mongolian_str = mongolian_str.gsub(/᠀/, "&")
|
47
|
+
mongolian_str = mongolian_str.gsub(/᠁/, "…")
|
48
|
+
mongolian_str = mongolian_str.gsub(/᠂/, ",")
|
49
|
+
mongolian_str = mongolian_str.gsub(/᠃/, ".")
|
50
|
+
mongolian_str = mongolian_str.gsub(/᠇/, ":")
|
51
|
+
mongolian_str = mongolian_str.gsub(/᠈/, "#")
|
52
|
+
mongolian_str = mongolian_str.gsub(/᠊/, "‐")
|
53
|
+
mongolian_str = mongolian_str.gsub(/᠋/, "") #fvs1
|
54
|
+
mongolian_str = mongolian_str.gsub(/᠌/, "") #fvs2
|
55
|
+
mongolian_str = mongolian_str.gsub(/᠍/, "") #fvs3
|
56
|
+
mongolian_str = mongolian_str.gsub(//, "_")
|
57
|
+
mongolian_str = mongolian_str.gsub(/᠐/, "'0")
|
58
|
+
mongolian_str = mongolian_str.gsub(/᠑/, "'1")
|
59
|
+
mongolian_str = mongolian_str.gsub(/᠒/, "'2")
|
60
|
+
mongolian_str = mongolian_str.gsub(/᠓/, "'3")
|
61
|
+
mongolian_str = mongolian_str.gsub(/᠔/, "'4")
|
62
|
+
mongolian_str = mongolian_str.gsub(/᠕/, "'5")
|
63
|
+
mongolian_str = mongolian_str.gsub(/᠖/, "'6")
|
64
|
+
mongolian_str = mongolian_str.gsub(/᠗/, "'7")
|
65
|
+
mongolian_str = mongolian_str.gsub(/᠘/, "'8")
|
66
|
+
mongolian_str = mongolian_str.gsub(/᠙/, "'9")
|
67
|
+
mongolian_str = mongolian_str.gsub(/ᡛ/, "ń")
|
68
|
+
mongolian_str = mongolian_str.gsub(/ᢀ/, "ṃ")
|
69
|
+
mongolian_str = mongolian_str.gsub(/ᢁ/, "ḥ")
|
70
|
+
mongolian_str = mongolian_str.gsub(/ᢂ/, "â")
|
71
|
+
mongolian_str = mongolian_str.gsub(/ᢃ/, "ŏ")
|
72
|
+
mongolian_str = mongolian_str.gsub(/ᢄ/, "ô")
|
73
|
+
mongolian_str = mongolian_str.gsub(/ᢅ/, "ˑ")
|
74
|
+
mongolian_str = mongolian_str.gsub(/ᢆ/, "ːˑ")
|
75
|
+
mongolian_str = mongolian_str.gsub(/ᢇ/, "ā")
|
76
|
+
mongolian_str = mongolian_str.gsub(/ᢈ/, "ī")
|
77
|
+
mongolian_str = mongolian_str.gsub(/ᢉ/, "ḵ")
|
78
|
+
mongolian_str = mongolian_str.gsub(/ᢊ/, "ṉ")
|
79
|
+
mongolian_str = mongolian_str.gsub(/ᢋ/, "ƈ")
|
80
|
+
mongolian_str = mongolian_str.gsub(/ᢌ/, "ť")
|
81
|
+
mongolian_str = mongolian_str.gsub(/ᢍ/, "ţ")
|
82
|
+
mongolian_str = mongolian_str.gsub(/ᢎ/, "ḏ")
|
83
|
+
mongolian_str = mongolian_str.gsub(/ᢏ/, "ņ")
|
84
|
+
mongolian_str = mongolian_str.gsub(/ᢐ/, "ṯ")
|
85
|
+
mongolian_str = mongolian_str.gsub(/ᢑ/, "ḓ")
|
86
|
+
mongolian_str = mongolian_str.gsub(/ᢒ/, "p̄")
|
87
|
+
mongolian_str = mongolian_str.gsub(/ᢓ/, "ṕh")
|
88
|
+
mongolian_str = mongolian_str.gsub(/ᢔ/, "ş")
|
89
|
+
mongolian_str = mongolian_str.gsub(/ᢕ/, "ẖ")
|
90
|
+
mongolian_str = mongolian_str.gsub(/ᢖ/, "ẕ")
|
91
|
+
mongolian_str = mongolian_str.gsub(/ᢗ/, "ʒ̄")
|
92
|
+
mongolian_str = mongolian_str.gsub(/ᢦ/, "ŭ")
|
93
|
+
mongolian_str = mongolian_str.gsub(/ᢧ/, "ÿ")
|
94
|
+
mongolian_str = mongolian_str.gsub(/ᢩ/, "̲")
|
95
|
+
mongolian_str = mongolian_str.gsub(//, "^")
|
96
|
+
mongolian_str = mongolian_str.gsub(//, "*")
|
97
|
+
mongolian_str = mongolian_str.gsub(/ /, "-")
|
98
|
+
return mongolian_str
|
99
|
+
end
|
100
|
+
|
101
|
+
# 对拉丁转写蒙古文恢复为蒙古文
|
102
|
+
def l2m
|
103
|
+
latin_str = self.dup.to_str
|
104
|
+
mongolian_str = latin_str
|
105
|
+
return mongolian_str
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Mongolian
|
2
|
+
# 基于语法的拼写检查包括元音和谐律及词性检测、划分音节等
|
3
|
+
|
4
|
+
# 测试单词是否符合元音和谐律,并判断词性 参考P87
|
5
|
+
# 返回值 0:错误,不符合元音和谐律,外来词、双词根词或者拼写错误
|
6
|
+
# 返回值 1:正确,且为阳性词
|
7
|
+
# 返回值 10:阳性词,但有错误,第一音节出现第五元音,却在后面出现了第四元音
|
8
|
+
# 返回值 2:正确,阴性词
|
9
|
+
# 返回值 20:阴性词,但有错误,第一音节出现第七元音,却在后面出现了第六元音
|
10
|
+
def vowel_harmony
|
11
|
+
mongolian_str = self.dup.to_str
|
12
|
+
#vowel = ["ᠠ", "ᠡ", "ᠢ", "ᠣ", "ᠤ", "ᠥ", "ᠦ"]
|
13
|
+
if mongolian_str =~ /[ᠠᠣᠤ]/ and mongolian_str =~ /[ᠡᠥᠦ]/
|
14
|
+
return 0
|
15
|
+
else
|
16
|
+
if mongolian_str =~ /[ᠠᠣᠤ]/
|
17
|
+
#如果第一音节阳性元音为第 5 元音,却在后面出现第 4 元音,则错误
|
18
|
+
if mongolian_str.syllable[0] =~ /ᠤ/ and mongolian_str[mongolian_str.syllable[0].size..-1] =~ /ᠣ/
|
19
|
+
return 10
|
20
|
+
else
|
21
|
+
return 1
|
22
|
+
end
|
23
|
+
else
|
24
|
+
#如果第一音节阳性元音为第 7 元音,却在后面出现第 6 元音,则错误
|
25
|
+
if mongolian_str.syllable[0] =~ /ᠦ/ and mongolian_str[mongolian_str.syllable[0].size..-1] =~ /ᠥ/
|
26
|
+
return 20
|
27
|
+
else
|
28
|
+
return 2
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# 对单词划分音节,返回音节数组
|
35
|
+
def syllable
|
36
|
+
mongolian_str = self.dup.to_str
|
37
|
+
mlist = []
|
38
|
+
s = ""
|
39
|
+
mongolian_str.each_char do |c|
|
40
|
+
if c =~ /[ᠠᠡᠢᠣᠤᠥᠦ]/
|
41
|
+
if s[-1] =~ /[ᠠᠡᠢᠣᠤᠥᠦ]/
|
42
|
+
s += c
|
43
|
+
else
|
44
|
+
if s[0..-2].size > 0
|
45
|
+
mlist << s[0..-2]
|
46
|
+
s = s[-1]
|
47
|
+
s += c
|
48
|
+
else
|
49
|
+
s += c
|
50
|
+
end
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s += c
|
54
|
+
end
|
55
|
+
end
|
56
|
+
mlist << s if s.size > 0
|
57
|
+
return mlist
|
58
|
+
end
|
59
|
+
|
60
|
+
# 蒙古语里没有复辅音是指在书面语单音节中没有复辅音 P89
|
61
|
+
def self.double_constant_check(str)
|
62
|
+
mongolian_str = str
|
63
|
+
result = 1
|
64
|
+
syllable(mongolian_str).each do |s|
|
65
|
+
sv = s.scan(/[ᠠᠡᠢᠣᠤᠥᠦ]/).join
|
66
|
+
if s.index(sv) < 2 and s.size - s.index(sv) - sv.size < 2
|
67
|
+
next
|
68
|
+
else
|
69
|
+
result = 0
|
70
|
+
break
|
71
|
+
end
|
72
|
+
end
|
73
|
+
return result
|
74
|
+
end
|
75
|
+
|
76
|
+
# 硬辅音 ᠪ(b) ᠭ(g) ᠷ(r) ᠰ(s) ᠳ(d) 后接以 ᠲ(t) ᠴ(q) 为首的附加成分
|
77
|
+
# 软辅音 ᠨ(n) ᠮ(m) ᠯ(l) ᠩ(ng) 后接以 ᠳ(d) ᠵ(j)为首的附加成分
|
78
|
+
|
79
|
+
# _ 用于分写 ᠠ(a)/ᠡ(e) 跟前面的辅音(h/g + a; n, l, m, s, sh, j, y, r , W + a/e)
|
80
|
+
def ae?(str)
|
81
|
+
if str =~ /[ᠠᠡ]/
|
82
|
+
return true
|
83
|
+
else
|
84
|
+
false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Mongolian
|
2
|
+
##
|
3
|
+
# 判断一个词或者字符是否包含蒙古文字符,
|
4
|
+
# 如果包含蒙古文返回 true,否则返回 nil。
|
5
|
+
def is_mongolian?
|
6
|
+
return true if !!(self =~ /\p{Mongolian}/)
|
7
|
+
end
|
8
|
+
|
9
|
+
## 对于混合有多个文种的一段文字,删除其中的非蒙古文字符和蒙古文标点符号后,
|
10
|
+
# 仅对蒙古文分词。
|
11
|
+
# 函数返回仅包含蒙古文的分词数组。
|
12
|
+
def mongolian_tokenize
|
13
|
+
w = self.dup.to_str
|
14
|
+
# 去除标点符号,用空格替换标点符号
|
15
|
+
w = w.gsub(/[!᠄?·᠃᠂⁈⁉᠁—;《》]/, " ")
|
16
|
+
new_w = ""
|
17
|
+
# 将字符串中所有非蒙古文字符删除
|
18
|
+
w.each_char do |c|
|
19
|
+
c = "" unless c.is_mongolian?
|
20
|
+
new_w = new_w + c
|
21
|
+
end
|
22
|
+
return new_w.split
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/lib/mongolian.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "mongolian/version"
|
4
|
+
require_relative "mongolian/latin"
|
5
|
+
require_relative "mongolian/tokenizer"
|
6
|
+
require_relative "mongolian/spellchecker"
|
7
|
+
require_relative "mongolian/stemmify"
|
8
|
+
|
9
|
+
module Mongolian
|
10
|
+
class Error < StandardError; end
|
11
|
+
end
|
12
|
+
|
13
|
+
## 扩展 String
|
14
|
+
class String
|
15
|
+
include Mongolian
|
16
|
+
end
|
data/sig/mongolian.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongolian
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Huang Fei-Long
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-06-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Mongolian information process, tokenizer, stemming, and so on ...
|
14
|
+
email:
|
15
|
+
- huangfeilong@imu.edu.cn
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- CHANGELOG.md
|
21
|
+
- CODE_OF_CONDUCT.md
|
22
|
+
- LICENSE.txt
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- lib/mongolian.rb
|
26
|
+
- lib/mongolian/latin.rb
|
27
|
+
- lib/mongolian/spellchecker.rb
|
28
|
+
- lib/mongolian/stemmify.rb
|
29
|
+
- lib/mongolian/tokenizer.rb
|
30
|
+
- lib/mongolian/version.rb
|
31
|
+
- sig/mongolian.rbs
|
32
|
+
homepage: https://huangfeilong.cn/
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
metadata:
|
36
|
+
allowed_push_host: https://rubygems.org
|
37
|
+
homepage_uri: https://huangfeilong.cn/
|
38
|
+
source_code_uri: https://github.com/hfl/mongolian
|
39
|
+
changelog_uri: https://github.com/hfl/mongolian/CHANGELOG.md
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 3.0.0
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubygems_version: 3.5.18
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: Mongolian Information Process Technology in Ruby.
|
59
|
+
test_files: []
|