freeling-analyzer 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Guardfile CHANGED
@@ -6,6 +6,7 @@ guard :minitest do
6
6
  #watch(%r|^test/(.*)\/?test_(.*)\.rb|)
7
7
  #watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
8
8
  #watch(%r|^test/test_helper\.rb|) { "test" }
9
+
9
10
  watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1].split("/").last}_test.rb" }
10
11
  watch(%r{^test/.+_test\.rb$})
11
12
  watch('test/test_helper.rb') { "test" }
data/README.md CHANGED
@@ -25,6 +25,7 @@ analyzer.tokens.map { |t| t.lemma }
25
25
  the input text to `analyzer` on demand.
26
26
  * It just works with the default instalation of FreeLing. Just set the language
27
27
  to use and you're good to go.
28
+ * It supports Freeling's [client/server mode](http://nlp.lsi.upc.edu/freeling/doc/userman/html/node84.html). Ex: `FreeLing::Analyzer.new(text, :server_host => 'localhost:50005')` (`analyze` must be running in server mode)
28
29
 
29
30
  ## Installation
30
31
 
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
9
9
  `analyzer`, a binary tool included in FreeLing's
10
10
  package that allows the user to process a stream of
11
11
  text with FreeLing.}
12
- gem.homepage = "https://github.com/munshkr/freeling-analyzer-ruby"
12
+ gem.homepage = "http://munshkr.github.io/freeling-analyzer-ruby"
13
13
 
14
14
  gem.files = `git ls-files`.split($\)
15
15
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
21
21
  gem.add_development_dependency "rake"
22
22
  gem.add_development_dependency "yard"
23
23
  gem.add_development_dependency "mocha", "~> 0.14.0"
24
- gem.add_development_dependency "minitest", "~> 5.0.2"
24
+ gem.add_development_dependency "minitest", "~> 4.7.4"
25
25
  gem.add_development_dependency "guard", "~> 1.8.0"
26
26
  gem.add_development_dependency "guard-minitest", "~> 0.5.0"
27
27
 
@@ -14,12 +14,14 @@ module FreeLing
14
14
  @document = document
15
15
 
16
16
  @options = {
17
- :share_path => freeling_path,
18
- :analyze_path => analyzer_path,
19
- :input_format => :plain,
20
- :output_format => :tagged,
21
- :memoize => true,
22
- :language => :es
17
+ :share_path => freeling_path,
18
+ :analyze_path => analyzer_path,
19
+ :input_format => :plain,
20
+ :output_format => :tagged,
21
+ :memoize => true,
22
+ :language => :es,
23
+ :server_host => nil,
24
+ :analyze_client_path => analyzer_client_path
23
25
  }.merge(opts)
24
26
  end
25
27
 
@@ -75,12 +77,16 @@ module FreeLing
75
77
 
76
78
  private
77
79
  def command
78
- "#{@options[:analyze_path]} " \
79
- "-f #{config_path} " \
80
- "--inpf #{@options[:input_format]} " \
81
- "--outf #{@options[:output_format]} " \
82
- "--nec " \
83
- "--noflush"
80
+ if @options[:server_host].nil?
81
+ "#{@options[:analyze_path]} " \
82
+ "-f #{config_path} " \
83
+ "--inpf #{@options[:input_format]} " \
84
+ "--outf #{@options[:output_format]} " \
85
+ "--nec " \
86
+ "--noflush"
87
+ else
88
+ "#{@options[:analyze_client_path]} #{@options[:server_host]}"
89
+ end
84
90
  end
85
91
 
86
92
  def config_path
@@ -93,7 +99,9 @@ module FreeLing
93
99
  @process_wrapper = ProcessWrapper.new(command, output_fd, "FREELINGSHARE" => @options[:share_path])
94
100
 
95
101
  @process_wrapper.run.each do |line|
96
- if not line.empty?
102
+ if line.empty?
103
+ yielder << nil
104
+ else
97
105
  yielder << parse_token_line(line)
98
106
  end
99
107
  end
@@ -126,5 +134,10 @@ module FreeLing
126
134
  def analyzer_path
127
135
  FreelingDefault.analyzer_path
128
136
  end
137
+
138
+ def analyzer_client_path
139
+ FreelingDefault.analyzer_client_path
140
+ end
141
+
129
142
  end
130
143
  end
@@ -2,16 +2,23 @@ module FreeLing
2
2
  class Analyzer
3
3
  class FreelingDefault
4
4
 
5
- LOCAL_ANALYZE_PATH = "/usr/local/bin/analyzer"
6
- USR_ANALYZE_PATH = "/usr/bin/analyzer"
7
- LOCAL_FREELING_SHARE_PATH = "/usr/local/share/freeling"
8
- USR_FREELING_SHARE_PATH = "/usr/share/freeling"
5
+ LOCAL_ANALYZE_PATH = "/usr/local/bin/analyzer"
6
+ USR_ANALYZE_PATH = "/usr/bin/analyzer"
7
+ LOCAL_ANALYZE_CLIENT_PATH = "/usr/local/bin/analyzer_client"
8
+ USR_ANALYZE_CLIENT_PATH = "/usr/bin/analyzer_client"
9
+ LOCAL_FREELING_SHARE_PATH = "/usr/local/share/freeling"
10
+ USR_FREELING_SHARE_PATH = "/usr/share/freeling"
9
11
 
10
12
  class << self
11
13
  def analyzer_path
12
14
  self.new.analyzer_path
13
15
  end
14
16
 
17
+ def analyzer_client_path
18
+ self.new.analyzer_client_path
19
+ end
20
+
21
+
15
22
  def freeling_path
16
23
  self.new.freeling_path
17
24
  end
@@ -39,6 +46,17 @@ module FreeLing
39
46
  end
40
47
  end
41
48
 
49
+ def analyzer_client_path
50
+ if File.exists? LOCAL_ANALYZE_CLIENT_PATH
51
+ LOCAL_ANALYZE_CLIENT_PATH
52
+ elsif File.exists? USR_ANALYZE_CLIENT_PATH
53
+ USR_ANALYZE_CLIENT_PATH
54
+ else
55
+ raise_error(:analyze_client)
56
+ end
57
+ end
58
+
59
+
42
60
  def freeling_path
43
61
  if Dir.exists? LOCAL_FREELING_SHARE_PATH
44
62
  LOCAL_FREELING_SHARE_PATH
@@ -1,5 +1,5 @@
1
1
  module FreeLing
2
2
  class Analyzer
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "test_helper"
3
3
 
4
- class AnalyzerTest < MiniTest::Test
4
+ class AnalyzerTest < MiniTest::Unit::TestCase
5
5
  def setup
6
6
  @a = "El gato come pescado y bebe agua."
7
7
  @b = "Yo bajo con el hombre bajo a tocar el bajo bajo la escalera."
@@ -1,11 +1,13 @@
1
1
  require 'test_helper'
2
2
 
3
- class FreelingDefaultTest < MiniTest::Test
3
+ class FreelingDefaultTest < MiniTest::Unit::TestCase
4
4
  def setup
5
- @usr_bin_analyzer = "/usr/bin/analyzer"
6
- @local_bin_analyzer = "/usr/local/bin/analyzer"
7
- @usr_share_freeling = "/usr/share/freeling"
8
- @local_share_freeling = "/usr/local/share/freeling"
5
+ @usr_bin_analyzer = "/usr/bin/analyzer"
6
+ @local_bin_analyzer = "/usr/local/bin/analyzer"
7
+ @usr_bin_analyze_client = "/usr/bin/analyzer_client"
8
+ @local_bin_analyze_client = "/usr/local/bin/analyzer_client"
9
+ @usr_share_freeling = "/usr/share/freeling"
10
+ @local_share_freeling = "/usr/local/share/freeling"
9
11
  end
10
12
 
11
13
  def test_freeling_installed_on_usr
@@ -31,8 +33,9 @@ class FreelingDefaultTest < MiniTest::Test
31
33
  end
32
34
  end
33
35
 
34
- def test_instanciate_analyzer
36
+ def test_instantiate_analyzer
35
37
  File.stubs("exists?").with(@local_bin_analyzer).returns(true)
38
+ File.stubs("exists?").with(@local_bin_analyze_client).returns(true)
36
39
  Dir.stubs("exists?").with(@local_share_freeling).returns(true)
37
40
  document = mock("document")
38
41
 
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class ProcessWrapperTest < MiniTest::Test
3
+ class ProcessWrapperTest < MiniTest::Unit::TestCase
4
4
  def setup
5
5
  @command = "cat"
6
6
  @text = ["Hello", "world!"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freeling-analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-24 00:00:00.000000000 Z
12
+ date: 2013-08-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: 5.0.2
69
+ version: 4.7.4
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +74,7 @@ dependencies:
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: 5.0.2
77
+ version: 4.7.4
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: guard
80
80
  requirement: !ruby/object:Gem::Requirement
@@ -149,7 +149,7 @@ files:
149
149
  - test/freeling_default_test.rb
150
150
  - test/process_wrapper_test.rb
151
151
  - test/test_helper.rb
152
- homepage: https://github.com/munshkr/freeling-analyzer-ruby
152
+ homepage: http://munshkr.github.io/freeling-analyzer-ruby
153
153
  licenses: []
154
154
  post_install_message:
155
155
  rdoc_options: []
@@ -163,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
163
  version: '0'
164
164
  segments:
165
165
  - 0
166
- hash: 3306996118738224912
166
+ hash: 3533613494738759404
167
167
  required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  none: false
169
169
  requirements:
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
172
  version: '0'
173
173
  segments:
174
174
  - 0
175
- hash: 3306996118738224912
175
+ hash: 3533613494738759404
176
176
  requirements: []
177
177
  rubyforge_project:
178
178
  rubygems_version: 1.8.25