unihan_lang 0.3.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07200fff605b22cae82d18c8b9a16041fb1fbcd53c9106a25582785a779631ad
4
- data.tar.gz: 335f78c7b507b547bbad354856bb294655f1042943ed66d3899a607721c40efb
3
+ metadata.gz: 9edfe134026854b7c939b4aa8a941b4781a7cbb3b944531e322ad5ebb6560558
4
+ data.tar.gz: 5b0c33cefa96257e0e83cfdd5ca76f5d47ae75b437e2403a06d691cdadeb27b9
5
5
  SHA512:
6
- metadata.gz: 7691fa9c50fc79921fa069e36a367cb37adc20a2be5fecdd4d768d037389b3fa434fa1078ab4bf05afc026f5a91d1b8215696f0eff0f2feb9987e10264a4bc32
7
- data.tar.gz: acff2b9f98d296486e0a83f2b8909db4351042e7ec837c088d0ddf8377b99425ebda8eea4f99709861390fe141162f95717768196c7a022eb29d13030d9708f8
6
+ metadata.gz: 51672291df0ad4762c41d39265e6c141a9b22f57bcc899fd8cf7051d5ce46c9091e163a48d1e6e22b5c18d58345519f6aa9fbc850e2570fa1ede818a44699b99
7
+ data.tar.gz: 440fe3f331130bd56ce65b0a6ad3723e894521730941dafdaeaf7e897ba404405926b8803347593e349d2f08538d08850e43e59a158a58912cfcb07419163ad6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unihan_lang (0.3.0)
4
+ unihan_lang (0.3.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/HOW_TO_UPDATE.md CHANGED
@@ -9,24 +9,5 @@ curl -u $RUBY_GEMS_ACCOUNT https://rubygems.org/api/v1/api_key.yaml > ~/.gem/cre
9
9
  # Publish
10
10
 
11
11
  ```bash
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
12
+ ./bump_new_version.sh 1.2.3
32
13
  ```
data/README.ja.md CHANGED
@@ -83,3 +83,4 @@ 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,3 +86,4 @@ 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.
@@ -0,0 +1,38 @@
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
@@ -10,10 +10,12 @@ module UnihanLang
10
10
  @variant_mapping = variant_mapping
11
11
  @traditional_score = 0
12
12
  @simplified_score = 0
13
+ @contains_kana = false
13
14
  analyze
14
15
  end
15
16
 
16
17
  def dominant_language
18
+ return "Unknown" if contains_kana?
17
19
  return "Unknown" if total_chinese.zero?
18
20
  return "ZH_TW" if traditional_score > simplified_score
19
21
  return "ZH_CN" if simplified_score > traditional_score
@@ -22,18 +24,37 @@ module UnihanLang
22
24
  end
23
25
 
24
26
  def language_ratio
25
- return :unknown if total_chinese != @text.length
27
+ return :unknown if contains_kana?
28
+ return :unknown if total_chinese.zero? || total_chinese != meaningful_length
26
29
  return :tw if traditional_score > simplified_score
27
- return :cn if simplified_score >= traditional_score
30
+ return :cn if simplified_score > traditional_score
28
31
 
29
32
  :unknown
30
33
  end
31
34
 
32
35
  private
33
36
 
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
+
34
53
  def analyze
35
54
  @total_chinese = 0
36
55
  @text.chars.each do |char|
56
+ @contains_kana ||= kana_char?(char)
57
+
37
58
  next unless @chinese_processor.chinese_character?(char)
38
59
 
39
60
  @total_chinese += 1
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UnihanLang
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kyubey1228
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-02-20 00:00:00.000000000 Z
10
+ date: 2026-08-17 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bundler
@@ -70,6 +70,7 @@ files:
70
70
  - README.ja.md
71
71
  - README.md
72
72
  - Rakefile
73
+ - bump_new_version.sh
73
74
  - data/Unihan_Variants.txt
74
75
  - lib/unihan_lang.rb
75
76
  - lib/unihan_lang/chinese_processor.rb