ruby-spacy 0.1.4 → 0.1.4.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: bd5a1c905e5aed7553ac5b1927a6b9cdecaf887c505ea3e38f806e886adeb60c
4
- data.tar.gz: 6d3f3fd22e9d927d430d2b9e48dcd018da6eb601813192e6ea14e094cf51e331
3
+ metadata.gz: 5fc769c4257e78333c3d6dc114d76b39c31b57365d032d7b741358f34b37099e
4
+ data.tar.gz: 281a9997a325d16819574c96a0696eeedb59af0709d8f25814e6fa0d39646757
5
5
  SHA512:
6
- metadata.gz: b5419fb75109b837465c64da1ace956b91d0a0ab589cdb71ace9a308ce1af263edc0e2f206a80ab71a3ab17e86e6520ab432b657c5f60548c696a36049773c60
7
- data.tar.gz: 385606212f290b701458bd1a555e553417ed20be2d1e2008107396a9adc224590c76317c52d30d7c97435c0650ef8c1a15a43fe4b92c797188944a302da51612
6
+ metadata.gz: 8b387962ee82b60499208225ab7cfca631a55a6eb305212f3b14a2c802f67cfa685b23e762a3877e4ba5ae01308c4909eb26286bcde2fc9683dedeee9059db88
7
+ data.tar.gz: d94e788a1458f6be22db486e43180f7cbcce516ad053baa8724ce6eacd7869c3123c9f292845fe7e400aa2115786617f5ad69bda5c71b403221c98c084dc9900
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Change Log
2
2
 
3
- ## 0.1.2 - 2021-06-26
3
+ ## 0.1.4.1 - 2021-07-06
4
+ - Test code refined
5
+ - `Spacy::Language::most_similar` returns an array of hash-based objects that accepts method calls
6
+
7
+ ## 0.1.4 - 2021-06-26
4
8
  ### Added
5
9
  - `Spacy::Lexeme` class
6
10
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-spacy (0.1.4)
4
+ ruby-spacy (0.1.4.1)
5
5
  numpy (~> 0.4.0)
6
6
  pycall (~> 1.4.0)
7
7
  terminal-table (~> 3.0.1)
data/README.md CHANGED
@@ -448,32 +448,36 @@ france = nlp.get_lexeme("France")
448
448
 
449
449
  query = tokyo.vector - japan.vector + france.vector
450
450
 
451
+ headings = ["rank", "text", "score"]
451
452
  rows = []
452
453
 
453
- results = nlp.most_similar(query, 10)
454
- results.each do |lexeme|
455
- rows << [lexeme[:key], lexeme[:text], lexeme[:score],]
454
+ results = nlp.most_similar(query, 20)
455
+ results.each_with_index do |lexeme, i|
456
+ index = (i + 1).to_s
457
+ rows << [index, lexeme.text, lexeme.score]
456
458
  end
457
459
 
458
- headings = ["key", "text", "score"]
459
460
  table = Terminal::Table.new rows: rows, headings: headings
460
461
  puts table
461
462
  ```
462
463
 
463
464
  Output:
464
465
 
465
- | key | text | score |
466
- |:---------------------|:------------|:-------------------|
467
- | 1432967385481565694 | FRANCE | 0.8346999883651733 |
468
- | 6613816697677965370 | France | 0.8346999883651733 |
469
- | 4362406852232399325 | france | 0.8346999883651733 |
470
- | 1637573253267610771 | PARIS | 0.7703999876976013 |
471
- | 15322182186497800017 | paris | 0.7703999876976013 |
472
- | 10427160276079242800 | Paris | 0.7703999876976013 |
473
- | 975948890941980630 | TOULOUSE | 0.6381999850273132 |
474
- | 7944504257273452052 | Toulouse | 0.6381999850273132 |
475
- | 9614730213792621885 | toulouse | 0.6381999850273132 |
476
- | 8515538464606421210 | marseille | 0.6370999813079834 |
466
+ | rank | text | score |
467
+ |:-----|:------------|:-------------------|
468
+ | 1 | FRANCE | 0.8346999883651733 |
469
+ | 2 | France | 0.8346999883651733 |
470
+ | 3 | france | 0.8346999883651733 |
471
+ | 4 | PARIS | 0.7703999876976013 |
472
+ | 5 | paris | 0.7703999876976013 |
473
+ | 6 | Paris | 0.7703999876976013 |
474
+ | 7 | TOULOUSE | 0.6381999850273132 |
475
+ | 8 | Toulouse | 0.6381999850273132 |
476
+ | 9 | toulouse | 0.6381999850273132 |
477
+ | 10 | marseille | 0.6370999813079834 |
478
+
479
+
480
+
477
481
 
478
482
 
479
483
  ### Word vector calculation (Japanese)
@@ -494,33 +498,33 @@ france = nlp.get_lexeme("フランス")
494
498
 
495
499
  query = tokyo.vector - japan.vector + france.vector
496
500
 
501
+ headings = ["rank", "text", "score"]
497
502
  rows = []
498
503
 
499
- results = nlp.most_similar(query, 10)
500
- results.each do |lexeme|
501
- rows << [lexeme[:key], lexeme[:text], lexeme[:score],]
504
+ results = nlp.most_similar(query, 20)
505
+ results.each_with_index do |lexeme, i|
506
+ index = (i + 1).to_s
507
+ rows << [index, lexeme.text, lexeme.score]
502
508
  end
503
509
 
504
- headings = ["key", "text", "score"]
505
510
  table = Terminal::Table.new rows: rows, headings: headings
506
511
  puts table
507
512
  ```
508
513
 
509
514
  Output:
510
515
 
511
- | key | text | score |
512
- |:---------------------|:---------------|:-------------------|
513
- | 12090003238699662352 | パリ | 0.7376999855041504 |
514
- | 18290786970454458111 | フランス | 0.7221999764442444 |
515
- | 9360021637096476946 | 東京 | 0.6697999835014343 |
516
- | 2437546359230213520 | ストラスブール | 0.631600022315979 |
517
- | 13988178952745813186 | リヨン | 0.5939000248908997 |
518
- | 10427160276079242800 | Paris | 0.574400007724762 |
519
- | 5562396768860926997 | ベルギー | 0.5683000087738037 |
520
- | 15029176915627965481 | ニース | 0.5679000020027161 |
521
- | 9750625950625019690 | アルザス | 0.5644999742507935 |
522
- | 2381640614569534741 | 南仏 | 0.5547999739646912 |
523
-
516
+ | rank | text | score |
517
+ |:-----|:---------------|:-------------------|
518
+ | 1 | パリ | 0.7376999855041504 |
519
+ | 2 | フランス | 0.7221999764442444 |
520
+ | 3 | 東京 | 0.6697999835014343 |
521
+ | 4 | ストラスブール | 0.631600022315979 |
522
+ | 5 | リヨン | 0.5939000248908997 |
523
+ | 6 | Paris | 0.574400007724762 |
524
+ | 7 | ベルギー | 0.5683000087738037 |
525
+ | 8 | ニース | 0.5679000020027161 |
526
+ | 9 | アルザス | 0.5644999742507935 |
527
+ | 10 | 南仏 | 0.5547999739646912 |
524
528
 
525
529
  ## Author
526
530
 
@@ -9,38 +9,39 @@ france = nlp.get_lexeme("France")
9
9
 
10
10
  query = tokyo.vector - japan.vector + france.vector
11
11
 
12
- headings = ["key", "text", "score"]
12
+ headings = ["rank", "text", "score"]
13
13
  rows = []
14
14
 
15
15
  results = nlp.most_similar(query, 20)
16
- results.each do |lexeme|
17
- rows << [lexeme[:key], lexeme[:text], lexeme[:score],]
16
+ results.each_with_index do |lexeme, i|
17
+ index = (i + 1).to_s
18
+ rows << [index, lexeme.text, lexeme.score]
18
19
  end
19
20
 
20
21
  table = Terminal::Table.new rows: rows, headings: headings
21
22
  puts table
22
23
 
23
- # +----------------------+-------------+--------------------+
24
- # | key | text | score |
25
- # +----------------------+-------------+--------------------+
26
- # | 1432967385481565694 | FRANCE | 0.8346999883651733 |
27
- # | 6613816697677965370 | France | 0.8346999883651733 |
28
- # | 4362406852232399325 | france | 0.8346999883651733 |
29
- # | 1637573253267610771 | PARIS | 0.7703999876976013 |
30
- # | 15322182186497800017 | paris | 0.7703999876976013 |
31
- # | 10427160276079242800 | Paris | 0.7703999876976013 |
32
- # | 975948890941980630 | TOULOUSE | 0.6381999850273132 |
33
- # | 7944504257273452052 | Toulouse | 0.6381999850273132 |
34
- # | 9614730213792621885 | toulouse | 0.6381999850273132 |
35
- # | 8515538464606421210 | marseille | 0.6370999813079834 |
36
- # | 8215995793762630878 | Marseille | 0.6370999813079834 |
37
- # | 12360854743603227406 | MARSEILLE | 0.6370999813079834 |
38
- # | 8339539946446536307 | Bordeaux | 0.6096000075340271 |
39
- # | 17690237501437860177 | BORDEAUX | 0.6096000075340271 |
40
- # | 13936807859007616770 | bordeaux | 0.6096000075340271 |
41
- # | 8731576325682930212 | prague | 0.6075000166893005 |
42
- # | 11722746441803481839 | PRAGUE | 0.6075000166893005 |
43
- # | 1133963107690000953 | Prague | 0.6075000166893005 |
44
- # | 16693216792428069950 | SWITZERLAND | 0.6068000197410583 |
45
- # | 6936121537367717968 | switzerland | 0.6068000197410583 |
46
- # +----------------------+-------------+--------------------+
24
+ # +------+-------------+--------------------+
25
+ # | rank | text | score |
26
+ # +------+-------------+--------------------+
27
+ # | 1 | FRANCE | 0.8346999883651733 |
28
+ # | 2 | France | 0.8346999883651733 |
29
+ # | 3 | france | 0.8346999883651733 |
30
+ # | 4 | PARIS | 0.7703999876976013 |
31
+ # | 5 | paris | 0.7703999876976013 |
32
+ # | 6 | Paris | 0.7703999876976013 |
33
+ # | 7 | TOULOUSE | 0.6381999850273132 |
34
+ # | 8 | Toulouse | 0.6381999850273132 |
35
+ # | 9 | toulouse | 0.6381999850273132 |
36
+ # | 10 | marseille | 0.6370999813079834 |
37
+ # | 11 | Marseille | 0.6370999813079834 |
38
+ # | 12 | MARSEILLE | 0.6370999813079834 |
39
+ # | 13 | Bordeaux | 0.6096000075340271 |
40
+ # | 14 | BORDEAUX | 0.6096000075340271 |
41
+ # | 15 | bordeaux | 0.6096000075340271 |
42
+ # | 16 | prague | 0.6075000166893005 |
43
+ # | 17 | PRAGUE | 0.6075000166893005 |
44
+ # | 18 | Prague | 0.6075000166893005 |
45
+ # | 19 | SWITZERLAND | 0.6068000197410583 |
46
+ # | 20 | switzerland | 0.6068000197410583 |
47
+ # +------+-------------+--------------------+
@@ -9,38 +9,39 @@ france = nlp.get_lexeme("フランス")
9
9
 
10
10
  query = tokyo.vector - japan.vector + france.vector
11
11
 
12
- headings = ["key", "text", "score"]
12
+ headings = ["rank", "text", "score"]
13
13
  rows = []
14
14
 
15
15
  results = nlp.most_similar(query, 20)
16
- results.each do |lexeme|
17
- rows << [lexeme[:key], lexeme[:text], lexeme[:score],]
16
+ results.each_with_index do |lexeme, i|
17
+ index = (i + 1).to_s
18
+ rows << [index, lexeme.text, lexeme.score]
18
19
  end
19
20
 
20
21
  table = Terminal::Table.new rows: rows, headings: headings
21
22
  puts table
22
23
 
23
- # +----------------------+----------------+--------------------+
24
- # | key | text | score |
25
- # +----------------------+----------------+--------------------+
26
- # | 12090003238699662352 | パリ | 0.7376999855041504 |
27
- # | 18290786970454458111 | フランス | 0.7221999764442444 |
28
- # | 9360021637096476946 | 東京 | 0.6697999835014343 |
29
- # | 2437546359230213520 | ストラスブール | 0.631600022315979 |
30
- # | 13988178952745813186 | リヨン | 0.5939000248908997 |
31
- # | 10427160276079242800 | Paris | 0.574400007724762 |
32
- # | 5562396768860926997 | ベルギー | 0.5683000087738037 |
33
- # | 15029176915627965481 | ニース | 0.5679000020027161 |
34
- # | 9750625950625019690 | アルザス | 0.5644999742507935 |
35
- # | 2381640614569534741 | 南仏 | 0.5547999739646912 |
36
- # | 7486004458946554189 | ロンドン | 0.5525000095367432 |
37
- # | 7457654095417343716 | モンマルトル | 0.5453000068664551 |
38
- # | 14063777960246535660 | ブローニュ | 0.5338000059127808 |
39
- # | 3297880777656467136 | トゥールーズ | 0.5275999903678894 |
40
- # | 3059066136348671923 | バスティーユ | 0.5213000178337097 |
41
- # | 2423471048892368989 | フランス人 | 0.5194000005722046 |
42
- # | 15944886306236465675 | ロレーヌ | 0.5148000121116638 |
43
- # | 9592561648283566590 | モンパルナス | 0.513700008392334 |
44
- # | 6560045335275831141 | 渡仏 | 0.5131000280380249 |
45
- # | 8597467336360225096 | イタリア | 0.5127000212669373 |
46
- # +----------------------+----------------+--------------------+
24
+ # +------+----------------+--------------------+
25
+ # | rank | text | score |
26
+ # +------+----------------+--------------------+
27
+ # | 1 | パリ | 0.7376999855041504 |
28
+ # | 2 | フランス | 0.7221999764442444 |
29
+ # | 3 | 東京 | 0.6697999835014343 |
30
+ # | 4 | ストラスブール | 0.631600022315979 |
31
+ # | 5 | リヨン | 0.5939000248908997 |
32
+ # | 6 | Paris | 0.574400007724762 |
33
+ # | 7 | ベルギー | 0.5683000087738037 |
34
+ # | 8 | ニース | 0.5679000020027161 |
35
+ # | 9 | アルザス | 0.5644999742507935 |
36
+ # | 10 | 南仏 | 0.5547999739646912 |
37
+ # | 11 | ロンドン | 0.5525000095367432 |
38
+ # | 12 | モンマルトル | 0.5453000068664551 |
39
+ # | 13 | ブローニュ | 0.5338000059127808 |
40
+ # | 14 | トゥールーズ | 0.5275999903678894 |
41
+ # | 15 | バスティーユ | 0.5213000178337097 |
42
+ # | 16 | フランス人 | 0.5194000005722046 |
43
+ # | 17 | ロレーヌ | 0.5148000121116638 |
44
+ # | 18 | モンパルナス | 0.513700008392334 |
45
+ # | 19 | 渡仏 | 0.5131000280380249 |
46
+ # | 20 | イタリア | 0.5127000212669373 |
47
+ # +------+----------------+--------------------+
data/lib/ruby-spacy.rb CHANGED
@@ -279,7 +279,15 @@ module Spacy
279
279
 
280
280
  results = []
281
281
  n.times do |i|
282
- results << {key: keys[i].to_i, text: texts[i], best_row: best_rows[i], score: scores[i]}
282
+ result = {key: keys[i].to_i,
283
+ text: texts[i],
284
+ best_row: best_rows[i],
285
+ score: scores[i]
286
+ }
287
+ result.each_key do |key|
288
+ result.define_singleton_method(key){ result[key] }
289
+ end
290
+ results << result
283
291
  end
284
292
  results
285
293
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Spacy
4
4
  # The version number of the module
5
- VERSION = "0.1.4"
5
+ VERSION = "0.1.4.1"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-spacy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoichiro Hasebe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-03 00:00:00.000000000 Z
11
+ date: 2021-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pycall
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  requirements: []
153
- rubygems_version: 3.2.11
153
+ rubygems_version: 3.2.3
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: A wrapper module for using spaCy natural language processing library from