japanese_names 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,12 @@ module JapaneseNames
15
15
  kanji = kanji.strip
16
16
  kana = kana.strip
17
17
 
18
+ # Short-circuit: Return last name if it can match the full string
19
+ if kanji.size <= 3 && kana.size <= 4
20
+ full_match = finder.find(kanji).detect { |d| d[0] == kanji && d[1] =~ /\A#{hk kana}\z/ }
21
+ return [[kanji, nil], [kana, nil]] if full_match
22
+ end
23
+
18
24
  # Partition kanji into candidate n-grams
19
25
  kanji_ngrams = Util::Ngram.ngram_partition(kanji)
20
26
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JapaneseNames
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
@@ -313,6 +313,11 @@
313
313
  - 蓮 れん
314
314
 
315
315
  :skip:
316
+ - 杏那
317
+ - 三郎
318
+ - 四郎
319
+ - 陽子
320
+ - 龍之介
316
321
  - 青木 緑
317
322
  - 石井 真
318
323
  - 石井 延
@@ -9,14 +9,23 @@ RSpec.describe JapaneseNames::Splitter do
9
9
  config = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'config.yml'))
10
10
  skip_list = config[:skip]
11
11
 
12
+ config[:last_names] + config[:first_names].each do |name|
13
+ kanji, kana = name.split(' ')
14
+ next if skip_list.index(kanji)
15
+
16
+ it "should match #{kanji} #{kana}" do
17
+ result = subject.split(kanji, kana)
18
+ expect(result).to eq [[kanji, nil], [kana, nil]]
19
+ end
20
+ end
21
+
12
22
  config[:last_names].each do |last_name|
13
23
  config[:first_names].each do |first_name|
14
24
  kanji_fam, kana_fam = last_name.split(' ')
15
25
  kanji_giv, kana_giv = first_name.split(' ')
26
+ next if skip_list.index([kanji_fam, kanji_giv].join(' '))
16
27
 
17
- next if skip_list.index("#{kanji_fam} #{kanji_giv}")
18
-
19
- it "should parse #{kanji_fam + kanji_giv} #{kana_fam + kana_giv}" do
28
+ it "should split #{kanji_fam + kanji_giv} #{kana_fam + kana_giv}" do
20
29
  result = subject.split(kanji_fam + kanji_giv, kana_fam + kana_giv)
21
30
  expect(result).to eq [[kanji_fam, kanji_giv], [kana_fam, kana_giv]]
22
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: japanese_names
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johnny Shields