require "ruby-spacy" require "terminal-table" nlp = Spacy::Language.new("ja_core_news_lg") tokyo = nlp.get_lexeme("東京") japan = nlp.get_lexeme("日本") france = nlp.get_lexeme("フランス") query = tokyo.vector - japan.vector + france.vector headings = ["key", "text", "score"] rows = [] results = nlp.most_similar(query, 20) results.each do |lexeme| rows << [lexeme[:key], lexeme[:text], lexeme[:score],] end table = Terminal::Table.new rows: rows, headings: headings puts table # +----------------------+----------------+--------------------+ # | key | text | score | # +----------------------+----------------+--------------------+ # | 12090003238699662352 | パリ | 0.7376999855041504 | # | 18290786970454458111 | フランス | 0.7221999764442444 | # | 9360021637096476946 | 東京 | 0.6697999835014343 | # | 2437546359230213520 | ストラスブール | 0.631600022315979 | # | 13988178952745813186 | リヨン | 0.5939000248908997 | # | 10427160276079242800 | Paris | 0.574400007724762 | # | 5562396768860926997 | ベルギー | 0.5683000087738037 | # | 15029176915627965481 | ニース | 0.5679000020027161 | # | 9750625950625019690 | アルザス | 0.5644999742507935 | # | 2381640614569534741 | 南仏 | 0.5547999739646912 | # | 7486004458946554189 | ロンドン | 0.5525000095367432 | # | 7457654095417343716 | モンマルトル | 0.5453000068664551 | # | 14063777960246535660 | ブローニュ | 0.5338000059127808 | # | 3297880777656467136 | トゥールーズ | 0.5275999903678894 | # | 3059066136348671923 | バスティーユ | 0.5213000178337097 | # | 2423471048892368989 | フランス人 | 0.5194000005722046 | # | 15944886306236465675 | ロレーヌ | 0.5148000121116638 | # | 9592561648283566590 | モンパルナス | 0.513700008392334 | # | 6560045335275831141 | 渡仏 | 0.5131000280380249 | # | 8597467336360225096 | イタリア | 0.5127000212669373 | # +----------------------+----------------+--------------------+