wordnet_japan_diagram 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7b079619d512bbb94f622ebceed258c67ee078cada25582767ccbd80ede79c93
4
+ data.tar.gz: e4db7ce1b7cce5e04362380171554e7d8e206e8773cf2627fe8fe928de93dec7
5
+ SHA512:
6
+ metadata.gz: 0c896e2f155c1e97884dc1dfee37e41cb9a997ee52326e3e9c43730c5f573df32b4f9bab30f91538904ab5b97cd21ea0ef2881ee9c6681e39e54b5e334b5c408
7
+ data.tar.gz: 38f7155b6406dccfa7bcd3eb7a2d0c62231d2d55aa3927a1acd353eadb2d79131c4efe8796cc1f9223107b7e62fd2c507c8a588a61885b0fa1fc7373ae274bb5
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-02-17
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at lonnlilonn@googlemail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in wordnet_japan_diagram.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,85 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ wordnet_japan_diagram (0.1.0)
5
+ activerecord (~> 7.0.4)
6
+ choice (~> 0.2.0)
7
+ ruby-graphviz (~> 1.2.5)
8
+ sqlite3 (~> 1.5.4)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activemodel (7.0.8)
14
+ activesupport (= 7.0.8)
15
+ activerecord (7.0.8)
16
+ activemodel (= 7.0.8)
17
+ activesupport (= 7.0.8)
18
+ activesupport (7.0.8)
19
+ concurrent-ruby (~> 1.0, >= 1.0.2)
20
+ i18n (>= 1.6, < 2)
21
+ minitest (>= 5.1)
22
+ tzinfo (~> 2.0)
23
+ ast (2.4.2)
24
+ choice (0.2.0)
25
+ concurrent-ruby (1.2.3)
26
+ diff-lcs (1.5.1)
27
+ i18n (1.14.1)
28
+ concurrent-ruby (~> 1.0)
29
+ json (2.7.1)
30
+ language_server-protocol (3.17.0.3)
31
+ minitest (5.22.2)
32
+ parallel (1.24.0)
33
+ parser (3.3.0.5)
34
+ ast (~> 2.4.1)
35
+ racc
36
+ racc (1.7.3)
37
+ rainbow (3.1.1)
38
+ rake (13.1.0)
39
+ regexp_parser (2.9.0)
40
+ rexml (3.2.6)
41
+ rspec (3.13.0)
42
+ rspec-core (~> 3.13.0)
43
+ rspec-expectations (~> 3.13.0)
44
+ rspec-mocks (~> 3.13.0)
45
+ rspec-core (3.13.0)
46
+ rspec-support (~> 3.13.0)
47
+ rspec-expectations (3.13.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.13.0)
50
+ rspec-mocks (3.13.0)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.13.0)
53
+ rspec-support (3.13.0)
54
+ rubocop (1.60.2)
55
+ json (~> 2.3)
56
+ language_server-protocol (>= 3.17.0)
57
+ parallel (~> 1.10)
58
+ parser (>= 3.3.0.2)
59
+ rainbow (>= 2.2.2, < 4.0)
60
+ regexp_parser (>= 1.8, < 3.0)
61
+ rexml (>= 3.2.5, < 4.0)
62
+ rubocop-ast (>= 1.30.0, < 2.0)
63
+ ruby-progressbar (~> 1.7)
64
+ unicode-display_width (>= 2.4.0, < 3.0)
65
+ rubocop-ast (1.30.0)
66
+ parser (>= 3.2.1.0)
67
+ ruby-graphviz (1.2.5)
68
+ rexml
69
+ ruby-progressbar (1.13.0)
70
+ sqlite3 (1.5.4-arm64-darwin)
71
+ tzinfo (2.0.6)
72
+ concurrent-ruby (~> 1.0)
73
+ unicode-display_width (2.5.0)
74
+
75
+ PLATFORMS
76
+ arm64-darwin-22
77
+
78
+ DEPENDENCIES
79
+ rake (~> 13.0)
80
+ rspec (~> 3.0)
81
+ rubocop (~> 1.21)
82
+ wordnet_japan_diagram!
83
+
84
+ BUNDLED WITH
85
+ 2.3.26
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 tommy-012
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # WordnetJapanDiagram
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.
4
+
5
+ example: search プログラミング
6
+
7
+ ![wordnet_japan_diagram_20240218193942](https://github.com/tommy-012/wordnet_japan_diagram/assets/46615665/d5c58962-f1e4-4174-9a9f-47407b72f3e1)
8
+
9
+ ## Installation
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add wordnet_japan_diagram
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install wordnet_japan_diagram
18
+
19
+ ## Usage
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.
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.
26
+
27
+ ```
28
+ $ wordnet_japan_diagram --wordnet_japan_db_file_path ./tmp/wnjpn.db --search_word サウナ
29
+
30
+ # If you were using bundler
31
+ $ bundle exec wordnet_japan_diagram --wordnet_japan_db_file_path ./tmp/wnjpn.db --search_word サウナ
32
+ ```
33
+
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.
36
+
37
+ The diagram name is `wordnet_japan_diagram_[%Y%m%d%H%M%S].png`.
38
+
39
+ ※ If you want to specify the diagram path, use `--output_diagram_path` option.
40
+
41
+ ![wordnet_japan_diagram_20240218193545](https://github.com/tommy-012/wordnet_japan_diagram/assets/46615665/afbe25cd-2c3b-4662-a1d0-4bc16517b6a0)
42
+
43
+ ### 4. As needed, use options for the command
44
+ ```
45
+ $ wordnet_japan_diagram --help
46
+ Usage: wordnet_japan_diagram
47
+
48
+ Specific options:
49
+ --wordnet_japan_db_file_path=text
50
+ Sets wordnet japan db file path
51
+ default: ./wnjpn.db
52
+ --search_word=text [Required] Sets japanese word to search
53
+ --graph_rankdir=[TB|BT|LR|RL]Sets direction of graph layout
54
+ default: BT
55
+ TB: Top to bottom
56
+ BT: Bottom to top
57
+ LR: Left to right
58
+ RL: Right to left
59
+ --node_contents=[synset|synset_and_words]
60
+ Sets node contents
61
+ default: synset_and_words
62
+ --height_from_target=number Sets height from target node
63
+ --depth_from_target=number Sets depth from target node
64
+ --output_diagram_path=text Sets output diagram path (The file extension is either .pdf, .png, .jpg, or .svg)
65
+ default: wordnet_japan_diagram_[%Y%m%d%H%M%S].png
66
+ --help Show this options information
67
+ ```
68
+
69
+ ## Development
70
+
71
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
72
+
73
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
74
+
75
+ ## Contributing
76
+
77
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/wordnet_japan_diagram. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/wordnet_japan_diagram/blob/main/CODE_OF_CONDUCT.md).
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
82
+
83
+ ## Code of Conduct
84
+
85
+ Everyone interacting in the WordnetJapanDiagram project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/wordnet_japan_diagram/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'wordnet_japan_diagram'
4
+
5
+ WordnetJapanDiagram::CLI.execute
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'choice'
4
+
5
+ require_relative 'command_options'
6
+ require_relative 'diagram_creater'
7
+
8
+ require_relative 'wordnet_japan/database'
9
+ require_relative 'wordnet_japan/sense'
10
+ require_relative 'wordnet_japan/synlink'
11
+ require_relative 'wordnet_japan/synset'
12
+ require_relative 'wordnet_japan/synset_def'
13
+ require_relative 'wordnet_japan/word'
14
+
15
+ Choice.options do
16
+ header ''
17
+ header 'Specific options:'
18
+
19
+ option :wordnet_japan_db_file_path do
20
+ long '--wordnet_japan_db_file_path=text'
21
+ desc "Sets wordnet japan db file path\n" \
22
+ ' default: ./wnjpn.db'
23
+ default 'wnjpn.db'
24
+ end
25
+
26
+ option :search_word, required: true do
27
+ long '--search_word=text'
28
+ desc '[Required] Sets japanese word to search'
29
+ validate /\p{Hiragana}+|\p{Katakana}+|\p{Han}+/
30
+ end
31
+
32
+ option :graph_rankdir do
33
+ long '--graph_rankdir=[TB|BT|LR|RL]'
34
+ desc "Sets direction of graph layout\n" \
35
+ " default: BT\n" \
36
+ " TB: Top to bottom\n" \
37
+ " BT: Bottom to top\n" \
38
+ " LR: Left to right\n" \
39
+ ' RL: Right to left'
40
+ default 'BT'
41
+ valid %w(TB BT LR RL)
42
+ end
43
+
44
+ option :node_contents do
45
+ long '--node_contents=[synset|synset_and_words]'
46
+ desc "Sets node contents\n" \
47
+ ' default: synset_and_words'
48
+ default 'synset_and_words'
49
+ valid %w(synset synset_and_words)
50
+ end
51
+
52
+ option :height_from_target do
53
+ long '--height_from_target=number'
54
+ desc 'Sets height from target node'
55
+ validate /\d+/
56
+ end
57
+
58
+ option :depth_from_target do
59
+ long '--depth_from_target=number'
60
+ desc 'Sets depth from target node'
61
+ validate /\d+/
62
+ end
63
+
64
+ option :output_diagram_path do
65
+ long '--output_diagram_path=text'
66
+ desc "Sets output diagram path (The file extension is either .pdf, .png, .jpg, or .svg)\n" \
67
+ ' default: wordnet_japan_diagram_[%Y%m%d%H%M%S].png'
68
+ default "wordnet_japan_diagram_#{Time.current.strftime('%Y%m%d%H%M%S')}.png"
69
+ validate /[pdf|png|jpg|svg]$/
70
+ end
71
+
72
+ option :help do
73
+ long '--help'
74
+ desc 'Show this options information'
75
+ end
76
+ end
77
+
78
+ module WordnetJapanDiagram
79
+ class CLI
80
+ class << self
81
+ def execute
82
+ connect_database
83
+ create_diagram
84
+ end
85
+
86
+ private
87
+
88
+ def connect_database
89
+ WordnetJapan::Database.connect(command_options)
90
+ end
91
+
92
+ def create_diagram
93
+ DiagramCreater.new(command_options).create
94
+ end
95
+
96
+ def command_options
97
+ @command_options ||= CommandOptions.new(options: Choice.choices)
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WordnetJapanDiagram
4
+ class CommandOptions
5
+ def initialize(options:)
6
+ @options = options
7
+ end
8
+
9
+ def wordnet_japan_db_options
10
+ {
11
+ database: @options[:wordnet_japan_db_file_path]
12
+ }
13
+ end
14
+
15
+ def diagram_creater_options
16
+ {
17
+ search_word: @options[:search_word],
18
+ output_diagram_path: @options[:output_diagram_path],
19
+ node_contents: @options[:node_contents],
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,
22
+ }
23
+ end
24
+
25
+ def graph_viz_options
26
+ {
27
+ rankdir: @options[:graph_rankdir].to_sym
28
+ }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'graph_viz'
4
+
5
+ module WordnetJapanDiagram
6
+ class DiagramCreater
7
+ def initialize(command_options)
8
+ @options = command_options.diagram_creater_options
9
+ @graph_viz = GraphViz.new(command_options)
10
+ end
11
+
12
+ def create
13
+ word = WordnetJapan::Word.find_by(lemma: @options[:search_word], pos: 'n')
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
+ )
23
+ end
24
+
25
+ private
26
+
27
+ def draw(synset)
28
+ draw_target(synset)
29
+
30
+ draw_hype(synset, @options[:height_from_target])
31
+ draw_hypo(synset, @options[:depth_from_target])
32
+ end
33
+
34
+ def draw_target(synset)
35
+ @graph_viz.find_or_create_node(node_contents: node_contents(synset), target: :main)
36
+ end
37
+
38
+ def draw_hype(synset, height)
39
+ dest_synsets = synset.synlinks.where(link: '上位語').map(&:dest_synset)
40
+
41
+ return if (height.present? && height <= 0) || dest_synsets.blank?
42
+
43
+ dest_synsets.each do |dest_synset|
44
+ @graph_viz.link(source: node_contents(synset), destination: node_contents(dest_synset))
45
+
46
+ height = height.present? ? height - 1 : nil
47
+ draw_hype(dest_synset, height)
48
+ end
49
+ end
50
+
51
+ def draw_hypo(synset, depth)
52
+ dest_synsets = synset.synlinks.where(link: '下位語').map(&:dest_synset)
53
+
54
+ return if (depth.present? && depth <= 0) || dest_synsets.blank?
55
+
56
+ dest_synsets.each do |dest_synset|
57
+ @graph_viz.link(source: node_contents(dest_synset), destination: node_contents(synset))
58
+
59
+ depth = depth.present? ? depth - 1 : nil
60
+ draw_hypo(dest_synset, depth)
61
+ end
62
+ end
63
+
64
+ def node_contents(synset)
65
+ synset_def = synset.synset_defs.where(lang: 'jpn').first&.def
66
+
67
+ return synset_def if @options[:node_contents] == 'synset'
68
+
69
+ words = synset.words.where(pos: "noun").map(&:lemma).join(',')
70
+
71
+ "#{synset_def}\n(#{words})"
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby-graphviz'
4
+
5
+ module WordnetJapanDiagram
6
+ class GraphViz
7
+ GRAPHVIZ_SETTING = {
8
+ use: :dot,
9
+ type: :digraph,
10
+ rankdir: :BT,
11
+ ranksep: 0.75, # NOTE default: 0.5
12
+ # nodesep: 0.5, # NOTE default: 0.25
13
+ pad: '0,0',
14
+ margin: '0,0',
15
+ concentrate: true,
16
+ labelloc: :t,
17
+ fontsize: 30, # NOTE default: 14.0
18
+ splines: 'spline', # NOTE https://graphviz.org/docs/attrs/splines/
19
+ }
20
+
21
+ EDGE_SETTING = {
22
+ color: '#444444'
23
+ }
24
+
25
+ NODE_SETTING = {
26
+ style: 'filled',
27
+ fontname: 'Helvetica Neue'
28
+ }
29
+
30
+ MAIN_NODE_COLOR = '#ecd3c4'
31
+ OTHER_NODE_COLOR = '#c4ddec'
32
+
33
+ def initialize(command_options)
34
+ # NOTE https://graphviz.org/
35
+ @graph_viz = ::GraphViz.new(:G, GRAPHVIZ_SETTING.merge(command_options.graph_viz_options))
36
+ end
37
+
38
+ def link(source:, destination:)
39
+ src_node = find_or_create_node(node_contents: source)
40
+ dst_node = find_or_create_node(node_contents: destination)
41
+
42
+ return if src_node.neighbors.present? && src_node.neighbors.map(&:id).include?(dst_node.id)
43
+
44
+ @graph_viz.add_edges(src_node, dst_node, EDGE_SETTING)
45
+ end
46
+
47
+ def find_or_create_node(node_contents:, target: :other)
48
+ if (existing_node = @graph_viz.find_node(node_contents)).present?
49
+ existing_node
50
+ else
51
+ @graph_viz.add_nodes(node_contents, label: node_contents, fillcolor: node_color(target), **NODE_SETTING)
52
+ end
53
+ end
54
+
55
+ def output(file_type:, file_path:)
56
+ @graph_viz.output(file_type => file_path)
57
+ end
58
+
59
+ private
60
+
61
+ def node_color(target)
62
+ case target
63
+ when :main
64
+ MAIN_NODE_COLOR
65
+ when :other
66
+ OTHER_NODE_COLOR
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WordnetJapanDiagram
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,38 @@
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
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "wordnet_japan_diagram/version"
4
+
5
+ require_relative "wordnet_japan_diagram/cli"
@@ -0,0 +1,4 @@
1
+ module WordnetJapanDiagram
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/wordnet_japan_diagram/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "wordnet_japan_diagram"
7
+ spec.version = WordnetJapanDiagram::VERSION
8
+ spec.authors = ["tommy-012"]
9
+ spec.email = ["lonnlilonn@googlemail.com"]
10
+
11
+ spec.summary = "Draw a diagram of Japanese WordNet."
12
+ spec.description = "Draw a diagram of Japanese WordNet about the hypernyms and hyponyms of the search word."
13
+ spec.homepage = "https://github.com/tommy-012/wordnet_japan_diagram"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/tommy-012/wordnet_japan_diagram"
19
+ spec.metadata["changelog_uri"] = "https://github.com/tommy-012/wordnet_japan_diagram/blob/main/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+
35
+ # For more information and examples about making a new gem, check out our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
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
+ spec.add_dependency "choice", "~> 0.2.0"
42
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wordnet_japan_diagram
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - tommy-012
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-02-19 00:00:00.000000000 Z
12
+ dependencies:
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
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby-graphviz
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.2.5
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: choice
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.2.0
69
+ description: Draw a diagram of Japanese WordNet about the hypernyms and hyponyms of
70
+ the search word.
71
+ email:
72
+ - lonnlilonn@googlemail.com
73
+ executables:
74
+ - wordnet_japan_diagram
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".rspec"
79
+ - ".rubocop.yml"
80
+ - CHANGELOG.md
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - exe/wordnet_japan_diagram
88
+ - lib/wordnet_japan_diagram.rb
89
+ - lib/wordnet_japan_diagram/cli.rb
90
+ - lib/wordnet_japan_diagram/command_options.rb
91
+ - lib/wordnet_japan_diagram/diagram_creater.rb
92
+ - lib/wordnet_japan_diagram/graph_viz.rb
93
+ - lib/wordnet_japan_diagram/version.rb
94
+ - lib/wordnet_japan_diagram/wordnet_japan/database.rb
95
+ - lib/wordnet_japan_diagram/wordnet_japan/sense.rb
96
+ - lib/wordnet_japan_diagram/wordnet_japan/synlink.rb
97
+ - lib/wordnet_japan_diagram/wordnet_japan/synset.rb
98
+ - lib/wordnet_japan_diagram/wordnet_japan/synset_def.rb
99
+ - lib/wordnet_japan_diagram/wordnet_japan/word.rb
100
+ - sig/wordnet_japan_diagram.rbs
101
+ - wordnet_japan_diagram.gemspec
102
+ homepage: https://github.com/tommy-012/wordnet_japan_diagram
103
+ licenses:
104
+ - MIT
105
+ metadata:
106
+ homepage_uri: https://github.com/tommy-012/wordnet_japan_diagram
107
+ source_code_uri: https://github.com/tommy-012/wordnet_japan_diagram
108
+ changelog_uri: https://github.com/tommy-012/wordnet_japan_diagram/blob/main/CHANGELOG.md
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 2.6.0
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubygems_version: 3.3.26
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Draw a diagram of Japanese WordNet.
128
+ test_files: []