unihan_lang 0.2.1 → 0.3.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: 838b5d8575bc79d05a24ed6555b9fe8d7856779b1f06e11ddbe3ae08e7030f11
4
- data.tar.gz: b0e38c1bacc89a87f227ede35cef8b1985688b781bc9ebaf5a4f37ea29b378d7
3
+ metadata.gz: 07200fff605b22cae82d18c8b9a16041fb1fbcd53c9106a25582785a779631ad
4
+ data.tar.gz: 335f78c7b507b547bbad354856bb294655f1042943ed66d3899a607721c40efb
5
5
  SHA512:
6
- metadata.gz: '0482b7206764fc812703fefcb37badb8a59cdd2a88fb04741ae4e25c7380c83f08e293992a6ec3158ff8d296c2c790d111b16e16fa48bb825a1b4091e1da2c1f'
7
- data.tar.gz: 7613e83a5579b1a45c9fdb4ef8d8df549f7f5dd95a5d7110dd5ca36c471cfcbcc410debfb9d15ca59927656699f756877051e9f49649ec5e01d98fcb5631f6b5
6
+ metadata.gz: 7691fa9c50fc79921fa069e36a367cb37adc20a2be5fecdd4d768d037389b3fa434fa1078ab4bf05afc026f5a91d1b8215696f0eff0f2feb9987e10264a4bc32
7
+ data.tar.gz: acff2b9f98d296486e0a83f2b8909db4351042e7ec837c088d0ddf8377b99425ebda8eea4f99709861390fe141162f95717768196c7a022eb29d13030d9708f8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unihan_lang (0.2.1)
4
+ unihan_lang (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/HOW_TO_UPDATE.md CHANGED
@@ -9,5 +9,24 @@ curl -u $RUBY_GEMS_ACCOUNT https://rubygems.org/api/v1/api_key.yaml > ~/.gem/cre
9
9
  # Publish
10
10
 
11
11
  ```bash
12
- ./bump_new_version.sh 1.2.3
12
+ # Add release branch
13
+ VERSION=TODO
14
+ git checkout master
15
+ git checkout -b release/$VERSION
16
+ vi lib/unihan_lang/version.rb # edit version
17
+ git commit -am "Bump version $VERSION"
18
+
19
+ # Publish to rubygems
20
+ gem build unihan_lang.gemspec
21
+ bundle install
22
+ gem push unihan_lang-$VERSION.gem
23
+
24
+ # GitHub release
25
+ git tag $VERSION
26
+ git push --tags
27
+ open https://github.com/kyubey1228/unihan_lang/releases/new
28
+
29
+ # merge to master
30
+ git checkout master
31
+ git merge release/$VERSION
13
32
  ```
data/README.ja.md CHANGED
@@ -83,4 +83,3 @@ puts unihan.contains_zh_cn?("這個text不包含簡體字") # => false
83
83
 
84
84
  このライブラリは、テキストの言語を完全に正確に判定することを保証するものではありません。
85
85
  特に、短いテキストや複数の言語が混在するテキストの場合、判定が難しい場合があります。
86
- 判定の際、句読点・数字・空白は無視されます。また、ひらがな・カタカナを含むテキストは中国語ではなく日本語として扱われます。
data/README.md CHANGED
@@ -71,7 +71,7 @@ puts unihan.contains_zh_cn?("這個text不包含簡體字") # => false
71
71
 
72
72
  ## Features
73
73
 
74
- - `determine_language(text)`: Determines the language of the text ("zh_TW", "zh_CN", "JA", "Unknown").
74
+ - `determine_language(text)`: Determines the language of the text ("ZH_TW", "ZH_CN", "JA", "Unknown").
75
75
  - `zh_tw?(text)`: Checks if the text is in Traditional Chinese.
76
76
  - `zh_cn?(text)`: Checks if the text is in Simplified Chinese.
77
77
  - `contains_chinese?(text)`: Checks if the text contains Chinese characters.
@@ -86,4 +86,3 @@ puts unihan.contains_zh_cn?("這個text不包含簡體字") # => false
86
86
  This library does not guarantee 100% accuracy in language identification.
87
87
  Particularly for short texts or texts containing multiple languages, determination may be challenging.
88
88
  The distinction between Traditional and Simplified Chinese is based on the Unihan database.
89
- Punctuation, digits, and whitespace are ignored when judging a sentence, and text containing Hiragana/Katakana is treated as Japanese rather than Chinese.
@@ -10,12 +10,10 @@ module UnihanLang
10
10
  @variant_mapping = variant_mapping
11
11
  @traditional_score = 0
12
12
  @simplified_score = 0
13
- @contains_kana = false
14
13
  analyze
15
14
  end
16
15
 
17
16
  def dominant_language
18
- return "Unknown" if contains_kana?
19
17
  return "Unknown" if total_chinese.zero?
20
18
  return "ZH_TW" if traditional_score > simplified_score
21
19
  return "ZH_CN" if simplified_score > traditional_score
@@ -24,37 +22,18 @@ module UnihanLang
24
22
  end
25
23
 
26
24
  def language_ratio
27
- return :unknown if contains_kana?
28
- return :unknown if total_chinese.zero? || total_chinese != meaningful_length
25
+ return :unknown if total_chinese != @text.length
29
26
  return :tw if traditional_score > simplified_score
30
- return :cn if simplified_score > traditional_score
27
+ return :cn if simplified_score >= traditional_score
31
28
 
32
29
  :unknown
33
30
  end
34
31
 
35
32
  private
36
33
 
37
- def contains_kana?
38
- @contains_kana
39
- end
40
-
41
- def kana_char?(char)
42
- ord = char.ord
43
- # 0x3040-0x309F: ひらがな, 0x30A0-0x30FF: カタカナ, 0x31F0-0x31FF: カタカナ拡張
44
- (ord >= 0x3040 && ord <= 0x309F) || (ord >= 0x30A0 && ord <= 0x30FF) || (ord >= 0x31F0 && ord <= 0x31FF)
45
- end
46
-
47
- # Punctuation, digits, and whitespace are ignored so they don't
48
- # invalidate an otherwise all-Chinese sentence (e.g. "這是中文。").
49
- def meaningful_length
50
- @text.chars.count { |char| char.match?(/\p{L}/) }
51
- end
52
-
53
34
  def analyze
54
35
  @total_chinese = 0
55
36
  @text.chars.each do |char|
56
- @contains_kana ||= kana_char?(char)
57
-
58
37
  next unless @chinese_processor.chinese_character?(char)
59
38
 
60
39
  @total_chinese += 1
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UnihanLang
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unihan_lang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kyubey1228
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-08-17 00:00:00.000000000 Z
10
+ date: 2025-02-20 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bundler
@@ -70,7 +70,6 @@ files:
70
70
  - README.ja.md
71
71
  - README.md
72
72
  - Rakefile
73
- - bump_new_version.sh
74
73
  - data/Unihan_Variants.txt
75
74
  - lib/unihan_lang.rb
76
75
  - lib/unihan_lang/chinese_processor.rb
data/bump_new_version.sh DELETED
@@ -1,38 +0,0 @@
1
- #!/bin/bash
2
-
3
- if [ -z "$1" ]; then
4
- echo "Usage: $0 <version>"
5
- exit 1
6
- fi
7
-
8
- # ~/.gem/credentials
9
- if [ ! -f ~/.gem/credentials ]; then
10
- echo "Error: ~/.gem/credentials not found. Please set up your RubyGems credentials."
11
- exit 1
12
- fi
13
-
14
- PROJECT_NAME="unihan_lang"
15
- GITHUB_REPO="kyubey1228/unihan_lang"
16
- VERSION=$1
17
- echo "Start bumping version: $VERSION"
18
-
19
- # Publish
20
- # Add release branch
21
- git checkout master
22
- git checkout -b release/$VERSION
23
- sed -i '' "s/VERSION = \".*\"/VERSION = \"$VERSION\"/" lib/$PROJECT_NAME/version.rb
24
- git commit -am "Bump version $VERSION"
25
-
26
- # Publish to rubygems
27
- gem build $PROJECT_NAME.gemspec
28
- bundle install
29
- gem push $PROJECT_NAME-$VERSION.gem
30
-
31
- # GitHub release
32
- git tag $VERSION
33
- git push --tags
34
- open https://github.com/$GITHUB_REPO/releases/new
35
-
36
- # merge to master
37
- git checkout master
38
- git merge release/$VERSION