timbl_client 0.0.1

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.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2010 Bjørn Arild Mæland
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
data/README ADDED
@@ -0,0 +1,15 @@
1
+ timbl_client
2
+ ============
3
+ A bare-bones client for TimblServer. For more information, consult
4
+ http://ilk.uvt.nl/timbl/ and/or
5
+ http://ilk.uvt.nl/downloads/pub/papers/TimblServer_1.0_Manual.pdf.
6
+
7
+ Installation
8
+ ============
9
+ gem install timbl_client
10
+
11
+ There are no dependencies.
12
+
13
+ Copyright
14
+ =========
15
+ Copyright (c) 2010 Bjørn Arild Mæland. See LICENSE for details.
@@ -0,0 +1,47 @@
1
+ require "socket"
2
+
3
+ class TimblClient
4
+
5
+ attr_reader :socket
6
+
7
+ def initialize(host="localhost", port=6060)
8
+ @host = host
9
+ @port = port
10
+ @socket = nil
11
+ connect
12
+ end
13
+
14
+ # Open the socket
15
+ def connect
16
+ @socket = TCPSocket.open(@host, @port)
17
+ @socket.gets # consumes the welcome msg
18
+ end
19
+
20
+ def classify(request)
21
+ #connect unless connected?
22
+ @socket.send(format_request(request), 0)
23
+ format_response(@socket.recv(1024))
24
+ end
25
+ alias :tag :classify
26
+
27
+ def format_request(request)
28
+ request = "c " + request unless request.start_with?("c ")
29
+ request.chomp + "\n"
30
+ end
31
+
32
+ # Turns the Timbl response into a more familiar Ruby-hash.
33
+ # E.g. the response 'CATEGORY {0}\n' is converted to {:category => "0"}
34
+ def format_response(response)
35
+ response.scan(/([A-Z]+) \{ ?(.*?) ?\}/).inject({}) do |res, e|
36
+ res[e[0].downcase.to_sym] = e[1]
37
+ res
38
+ end
39
+ end
40
+
41
+ def disconnect
42
+ @socket.send("exit\n", 0)
43
+ @socket.close
44
+ end
45
+ alias :close :disconnect
46
+
47
+ end
@@ -0,0 +1,28 @@
1
+ require "rspec-expectations"
2
+ require "mocha"
3
+ include Mocha::API
4
+
5
+ require "timbl_client"
6
+
7
+ describe TimblClient do
8
+
9
+ before(:all) do
10
+ socket = stub(:gets => nil)
11
+ TCPSocket.expects(:open).returns(socket)
12
+ @client = TimblClient.new
13
+ end
14
+
15
+ it "should convert the server response to a hash" do
16
+ response = "ERROR { The following feature(s) have only 1 value: 2 }\n" +
17
+ "CATEGORY {1}\n"
18
+ @client.format_response(response).should == {
19
+ :error => "The following feature(s) have only 1 value: 2",
20
+ :category => "1"
21
+ }
22
+
23
+ @client.format_response("CATEGORY {0}\n").should == {
24
+ :category => "0"
25
+ }
26
+ end
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timbl_client
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - "Bj\xC3\xB8rn Arild M\xC3\xA6land"
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-22 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec-expectations
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: mocha
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: timbl_client is a Ruby client for interacting with TimblServer.
47
+ email: bjorn.maeland@gmail.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files: []
53
+
54
+ files:
55
+ - README
56
+ - LICENSE
57
+ - lib/timbl_client.rb
58
+ - spec/timbl_client_spec.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/bmaland/timbl_client
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options: []
65
+
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project: timbl_client
87
+ rubygems_version: 1.3.7
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: timbl_client is a Ruby client for interacting with TimblServer.
91
+ test_files:
92
+ - spec/timbl_client_spec.rb