wordnet_japan_diagram 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 832db3f091de521d66ad98b8c4f96dce13faac4f3382ea687655a050aa429f36
4
- data.tar.gz: 05b0444573db1a97aba7822c5ca42b0d88134d063234820c4f5ed74fdf868f21
3
+ metadata.gz: 150dbe4fda2512307197d07428fbbcefb68c90800d30aa23082f26ac5bd8e634
4
+ data.tar.gz: 43c1e41f5565170eb028767510a1fc8b0b916a1bf4998da1f7bab877be3ca1fd
5
5
  SHA512:
6
- metadata.gz: 740f37b8eb9a737f8df225e29dac04678dfc9041ba05b34caa8a0cf061abc8147d44c0a10c22da0f935a5fe844b9ef153d7d675ca980e9c77a2c7126f8ee6283
7
- data.tar.gz: e41261374019aba180c148fc03b0df284fee68477394722a4676247fb73edae63e5e3be7fe41d68bf64c83f4adf88c77a965b65acea2ba89c974bc2a20d6a998
6
+ metadata.gz: a6eb1855cd58e5ec4e0740b057337cb7f068704d98487ca8b220276246d951b5b0949f91bbe32568e9165d9811a1c555b07934d2a186d44df3b6f7f76b0df8df
7
+ data.tar.gz: 4224c2ae5f4babc4643b0d7cf4e14c35e930391e5f60bde22df8d3b0062b3c424b13d10aa10a4d979c3750e34066e61391eefca01fd65a25086959ed055ed11a
data/Gemfile CHANGED
@@ -10,3 +10,5 @@ gem "rake", "~> 13.0"
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
12
  gem "rubocop", "~> 1.21"
13
+
14
+ gem "pry-byebug"
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # WordnetJapanDiagram
2
2
 
3
- Draw a diagram of [Japanese WordNet](https://bond-lab.github.io/wnja/jpn/index.html) about the hypernyms and hyponyms of the search word.
3
+ [日本語 WordNet](https://bond-lab.github.io/wnja/jpn/index.html)を利用して、検索キーワードの上位語・下位語を可視化します。
4
4
 
5
- example: search プログラミング
5
+ 例えば、「プログラミング」を可視化した結果は以下になります。
6
6
 
7
7
  ![wordnet_japan_diagram_20240218193942](https://github.com/tommy-012/wordnet_japan_diagram/assets/46615665/d5c58962-f1e4-4174-9a9f-47407b72f3e1)
8
8
 
@@ -18,11 +18,15 @@ If bundler is not being used to manage dependencies, install the gem by executin
18
18
 
19
19
  ## Usage
20
20
 
21
- ### 1. Prepare Japanese WordNet SQLite3 file
22
- Download [Japanese WordNet SQLite3 file](https://github.com/bond-lab/wnja/releases/download/v1.1/wnjpn.db.gz), unzip the file.
21
+ ### 1. 「日本語 WordNetSQLite3)」を用意します
22
+ [Japanese WordNet SQLite3 file](https://github.com/bond-lab/wnja/releases/download/v1.1/wnjpn.db.gz) をダウンロードして解凍します。
23
23
 
24
- ### 2. Execute the command using the above file
25
- If the above file path is `./tmp/wnjpn.db`, specify the path with `--wordnet_japan_db_file_path` option.
24
+ 解凍したファイルを適切なパスに移動します。
25
+
26
+ ### 2. コマンドを実行します
27
+ 「日本語 WordNet(SQLite3)」のデフォルトパスは、`./wnjpn.db` になります。
28
+
29
+ もしパスを指定したい場合は、`--wordnet_japan_db_file_path` オプションで指定します。
26
30
 
27
31
  ```
28
32
  $ wordnet_japan_diagram --wordnet_japan_db_file_path ./tmp/wnjpn.db --search_word サウナ
@@ -31,19 +35,19 @@ $ wordnet_japan_diagram --wordnet_japan_db_file_path ./tmp/wnjpn.db --search_wor
31
35
  $ bundle exec wordnet_japan_diagram --wordnet_japan_db_file_path ./tmp/wnjpn.db --search_word サウナ
32
36
  ```
33
37
 
34
- ### 3. Check the diagram that is the result of the command execution
35
- The diagram is located under the same path as the command execution.
38
+ ### 3. コマンド実行結果を確認します
39
+ 可視化した画像は、コマンド実行したパス配下に作られます。
36
40
 
37
- The diagram name is `wordnet_japan_diagram_[%Y%m%d%H%M%S].png`.
41
+ もしパスを指定したい場合は、`--output_diagram_path` オプションで指定します。
38
42
 
39
- ※ If you want to specify the diagram path, use `--output_diagram_path` option.
43
+ 画像の名前フォーマットは、`wordnet_japan_diagram_[%Y%m%d%H%M%S].png` になります。
40
44
 
41
45
  ![wordnet_japan_diagram_20240218193545](https://github.com/tommy-012/wordnet_japan_diagram/assets/46615665/afbe25cd-2c3b-4662-a1d0-4bc16517b6a0)
42
46
 
43
- ### 4. As needed, use options for the command
47
+ ### 4. (必要に応じて) 他オプションを確認できます
44
48
  ```
45
49
  $ wordnet_japan_diagram --help
46
- Usage: wordnet_japan_diagram
50
+ Usage: wordnet_japan_diagram [-v]
47
51
 
48
52
  Specific options:
49
53
  --wordnet_japan_db_file_path=text
@@ -63,7 +67,10 @@ Specific options:
63
67
  --depth_from_target=number Sets depth from target node
64
68
  --output_diagram_path=text Sets output diagram path (The file extension is either .pdf, .png, .jpg, or .svg)
65
69
  default: wordnet_japan_diagram_[%Y%m%d%H%M%S].png
70
+
71
+ Common options:
66
72
  --help Show this options information
73
+ -v, --version Show version and quit.
67
74
  ```
68
75
 
69
76
  ## Development
@@ -1,14 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'command_options'
4
- require_relative 'diagram_creater'
3
+ require_relative "command_options"
4
+ require_relative "diagram_creater"
5
5
 
6
- require_relative 'wordnet_japan/database'
7
- require_relative 'wordnet_japan/sense'
8
- require_relative 'wordnet_japan/synlink'
9
- require_relative 'wordnet_japan/synset'
10
- require_relative 'wordnet_japan/synset_def'
11
- require_relative 'wordnet_japan/word'
6
+ require "wordnet_japan"
12
7
 
13
8
  module WordnetJapanDiagram
14
9
  class CLI
@@ -24,13 +19,14 @@ module WordnetJapanDiagram
24
19
 
25
20
  def execute
26
21
  connect_database
22
+
27
23
  create_diagram
28
24
  end
29
25
 
30
26
  private
31
27
 
32
28
  def connect_database
33
- WordnetJapan::Database.connect(@command_options)
29
+ WordnetJapan::Database.connect(database: @command_options.wordnet_japan_db_options[:database])
34
30
  end
35
31
 
36
32
  def create_diagram
@@ -18,7 +18,7 @@ module WordnetJapanDiagram
18
18
  output_diagram_path: @options[:output_diagram_path],
19
19
  node_contents: @options[:node_contents],
20
20
  height_from_target: @options[:height_from_target].nil? ? nil : @options[:height_from_target].to_i,
21
- depth_from_target: @options[:depth_from_target].nil? ? nil : @options[:depth_from_target].to_i,
21
+ depth_from_target: @options[:depth_from_target].nil? ? nil : @options[:depth_from_target].to_i
22
22
  }
23
23
  end
24
24
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'graph_viz'
3
+ require_relative "graph_viz"
4
4
 
5
5
  module WordnetJapanDiagram
6
6
  class DiagramCreater
@@ -10,25 +10,22 @@ module WordnetJapanDiagram
10
10
  end
11
11
 
12
12
  def create
13
- word = WordnetJapan::Word.find_by(lemma: @options[:search_word], pos: 'n')
13
+ draw_diagram
14
14
 
15
- word.synsets.each do |synset|
16
- draw(synset)
17
- end
18
-
19
- @graph_viz.output(
20
- file_type: File.extname(@options[:output_diagram_path]).delete('.').to_sym,
21
- file_path: @options[:output_diagram_path]
22
- )
15
+ output_diagram
23
16
  end
24
17
 
25
18
  private
26
19
 
27
- def draw(synset)
28
- draw_target(synset)
20
+ def draw_diagram
21
+ word = WordnetJapan::Word.find_by(lemma: @options[:search_word], pos: "n")
22
+
23
+ word.synsets.each do |synset|
24
+ draw_target(synset)
29
25
 
30
- draw_hype(synset, @options[:height_from_target])
31
- draw_hypo(synset, @options[:depth_from_target])
26
+ draw_hype(synset, @options[:height_from_target])
27
+ draw_hypo(synset, @options[:depth_from_target])
28
+ end
32
29
  end
33
30
 
34
31
  def draw_target(synset)
@@ -36,8 +33,9 @@ module WordnetJapanDiagram
36
33
  end
37
34
 
38
35
  def draw_hype(synset, height)
39
- dest_synsets = synset.synlinks.where(link: '上位語').map(&:dest_synset)
36
+ dest_synsets = synset.synlinks.where(link: "上位語").map(&:dest_synset)
40
37
 
38
+ # NOTE: オプション指定がない場合は height が nil になる
41
39
  return if (height.present? && height <= 0) || dest_synsets.blank?
42
40
 
43
41
  dest_synsets.each do |dest_synset|
@@ -49,8 +47,9 @@ module WordnetJapanDiagram
49
47
  end
50
48
 
51
49
  def draw_hypo(synset, depth)
52
- dest_synsets = synset.synlinks.where(link: '下位語').map(&:dest_synset)
50
+ dest_synsets = synset.synlinks.where(link: "下位語").map(&:dest_synset)
53
51
 
52
+ # NOTE: オプション指定がない場合は depth が nil になる
54
53
  return if (depth.present? && depth <= 0) || dest_synsets.blank?
55
54
 
56
55
  dest_synsets.each do |dest_synset|
@@ -62,13 +61,20 @@ module WordnetJapanDiagram
62
61
  end
63
62
 
64
63
  def node_contents(synset)
65
- synset_def = synset.synset_defs.where(lang: 'jpn').first&.def
64
+ synset_def = synset.synset_defs.where(lang: "jpn").first&.def
66
65
 
67
- return synset_def if @options[:node_contents] == 'synset'
66
+ return synset_def if @options[:node_contents] == "synset"
68
67
 
69
- words = synset.words.where(pos: "noun").map(&:lemma).join(',')
68
+ words = synset.words.where(pos: "noun").map(&:lemma).join(",")
70
69
 
71
70
  "#{synset_def}\n(#{words})"
72
71
  end
72
+
73
+ def output_diagram
74
+ @graph_viz.output(
75
+ file_type: File.extname(@options[:output_diagram_path]).delete(".").to_sym,
76
+ file_path: @options[:output_diagram_path]
77
+ )
78
+ end
73
79
  end
74
80
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WordnetJapanDiagram
4
- VERSION = '0.1.3'
4
+ VERSION = "0.1.4"
5
5
  BANNER = "WordnetJapanDiagram #{VERSION}"
6
6
  end
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
6
6
  spec.name = "wordnet_japan_diagram"
7
7
  spec.version = WordnetJapanDiagram::VERSION
8
8
  spec.authors = ["tommy-012"]
9
- spec.email = ["lonnlilonn@googlemail.com"]
9
+ spec.email = ["lonnlilonn@gmail.com"]
10
10
 
11
11
  spec.summary = "Draw a diagram of Japanese WordNet."
12
12
  spec.description = "Draw a diagram of Japanese WordNet about the hypernyms and hyponyms of the search word."
@@ -35,8 +35,7 @@ Gem::Specification.new do |spec|
35
35
  # For more information and examples about making a new gem, check out our
36
36
  # guide at: https://bundler.io/guides/creating_gem.html
37
37
 
38
- spec.add_dependency "activerecord", "~> 7.0.4"
39
- spec.add_dependency "sqlite3", "~> 1.5.4"
40
- spec.add_dependency "ruby-graphviz", "~> 1.2.5"
41
38
  spec.add_dependency "choice", "~> 0.2.0"
39
+ spec.add_dependency "ruby-graphviz", "~> 1.2.5"
40
+ spec.add_dependency "wordnet_japan"
42
41
  end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wordnet_japan_diagram
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - tommy-012
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-21 00:00:00.000000000 Z
11
+ date: 2024-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activerecord
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 7.0.4
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 7.0.4
27
- - !ruby/object:Gem::Dependency
28
- name: sqlite3
14
+ name: choice
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: 1.5.4
19
+ version: 0.2.0
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: 1.5.4
26
+ version: 0.2.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: ruby-graphviz
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,23 +39,23 @@ dependencies:
53
39
  - !ruby/object:Gem::Version
54
40
  version: 1.2.5
55
41
  - !ruby/object:Gem::Dependency
56
- name: choice
42
+ name: wordnet_japan
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - "~>"
45
+ - - ">="
60
46
  - !ruby/object:Gem::Version
61
- version: 0.2.0
47
+ version: '0'
62
48
  type: :runtime
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - "~>"
52
+ - - ">="
67
53
  - !ruby/object:Gem::Version
68
- version: 0.2.0
54
+ version: '0'
69
55
  description: Draw a diagram of Japanese WordNet about the hypernyms and hyponyms of
70
56
  the search word.
71
57
  email:
72
- - lonnlilonn@googlemail.com
58
+ - lonnlilonn@gmail.com
73
59
  executables:
74
60
  - wordnet_japan_diagram
75
61
  extensions: []
@@ -90,12 +76,6 @@ files:
90
76
  - lib/wordnet_japan_diagram/diagram_creater.rb
91
77
  - lib/wordnet_japan_diagram/graph_viz.rb
92
78
  - lib/wordnet_japan_diagram/version.rb
93
- - lib/wordnet_japan_diagram/wordnet_japan/database.rb
94
- - lib/wordnet_japan_diagram/wordnet_japan/sense.rb
95
- - lib/wordnet_japan_diagram/wordnet_japan/synlink.rb
96
- - lib/wordnet_japan_diagram/wordnet_japan/synset.rb
97
- - lib/wordnet_japan_diagram/wordnet_japan/synset_def.rb
98
- - lib/wordnet_japan_diagram/wordnet_japan/word.rb
99
79
  - sig/wordnet_japan_diagram.rbs
100
80
  - wordnet_japan_diagram.gemspec
101
81
  homepage: https://github.com/tommy-012/wordnet_japan_diagram
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_record'
4
-
5
- module WordnetJapanDiagram
6
- module WordnetJapan
7
- class Database < ActiveRecord::Base
8
- self.abstract_class = true
9
-
10
- def self.connect(command_options)
11
- establish_connection(
12
- adapter: 'sqlite3',
13
- **command_options.wordnet_japan_db_options
14
- )
15
- end
16
- end
17
- end
18
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module WordnetJapanDiagram
4
- module WordnetJapan
5
- class Sense < Database
6
- self.table_name = 'sense'
7
-
8
- belongs_to :word, foreign_key: :wordid, primary_key: :wordid
9
- belongs_to :synset, foreign_key: :synset, primary_key: :synset
10
- end
11
- end
12
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module WordnetJapanDiagram
4
- module WordnetJapan
5
- class Synlink < Database
6
- self.table_name = 'synlink'
7
-
8
- enum :link, {
9
- '上位語' => 'hype',
10
- '下位語' => 'hypo',
11
- '被構成要素(部分)' => 'mprt',
12
- '構成要素(部分)' => 'hprt',
13
- '被構成要素(構成員)' => 'mmem',
14
- '構成要素(構成員)' => 'hmem',
15
- '被構成要素(物質・材料)' => 'msub',
16
- '構成要素(物質・材料)' => 'hsub',
17
- '被包含領域(カテゴリ)' => 'dmnc',
18
- '包含領域(カテゴリ)' => 'dmtc',
19
- '被包含領域(語法)' => 'dmnu',
20
- '包含領域(語法)' => 'dmtu',
21
- '被包含領域(地域)' => 'dmnr',
22
- '包含領域(地域)' => 'dmtr',
23
- '例' => 'inst',
24
- '例あり' => 'hasi',
25
- '含意' => 'enta',
26
- '引き起こし' => 'caus',
27
- '関連' => 'also',
28
- '属性' => 'attr',
29
- '近似' => 'sim',
30
- }
31
-
32
- has_one :src_synset, class_name: 'Synset', foreign_key: :synset, primary_key: :synset1
33
- has_one :dest_synset, class_name: 'Synset', foreign_key: :synset, primary_key: :synset2
34
- has_many :senses, through: :dest_synset
35
- has_many :words, through: :senses
36
- end
37
- end
38
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module WordnetJapanDiagram
4
- module WordnetJapan
5
- class Synset < Database
6
- self.table_name = 'synset'
7
-
8
- has_many :synset_defs, foreign_key: :synset, primary_key: :synset
9
- has_many :senses, foreign_key: :synset, primary_key: :synset
10
- has_many :words, through: :senses
11
- has_many :synlinks, foreign_key: :synset1, primary_key: :synset
12
- end
13
- end
14
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module WordnetJapanDiagram
4
- module WordnetJapan
5
- class SynsetDef < Database
6
- self.table_name = 'synset_def'
7
-
8
- belongs_to :synset, foreign_key: :synset, primary_key: :synset
9
- end
10
- end
11
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module WordnetJapanDiagram
4
- module WordnetJapan
5
- class Word < Database
6
- self.table_name = 'word'
7
-
8
- enum :pos, {
9
- noun: 'n', # NOTE 名詞
10
- verb: 'v', # NOTE 動詞
11
- adjective: 'a', # NOTE 形容詞
12
- adverb: 'r' # NOTE 副詞
13
- }
14
-
15
- has_many :senses, foreign_key: :wordid, primary_key: :wordid
16
- has_many :synsets, through: :senses
17
- end
18
- end
19
- end