opener-kaf-naf-parser 1.1.0 → 2.0.0

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
  SHA1:
3
- metadata.gz: b56f23da566c734261e96e6ffb2ce0d70e1ddb76
4
- data.tar.gz: acf4525a3c6783ab154a2be067a61b4eb0d6f669
3
+ metadata.gz: 6f5aaa78b3700c42cc998864b448bb9d68ec528a
4
+ data.tar.gz: 8548321691a1ed22ceec59df5b668428766dae6f
5
5
  SHA512:
6
- metadata.gz: 0df0b939aaea16c508084f64abf55c523cedec7eb6fbed566bd8ab07a4f445f61e01603bdbb6379c4df9975ff4d9461d5a170b578a395b1c966319f47fe28788
7
- data.tar.gz: fdd941e5c62e566d0989de1562f4048b15864f79e6a26c1bfdc3c8fff49e6baca8209d3e021317cd1d0edbde8a90d1d870bfaf84daf7ee03e86929f3ac38dffa
6
+ metadata.gz: 0d63c868e56951e07d3588f8c8daeb0e77daeeeb2ba9f7ef4b7c81ffb08859133616ed8de27ad90c6578364fa338066de20cf45e97d9e35e892653c9e7178735
7
+ data.tar.gz: b305e47c22c75ce957b12bc44e640db1e31ba1df9e5143cc00c9744749ae75f4d45d7ee0d5257995f9cda5233ca3293d810e91ddf968bc6d714dc735f6e7aaa2
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- Introduction
2
- ------------
1
+ # KAF NAF Parser
3
2
 
4
3
  This library converts KAF to NAF and NAF to KAF. It also contains a webservice
5
4
  for doing exactly this.
@@ -16,14 +15,13 @@ project at [the OpeNER portal](http://opener-project.github.io). There you can
16
15
  also find references to terms like KAF (an XML standard to represent linguistic
17
16
  annotations in texts), component, cores, scenario's and pipelines.
18
17
 
19
- Quick Use Example
20
- -----------------
18
+ ## Quick Use Example
21
19
 
22
20
  Installing the kaf-naf-parser can be done by executing:
23
21
 
24
22
  gem install opener-kaf-naf-parser
25
23
 
26
- Please bare in mind that all components in OpeNER take KAF as an input and
24
+ Please keep in mind that all components in OpeNER take KAF as an input and
27
25
  output KAF by default.
28
26
 
29
27
  It ships with 3 command line tools and a webservice:
@@ -57,8 +55,12 @@ jobs (and write) jobs to and from Amazon SQS queues. For more information type:
57
55
 
58
56
  kaf-naf-parser-daemon -h
59
57
 
60
- Description of dependencies
61
- ---------------------------
58
+ ## Description of dependencies
59
+
60
+ The working part of this OpeNER component is the KafNafParserPy Python library.
61
+ More documentation on this library can be found here
62
+ http://kyoto.let.vu.nl/~izquierdo/api/KafNafParserPy/ and at
63
+ [KafNafParserPy Github Page](https://github.com/cltl/KafNafParserPy).
62
64
 
63
65
  This component runs best if you run it in an environment suited for OpeNER
64
66
  components. You can find an installation guide and helper tools in the
@@ -72,21 +74,18 @@ At least you need the following system setup:
72
74
  * Ruby 1.9.3 or newer
73
75
  * Python 2.6
74
76
 
75
- Where to go from here
76
- ---------------------
77
+ ## Where to go from here
77
78
 
78
79
  * [Check the project website](http://opener-project.github.io)
79
80
  * [Checkout the webservice](http://opener.olery.com/kaf-naf-parser)
80
81
 
81
- Report problem/Get help
82
- -----------------------
82
+ ## Report problem/Get help
83
83
 
84
84
  If you encounter problems, please email support@opener-project.eu or leave an
85
85
  issue in the
86
86
  [issue tracker](https://github.com/opener-project/kaf-naf-parser/issues).
87
87
 
88
- Contributing
89
- ------------
88
+ ## Contributing
90
89
 
91
90
  1. Fork it <http://github.com/opener-project/kaf-naf-parser/fork>
92
91
  2. Create your feature branch (`git checkout -b my-new-feature`)
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative '../lib/opener/kaf_naf_parser'
4
4
 
5
- cli = Opener::KafNafParser::CLI.new(:args => ARGV)
5
+ cli = Opener::KafNafParser::CLI.new
6
6
 
7
- cli.run(STDIN.tty? ? nil : STDIN.read)
7
+ cli.run
8
8
 
@@ -2,9 +2,9 @@
2
2
 
3
3
  require 'opener/daemons'
4
4
 
5
- exec_path = File.expand_path('../../exec/kaf-naf-parser.rb', __FILE__)
6
-
7
- Opener::Daemons::Controller.new(
5
+ controller = Opener::Daemons::Controller.new(
8
6
  :name => 'kaf-naf-parser',
9
- :exec_path => exec_path
10
- )
7
+ :exec_path => File.expand_path('../../exec/kaf-naf-parser.rb', __FILE__)
8
+ )
9
+
10
+ controller.run
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'puma/cli'
3
+ require 'opener/webservice'
4
4
 
5
- rack_config = File.expand_path('../../config.ru', __FILE__)
5
+ parser = Opener::Webservice::OptionParser.new(
6
+ 'opener-kaf-naf-parser',
7
+ File.expand_path('../../config.ru', __FILE__)
8
+ )
6
9
 
7
- cli = Puma::CLI.new([rack_config] + ARGV)
8
- cli.run
10
+ parser.run
@@ -2,6 +2,6 @@
2
2
 
3
3
  require_relative '../lib/opener/kaf_naf_parser'
4
4
 
5
- cli = Opener::KafNafParser::CLI.new(:args => ARGV, :conversion=>"to-naf")
5
+ cli = Opener::KafNafParser::CLI.new
6
6
 
7
- cli.run(STDIN.tty? ? nil : STDIN.read)
7
+ cli.run(ARGV + ['--nonaf'])
@@ -2,6 +2,6 @@
2
2
 
3
3
  require_relative '../lib/opener/kaf_naf_parser'
4
4
 
5
- cli = Opener::KafNafParser::CLI.new(:args => ARGV, :conversion=>"to-kaf")
5
+ cli = Opener::KafNafParser::CLI.new
6
6
 
7
- cli.run(STDIN.tty? ? nil : STDIN.read)
7
+ cli.run(ARGV + ['--tokaf'])
data/config.ru CHANGED
@@ -1,4 +1,3 @@
1
1
  require File.expand_path('../lib/opener/kaf_naf_parser', __FILE__)
2
- require File.expand_path('../lib/opener/kaf_naf_parser/server', __FILE__)
3
2
 
4
3
  run Opener::KafNafParser::Server
@@ -8,7 +8,7 @@ this_folder = os.path.dirname(os.path.realpath(__file__))
8
8
  # can be used to load packages (e.g. a locally installed copy of lxml).
9
9
  sys.path.append(os.path.join(this_folder, 'site-packages/pre_install'))
10
10
 
11
- from KafNafParser import KafNafParser
11
+ from KafNafParserPy import KafNafParser
12
12
 
13
13
  def main(argv):
14
14
  conversion = ""
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'opener/daemons'
4
+
4
5
  require_relative '../lib/opener/kaf_naf_parser'
5
6
 
6
- options = Opener::Daemons::OptParser.parse!(ARGV)
7
- daemon = Opener::Daemons::Daemon.new(Opener::KafNafParser, options)
7
+ daemon = Opener::Daemons::Daemon.new(Opener::KafNafParser)
8
8
 
9
- daemon.start
9
+ daemon.start
@@ -1,8 +1,9 @@
1
1
  require 'open3'
2
- require 'optparse'
2
+ require 'slop'
3
3
 
4
4
  require_relative 'kaf_naf_parser/version'
5
5
  require_relative 'kaf_naf_parser/cli'
6
+ require_relative 'kaf_naf_parser/server'
6
7
 
7
8
  module Opener
8
9
  ##
@@ -20,8 +21,8 @@ module Opener
20
21
  # @return [Hash]
21
22
  #
22
23
  DEFAULT_OPTIONS = {
23
- :args => [],
24
- :conversion => "to-kaf"
24
+ :args => [],
25
+ :conversion => 'to-kaf'
25
26
  }.freeze
26
27
 
27
28
  ##
@@ -40,26 +41,49 @@ module Opener
40
41
  # @return [String]
41
42
  #
42
43
  def command
43
- return "python -E #{kernel} #{options[:args].join(' ')} #{conversion}"
44
+ args = options[:args].join(' ')
45
+
46
+ return "python -E #{kernel} #{args} #{conversion}"
44
47
  end
45
48
 
49
+ ##
50
+ # @return [String]
51
+ #
46
52
  def conversion
47
53
  "--#{options[:conversion].gsub(/-/,'')}"
48
54
  end
49
55
 
50
56
  ##
51
- # Processes the input and returns an Array containing the output of STDOUT,
52
- # STDERR and an object containing process information.
57
+ # Processes a given input KAF/NAF document and returns a new document in the
58
+ # opposite format.
53
59
  #
54
- # @param [String] input The text of which to detect the language.
55
- # @return [Array]
60
+ # @param [String] input
61
+ # @return [String]
56
62
  #
57
63
  def run(input)
58
- return Open3.capture3(command, :stdin_data => input)
64
+ stdout, stderr, process = capture(input)
65
+
66
+ raise stderr unless process.success?
67
+
68
+ return stdout
59
69
  end
60
70
 
61
71
  protected
62
72
 
73
+ ##
74
+ # capture3 method doesn't work properly with Jruby, so
75
+ # this is a workaround
76
+ #
77
+ def capture(input)
78
+ Open3.popen3(*command.split(" ")) {|i, o, e, t|
79
+ out_reader = Thread.new { o.read }
80
+ err_reader = Thread.new { e.read }
81
+ i.write input
82
+ i.close
83
+ [out_reader.value, err_reader.value, t.value]
84
+ }
85
+ end
86
+
63
87
  ##
64
88
  # @return [String]
65
89
  #
@@ -1,92 +1,66 @@
1
1
  module Opener
2
2
  class KafNafParser
3
3
  ##
4
- # CLI wrapper around {Opener::LanguageIdentifier} using OptionParser.
4
+ # CLI wrapper around {Opener::KafNafParser} using Slop.
5
5
  #
6
- # @!attribute [r] options
7
- # @return [Hash]
8
- # @!attribute [r] option_parser
9
- # @return [OptionParser]
6
+ # @!attribute [r] parser
7
+ # @return [Slop]
10
8
  #
11
9
  class CLI
12
- attr_reader :options, :option_parser
10
+ attr_reader :parser
11
+
12
+ def initialize
13
+ @parser = configure_slop
14
+ end
13
15
 
14
16
  ##
15
- # @param [Hash] options
17
+ # @param [Array] argv
16
18
  #
17
- def initialize(options = {})
18
- @options = DEFAULT_OPTIONS.merge(options)
19
-
20
- @option_parser = OptionParser.new do |opts|
21
- opts.program_name = 'kaf-naf-parser'
22
- opts.summary_indent = ' '
23
-
24
- opts.on('-h', '--help', 'Shows this help message') do
25
- show_help
26
- end
27
-
28
- opts.on('-v', '--version', 'Shows the current version') do
29
- show_version
30
- end
19
+ def run(argv = ARGV)
20
+ parser.parse(argv)
21
+ end
31
22
 
32
- opts.on('-k', '--tokaf', 'Parses input to KAF') do
33
- @options[:conversion] = "to-kaf"
34
- end
23
+ ##
24
+ # @return [Slop]
25
+ #
26
+ def configure_slop
27
+ return Slop.new(:strict => false, :indent => 2, :help => true) do
28
+ banner 'Usage: kaf-naf-parser [OPTIONS]'
35
29
 
36
- opts.on('-n', '--tonaf', 'Parses input to NAF') do
37
- @options[:conversion] = "to-naf"
38
- end
30
+ separator <<-EOF.chomp
39
31
 
40
- opts.on('-l', '--log', 'Enable logging to STDERR') do
41
- @options[:logging] = true
42
- end
32
+ About:
43
33
 
44
- opts.separator <<-EOF
34
+ Component for converting KAF documents to NAF documents and vice-versa.
35
+ This command reads input from STDIN.
45
36
 
46
- Examples:
37
+ Example:
47
38
 
48
- cat example.kaf | #{opts.program_name} --tonaf # Basic usage
49
- cat example.kaf | #{opts.program_name} --tonaf -l # Logs information to STDERR
39
+ cat some_file.kaf | kaf-naf-parser --tonaf
50
40
  EOF
51
- end
52
- end
53
41
 
54
- ##
55
- # @param [String] input
56
- #
57
- def run(input)
58
- option_parser.parse!(options[:args])
42
+ separator "\nOptions:\n"
59
43
 
60
- tagger = KafNafParser.new(options)
44
+ on :v, :version, 'Shows the current version' do
45
+ abort "kaf-naf-parser v#{VERSION} on #{RUBY_DESCRIPTION}"
46
+ end
61
47
 
62
- stdout, stderr, process = tagger.run(input)
48
+ on :k, :tokaf, 'Converts NAF to KAF'
49
+ on :n, :tonaf, 'Converts KAF to NAF'
63
50
 
64
- if process.success?
65
- puts stdout
51
+ run do |opts, args|
52
+ conversion = opts[:tonaf] ? 'to-naf' : 'to-kaf'
53
+ parser = KafNafParser.new(
54
+ :args => args,
55
+ :conversion => conversion
56
+ )
66
57
 
67
- if options[:logging] and !stderr.empty?
68
- STDERR.puts(stderr)
58
+ input = STDIN.tty? ? nil : STDIN.read
59
+
60
+ puts parser.run(input)
69
61
  end
70
- else
71
- abort stderr
72
62
  end
73
63
  end
74
-
75
- private
76
-
77
- ##
78
- # Shows the help message and exits the program.
79
- #
80
- def show_help
81
- abort option_parser.to_s
82
- end
83
-
84
- ##
85
- # Shows the version and exits the program.
86
- #
87
- def show_version
88
- abort "#{option_parser.program_name} v#{VERSION} on #{RUBY_DESCRIPTION}"
89
- end
90
64
  end # CLI
91
65
  end # KafNafParser
92
66
  end # Opener
@@ -1,5 +1,3 @@
1
- require 'sinatra/base'
2
- require 'httpclient'
3
1
  require 'opener/webservice'
4
2
 
5
3
  module Opener
@@ -7,10 +5,11 @@ module Opener
7
5
  ##
8
6
  # Polarity tagger server powered by Sinatra.
9
7
  #
10
- class Server < Webservice
8
+ class Server < Webservice::Server
11
9
  set :views, File.expand_path('../views', __FILE__)
12
- text_processor KafNafParser
13
- accepted_params :input, :conversion
10
+
11
+ self.text_processor = KafNafParser
12
+ self.accepted_params = [:conversion]
14
13
  end # Server
15
14
  end # KafNafParser
16
15
  end # Opener
@@ -1,5 +1,5 @@
1
1
  module Opener
2
2
  class KafNafParser
3
- VERSION = '1.1.0'
3
+ VERSION = '2.0.0'
4
4
  end # KafNafVersion
5
5
  end # Opener
@@ -1,16 +1,16 @@
1
1
  require File.expand_path('../lib/opener/kaf_naf_parser/version', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
- gem.name = 'opener-kaf-naf-parser'
5
- gem.version = Opener::KafNafParser::VERSION
6
- gem.authors = ['ruben.izquierdobevia@vu.nl','development@olery.com']
7
- gem.summary = 'Parser to translate KAF to NAF and back.'
8
- gem.description = gem.summary
9
- gem.homepage = "http://github.com/cltl/KafNafParserPy"
10
- gem.required_ruby_version = '>= 1.9.2'
11
- gem.extensions = ['ext/hack/Rakefile']
4
+ gem.name = 'opener-kaf-naf-parser'
5
+ gem.version = Opener::KafNafParser::VERSION
6
+ gem.authors = ['ruben.izquierdobevia@vu.nl','development@olery.com']
7
+ gem.summary = 'Parser to translate KAF to NAF and back.'
8
+ gem.description = gem.summary
9
+ gem.homepage = "http://github.com/cltl/KafNafParserPy"
10
+ gem.extensions = ['ext/hack/Rakefile']
11
+ gem.license = 'Apache 2.0'
12
12
 
13
- gem.license = 'Apache 2.0'
13
+ gem.required_ruby_version = '>= 1.9.2'
14
14
 
15
15
  gem.files = Dir.glob([
16
16
  'core/*',
@@ -27,13 +27,11 @@ Gem::Specification.new do |gem|
27
27
 
28
28
  gem.executables = Dir.glob('bin/*').map { |file| File.basename(file) }
29
29
 
30
+ gem.add_dependency 'opener-daemons', '~> 2.2'
31
+ gem.add_dependency 'opener-webservice', '~> 2.1'
32
+ gem.add_dependency 'opener-core', '~> 2.2'
33
+
30
34
  gem.add_dependency 'builder'
31
- gem.add_dependency 'sinatra', '~>1.4.3'
32
- gem.add_dependency 'httpclient'
33
- gem.add_dependency 'uuidtools'
34
- gem.add_dependency 'opener-webservice'
35
- gem.add_dependency 'puma'
36
- gem.add_dependency 'opener-daemons'
37
35
 
38
36
  gem.add_development_dependency 'rspec', '~> 3.0'
39
37
  gem.add_development_dependency 'cucumber'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-kaf-naf-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ruben.izquierdobevia@vu.nl
@@ -9,94 +9,52 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-25 00:00:00.000000000 Z
12
+ date: 2014-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: builder
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: '0'
28
- - !ruby/object:Gem::Dependency
29
- name: sinatra
15
+ name: opener-daemons
30
16
  requirement: !ruby/object:Gem::Requirement
31
17
  requirements:
32
18
  - - "~>"
33
19
  - !ruby/object:Gem::Version
34
- version: 1.4.3
20
+ version: '2.2'
35
21
  type: :runtime
36
22
  prerelease: false
37
23
  version_requirements: !ruby/object:Gem::Requirement
38
24
  requirements:
39
25
  - - "~>"
40
26
  - !ruby/object:Gem::Version
41
- version: 1.4.3
42
- - !ruby/object:Gem::Dependency
43
- name: httpclient
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: '0'
49
- type: :runtime
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: '0'
56
- - !ruby/object:Gem::Dependency
57
- name: uuidtools
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- type: :runtime
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: '0'
27
+ version: '2.2'
70
28
  - !ruby/object:Gem::Dependency
71
29
  name: opener-webservice
72
30
  requirement: !ruby/object:Gem::Requirement
73
31
  requirements:
74
- - - ">="
32
+ - - "~>"
75
33
  - !ruby/object:Gem::Version
76
- version: '0'
34
+ version: '2.1'
77
35
  type: :runtime
78
36
  prerelease: false
79
37
  version_requirements: !ruby/object:Gem::Requirement
80
38
  requirements:
81
- - - ">="
39
+ - - "~>"
82
40
  - !ruby/object:Gem::Version
83
- version: '0'
41
+ version: '2.1'
84
42
  - !ruby/object:Gem::Dependency
85
- name: puma
43
+ name: opener-core
86
44
  requirement: !ruby/object:Gem::Requirement
87
45
  requirements:
88
- - - ">="
46
+ - - "~>"
89
47
  - !ruby/object:Gem::Version
90
- version: '0'
48
+ version: '2.2'
91
49
  type: :runtime
92
50
  prerelease: false
93
51
  version_requirements: !ruby/object:Gem::Requirement
94
52
  requirements:
95
- - - ">="
53
+ - - "~>"
96
54
  - !ruby/object:Gem::Version
97
- version: '0'
55
+ version: '2.2'
98
56
  - !ruby/object:Gem::Dependency
99
- name: opener-daemons
57
+ name: builder
100
58
  requirement: !ruby/object:Gem::Requirement
101
59
  requirements:
102
60
  - - ">="