proiel-cli 1.0.0 → 1.1.0

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
  SHA1:
3
- metadata.gz: cf5056d98706541003c897f25b470145a26dab43
4
- data.tar.gz: 3bc9d72f373deec98554ec4bab9d0482f427a6b6
3
+ metadata.gz: fc78a4e1e71e4aeb4a10f6af394233bfa72c3be6
4
+ data.tar.gz: db99ba991d35a6a97948844b72c737f97bb870e1
5
5
  SHA512:
6
- metadata.gz: 6f4a512e9c4f35ccfdd84c4ec1c7d2bed4c5089862802c6171247817b64bb00ba9a3dadf2e82b7ba12bee2b647b86d0faf705e402e34ba6f74c0bdc3a8547796
7
- data.tar.gz: c14b7972c896f8f47dbf764b69796c011c9827b715fbf324b2bcca58f82d30acad7f0906d084e3e654299bb5cc22a77547c7fa6a7ef0e6d1c135227cf69701d9
6
+ metadata.gz: 5c6ef485c7ac49f746fb03a382e75601941893ff986618eabea94392e8a5c196366e2fd3a4a478a7312748e2ce66ec3db78d34832eec66ad115a1682ba8fd78c
7
+ data.tar.gz: 45cd79177f845d6e07bdd7af82af5a764d10acdc151c0c148c9334db33d70f905f62e41a9691106df42f373d57083e933b0b8c2713abf83072484f398e5d1bbf
data/README.md CHANGED
@@ -17,6 +17,8 @@ The gem includes a command-line utility `proiel` for a number of routine tasks.
17
17
  `proiel convert conll` converts the treebank to CoNLL format. Use `proiel
18
18
  --help` for further examples and usage instructions.
19
19
 
20
+ To use the `visualize` command you will need a local installation of [graphviz](http://graphviz.org). More specifically, the `dot` command must be available in the path.
21
+
20
22
  ## Development
21
23
 
22
24
  Check out the git repository from github and run `bin/setup` to install
data/bin/setup CHANGED
@@ -4,4 +4,5 @@ IFS=$'\n\t'
4
4
 
5
5
  bundle install
6
6
 
7
- # Do any other automated setup that you need to do here
7
+ # Issue a warning if dot cannot be found
8
+ command -v dot >/dev/null 2>&1 || { echo >&2; echo >&2 "Warning: dot binary not found. Please install graphviz."; exit 0; }
data/lib/proiel/cli.rb CHANGED
@@ -1,2 +1,4 @@
1
+ require 'ruby-progressbar'
2
+
1
3
  require 'proiel/cli/version'
2
4
  require 'proiel/cli/commands'
@@ -0,0 +1,80 @@
1
+ module PROIEL
2
+ module Commands
3
+ class Visualize < Command
4
+ class << self
5
+ def init_with_program(prog)
6
+ prog.command(:visualize) do |c|
7
+ c.syntax 'visualize sentences|divs|sources FILENAME(S)'
8
+ c.description 'Visualize treebank graphs'
9
+ c.option 'objects', '--objects sentences|divs|sources', 'Objects to visualize (default: sentences)'
10
+ c.option 'format', '--format png|svg|dot', 'Output format (default: svg)'
11
+ c.option 'layout', '--layout classic|linearized|packed', 'Graph layout (default: classic)'
12
+
13
+ c.action { |args, options| process(args, options) }
14
+ end
15
+ end
16
+
17
+ def process(args, options)
18
+ objects = options['objects'] || 'sentences'
19
+ format = options['format'] || 'svg'
20
+ layout = options['layout'] || 'classic'
21
+
22
+ if layout != 'classic' and layout != 'linearized' and layout != 'packed'
23
+ STDERR.puts "Invalid layout"
24
+ exit 1
25
+ end
26
+
27
+ if objects != 'sentences' and objects != 'divs' and objects != 'sources'
28
+ STDERR.puts "Invalid object type"
29
+ exit 1
30
+ end
31
+
32
+ if format != 'png' and format != 'svg' and format != 'dot'
33
+ STDERR.puts "Invalid format"
34
+ exit 1
35
+ end
36
+
37
+ tb = PROIEL::Treebank.new
38
+
39
+ if args.empty?
40
+ STDERR.puts "Reading from standard input...".green if options['verbose']
41
+ tb.load_from_xml(STDIN)
42
+ else
43
+ args.each do |filename|
44
+ STDERR.puts "Reading #{filename}...".green if options['verbose']
45
+
46
+ tb.load_from_xml(filename)
47
+ end
48
+ end
49
+
50
+ tb.sources.each do |source|
51
+ case objects
52
+ when 'sources'
53
+ puts "This can take a very, very long time... Be patient!"
54
+ save_graph layout, format, source
55
+ when 'divs'
56
+ save_graphs source.divs, layout, format, source.id, source.divs.count
57
+ when 'sentences'
58
+ save_graphs source.sentences, layout, format, source.id, source.sentences.count
59
+ else
60
+ raise
61
+ end
62
+ end
63
+ end
64
+
65
+ def save_graph(template, format, graph)
66
+ PROIEL::Visualization::Graphviz.generate_to_file(template, graph, format, "#{graph.id}.#{format}")
67
+ end
68
+
69
+ def save_graphs(enumerator, template, format, title, n)
70
+ pbar = ProgressBar.create progress_mark: 'X', remainder_mark: ' ', title: title, total: n
71
+
72
+ enumerator.each_with_index do |object, i|
73
+ save_graph template, format, object
74
+ pbar.increment
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,5 +1,5 @@
1
1
  module PROIEL
2
2
  module CLI
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proiel-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marius L. Jøhndal
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-04 00:00:00.000000000 Z
12
+ date: 2016-08-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
@@ -59,42 +59,42 @@ dependencies:
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '1.1'
62
+ version: '1.2'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '1.1'
69
+ version: '1.2'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: bundler
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '1.10'
76
+ version: '1.12'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '1.10'
83
+ version: '1.12'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: rake
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '10.0'
90
+ version: '11.2'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '10.0'
97
+ version: '11.2'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: rspec
100
100
  requirement: !ruby/object:Gem::Requirement
@@ -143,42 +143,42 @@ dependencies:
143
143
  requirements:
144
144
  - - "~>"
145
145
  - !ruby/object:Gem::Version
146
- version: 2.0.2
146
+ version: '2.4'
147
147
  type: :development
148
148
  prerelease: false
149
149
  version_requirements: !ruby/object:Gem::Requirement
150
150
  requirements:
151
151
  - - "~>"
152
152
  - !ruby/object:Gem::Version
153
- version: 2.0.2
153
+ version: '2.4'
154
154
  - !ruby/object:Gem::Dependency
155
155
  name: aruba
156
156
  requirement: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - "~>"
159
159
  - !ruby/object:Gem::Version
160
- version: 0.8.1
160
+ version: '0.14'
161
161
  type: :development
162
162
  prerelease: false
163
163
  version_requirements: !ruby/object:Gem::Requirement
164
164
  requirements:
165
165
  - - "~>"
166
166
  - !ruby/object:Gem::Version
167
- version: 0.8.1
167
+ version: '0.14'
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: yard
170
170
  requirement: !ruby/object:Gem::Requirement
171
171
  requirements:
172
172
  - - "~>"
173
173
  - !ruby/object:Gem::Version
174
- version: 0.8.7
174
+ version: '0.9'
175
175
  type: :development
176
176
  prerelease: false
177
177
  version_requirements: !ruby/object:Gem::Requirement
178
178
  requirements:
179
179
  - - "~>"
180
180
  - !ruby/object:Gem::Version
181
- version: 0.8.7
181
+ version: '0.9'
182
182
  description: This provides a command-line interface to various tools that manipulate
183
183
  treebanks that use the PROIEL dependency format.
184
184
  email:
@@ -204,7 +204,7 @@ files:
204
204
  - lib/proiel/cli/commands/info.rb
205
205
  - lib/proiel/cli/commands/tokenize.rb
206
206
  - lib/proiel/cli/commands/validate.rb
207
- - lib/proiel/cli/commands/words.rb
207
+ - lib/proiel/cli/commands/visualize.rb
208
208
  - lib/proiel/cli/converters/conll-u.rb
209
209
  - lib/proiel/cli/converters/conll-u/morphology.rb
210
210
  - lib/proiel/cli/converters/conll-u/syntax.rb
@@ -241,4 +241,3 @@ signing_key:
241
241
  specification_version: 4
242
242
  summary: A command-line interface for working with PROIEL treebanks
243
243
  test_files: []
244
- has_rdoc:
@@ -1,36 +0,0 @@
1
- module PROIEL
2
- module Commands
3
- class Words < Command
4
- class << self
5
- def init_with_program(prog)
6
- prog.command(:words) do |c|
7
- c.syntax 'words [options] filename(s)'
8
- c.description 'Extract a word list'
9
-
10
- c.action do |args, options|
11
- if args.empty?
12
- STDERR.puts 'Missing filename(s). Use --help for more information.'
13
- else
14
- process(args, options)
15
- end
16
- end
17
- end
18
- end
19
-
20
- def process(args, options)
21
- tb = PROIEL::Treebank.new
22
-
23
- args.each do |filename|
24
- STDERR.puts "Reading #{filename}...".green if options['verbose']
25
-
26
- tb.load_from_xml(filename)
27
- end
28
-
29
- tb.sources.map { |s| s.tokens.map(&:form) }.flatten.sort.uniq.each do |form|
30
- STDOUT.puts form
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end