freeling-client 0.0.2 → 0.0.3

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: 22175d4562553eaba3d4d095df0cf9277813cfb7
4
- data.tar.gz: 3e62780a11bab00955217a164a8aa1dfa342b952
3
+ metadata.gz: 62a4acda4bd1089ad98e20cab65faed5e708cf02
4
+ data.tar.gz: c8d8cce46008af061eb11129376d7cc12563b2b0
5
5
  SHA512:
6
- metadata.gz: b4042283e88acaa32d476ce2575bef9f7611a798acb0b00d8c061bfec78c2aed66b8fa0b9295053d484b5a5fd8e25323f70a137a5a5a3205b3e54e349a1c2a69
7
- data.tar.gz: 249cf116647b29dba7a8b5d6286cf6a53edf4d1d6cd58ae016ebc5a5afe696e34627c13c6d7831e1c6e18bec73ad5e3f1379a91e6688a281e71626cb3a5c2c01
6
+ metadata.gz: a8a56248656d3176eef293c7dd121838e889605f88f0b1d4a913f0e0698afbc4aa771455174dc838e9faccd9648968f0440aa8c598a929a575288bfe56f775e0
7
+ data.tar.gz: 7ae997ecc681f90b20e36679c58d898f6c3f3af7a5bc9d68cfe0b8f4191bf622cee5aab7310cfd28c085d80be9d8206faa436261ef3e1ebfcd34c1e5ae9300d9
data/Gemfile.lock CHANGED
@@ -1,13 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- freeling-client (0.0.1)
5
- hashie (~> 3)
4
+ freeling-client (0.0.3)
6
5
 
7
6
  GEM
8
7
  remote: https://rubygems.org/
9
8
  specs:
10
- hashie (3.3.2)
11
9
  minitest (5.4.3)
12
10
  rake (10.3.2)
13
11
 
data/README.md CHANGED
@@ -60,3 +60,7 @@ With `nec` analysis:
60
60
 
61
61
  FREELINGSHARE=/usr/local/share/freeling/ analyzer \
62
62
  -f config/freeling/analyzer.cfg --server --port 50005 --inpf plain --outf tagged --nec --noflush
63
+
64
+ ## Testing Freeling stand-alone
65
+
66
+ FREELINGSHARE=/usr/local/share/freeling/ analyzer -f config/freeling/analyzer.cfg --inpf plain --locale es_ES.UTF-8 --outf morfo --noflush < file.txt
@@ -20,7 +20,6 @@ Gem::Specification.new do |s|
20
20
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
21
21
  s.require_paths = ["lib"]
22
22
 
23
- s.add_dependency "hashie", "~> 3"
24
23
  s.add_development_dependency "bundler", "~> 1.7"
25
24
  s.add_development_dependency "rake", "~> 10.3"
26
25
  s.add_development_dependency "minitest", "~> 5"
@@ -5,50 +5,27 @@ require "open3"
5
5
  require "tempfile"
6
6
  require "timeout"
7
7
 
8
- require "hashie/mash"
9
8
  require "freeling_client/base"
10
9
 
11
10
 
12
11
  module FreelingClient
13
12
  class Analyzer < Base
14
-
15
- Token = Class.new(Hashie::Mash)
16
-
17
13
  def initialize(opt={})
18
14
  @config = opt.fetch(:config, 'config/freeling/analyzer.cfg')
19
- @port = opt[:port]
20
- @server = opt[:server]
21
15
  @timeout = opt.fetch(:timeout, 60) # Three hours
22
16
  end
23
17
 
24
- def call(cmd, text)
25
- valide_command!(cmd)
26
-
27
- output = []
28
- file = Tempfile.new('foo', encoding: 'utf-8')
29
- begin
30
- file.write(text)
31
- file.close
32
- stdin, stdout, stderr = Open3.popen3(command(cmd, file.path))
33
- Timeout::timeout(@timeout) {
34
- until (line = stdout.gets).nil?
35
- output << line.chomp
36
- end
37
-
38
- message = stderr.readlines
39
- unless message.empty?
40
- raise ExtractionError, message.join("\n")
41
- end
42
- }
43
- rescue Timeout::Error
44
- raise ExtractionError, "Timeout"
45
- ensure
46
- file.close
47
- file.unlink
48
- end
49
- output
50
- end
51
-
18
+ # Generate tokens for a given text
19
+ #
20
+ # Example:
21
+ #
22
+ # >> analyzer = FreelingClient::Analyzer.new
23
+ # >> analyzer.token(:morfo, "Este texto está en español.")
24
+ #
25
+ # Arguments:
26
+ # cmd: (Symbol)
27
+ # text: (String)
28
+ #
52
29
  def tokens(cmd, text)
53
30
  valide_command!(cmd)
54
31
  Enumerator.new do |yielder|
@@ -58,6 +35,18 @@ module FreelingClient
58
35
  end
59
36
  end
60
37
 
38
+ # Generate ptokens for a given text
39
+ # ptokens: Tokens with position
40
+ #
41
+ # Example:
42
+ #
43
+ # >> analyzer = FreelingClient::Analyzer.new
44
+ # >> analyzer.ptoken(:morfo, "Este texto está en español.")
45
+ #
46
+ # Arguments:
47
+ # cmd: (Symbol)
48
+ # text: (String)
49
+ #
61
50
  def ptokens(cmd, text)
62
51
  Enumerator.new do |yielder|
63
52
  pos = 0
@@ -79,9 +68,37 @@ module FreelingClient
79
68
  end
80
69
  end
81
70
 
71
+ def call(cmd, text)
72
+ valide_command!(cmd)
73
+
74
+ output = []
75
+ file = Tempfile.new('foo', encoding: 'utf-8')
76
+ begin
77
+ file.write(text)
78
+ file.close
79
+ stdin, stdout, stderr = Open3.popen3(command(cmd, file.path))
80
+ Timeout::timeout(@timeout) {
81
+ until (line = stdout.gets).nil?
82
+ output << line.chomp
83
+ end
84
+
85
+ message = stderr.readlines
86
+ unless message.empty?
87
+ raise ExtractionError, message.join("\n")
88
+ end
89
+ }
90
+ rescue Timeout::Error
91
+ raise ExtractionError, "Timeout"
92
+ ensure
93
+ file.close
94
+ file.unlink
95
+ end
96
+ output
97
+ end
98
+
82
99
  def parse_token_line(str)
83
100
  form, lemma, tag, prob = str.split(' ')[0..3]
84
- Token.new({
101
+ FreelingClient::Token.new({
85
102
  :form => form,
86
103
  :lemma => lemma,
87
104
  :tag => tag,
@@ -4,12 +4,34 @@ require "freeling_client/base"
4
4
 
5
5
  module FreelingClient
6
6
  class Client < Base
7
+
8
+ # Initializes the client
9
+ #
10
+ # Example:
11
+ #
12
+ # >> client = FreelingClient::Client.new
13
+ #
14
+ # Arguments:
15
+ # server: (String)
16
+ # port: (String)
17
+ # timeout: (Integer)
18
+ #
7
19
  def initialize(opt = {})
8
20
  @server = opt.fetch(:server, 'localhost')
9
21
  @port = opt.fetch(:port, 50005)
10
22
  @timeout = opt.fetch(:timeout, 120)
11
23
  end
12
24
 
25
+ # Calls the server with a given text
26
+ #
27
+ # Example:
28
+ #
29
+ # >> client = FreelingClient::Client.new
30
+ # >> client.call("Este texto está en español.")
31
+ #
32
+ # Arguments:
33
+ # text: (String)
34
+ #
13
35
  def call(text)
14
36
  output = []
15
37
  file = Tempfile.new('foo', encoding: 'utf-8')
@@ -38,6 +60,8 @@ module FreelingClient
38
60
  output
39
61
  end
40
62
 
63
+ private
64
+
41
65
  def command(file_path)
42
66
  "/usr/local/bin/analyzer_client #{server}:#{port} < #{file_path}"
43
67
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "open3"
2
4
  require "freeling_client/base"
3
5
 
@@ -10,6 +12,17 @@ module FreelingClient
10
12
  @timeout = opt.fetch(:timeout, 120)
11
13
  end
12
14
 
15
+ # Detects language
16
+ #
17
+ # Example:
18
+ #
19
+ # >> detector = FreelingClient::LanguageDetector.new
20
+ # >> detector.detect("Este texto está en español.")
21
+ # => "es"
22
+ #
23
+ # Arguments:
24
+ # text: (String)
25
+ #
13
26
  def detect(text)
14
27
  output = []
15
28
  file = Tempfile.new('foo', encoding: 'utf-8')
@@ -38,6 +51,8 @@ module FreelingClient
38
51
  output[0].to_sym
39
52
  end
40
53
 
54
+ private
55
+
41
56
  def command(file_path)
42
57
  "/usr/local/bin/analyzer --outf ident --fidn #{ident} -f #{config} < #{file_path}"
43
58
  end
@@ -0,0 +1,18 @@
1
+ module FreelingClient
2
+ class Token
3
+
4
+ attr_accessor :form, :lemma, :tag, :prob, :pos
5
+
6
+ def initialize(opt = {})
7
+ @form = opt[:form]
8
+ @lemma = opt[:lemma]
9
+ @tag = opt[:tag]
10
+ @prob = opt[:tag]
11
+ end
12
+
13
+ def [](key)
14
+ key = key.to_sym if key.is_a? String
15
+ self.send(key)
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module FreelingClient
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require "tempfile"
2
2
  require "freeling_client/version"
3
+ require "freeling_client/token"
3
4
  require "freeling_client/analyzer"
4
5
  require "freeling_client/client"
5
6
  require "freeling_client/language_detector"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freeling-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcos Vanetta
@@ -10,20 +10,6 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: hashie
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '3'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '3'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -85,6 +71,7 @@ files:
85
71
  - lib/freeling_client/base.rb
86
72
  - lib/freeling_client/client.rb
87
73
  - lib/freeling_client/language_detector.rb
74
+ - lib/freeling_client/token.rb
88
75
  - lib/freeling_client/version.rb
89
76
  - start-freeling.sh
90
77
  - test/lib/freeling_client_test.rb