opener-client 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8224c6b41577a334b81e3a324b806f7a15bddaef
4
+ data.tar.gz: 82d9f14ad375997975f519f269fd91c95cf97362
5
+ SHA512:
6
+ metadata.gz: c5bb6aaf1656e8851f2c680930f985ea00a5bcd37daac94fa91f8c3e11a54ff7c7802278381f1b192a4118eb6103bbef83918e6eade7208cfbbc10ec3df35b2d
7
+ data.tar.gz: 0f962edc4afa1422f341032158b9e89739d4511316643c4ac7c2e583cc4bae4e76e9c99a777928ee22dfb8228c143532e4ba43976505a871f4370598b7f42da7
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Wilco van Duinkerken
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Opener::Client
2
+
3
+ This is a ruby library that makes it very easy to connect to OpeNER webservices
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'opener-client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install opener-client
18
+
19
+ ## Usage
20
+
21
+ You have to create your own OpeNER pipeline. You can do this like this:
22
+
23
+ ```ruby
24
+ require 'opener/client'
25
+
26
+ class Basic < Opener::Client::Pipeline
27
+ # Define your processors. The order matters.
28
+ define_processors "language-identifier",
29
+ "tokenizer",
30
+ "pos-tagger",
31
+ "polarity-tagger",
32
+ "ner",
33
+ "opinion-detector"
34
+
35
+ # Defaults to :async, the other option is :sync
36
+ processor_style :async
37
+
38
+ webservice_host "http://opener.olery.com"
39
+ end
40
+ ```
41
+
42
+ That's it basically. You can now process files like this:
43
+
44
+ ```ruby
45
+ pipeline = Basic.new
46
+ response = pipeline.process("This is the text to analyse")
47
+ ```
48
+
49
+ By default the async callback chain is used. So the response will contain
50
+ an output url where you can find your output after a few seconds.
51
+
52
+ Check out the examples folder in this repository for a more extensive example.
53
+
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
@@ -0,0 +1,17 @@
1
+ require 'nokogiri'
2
+ require 'active_support/inflector'
3
+ require 'httpclient'
4
+
5
+ require "opener/client/version"
6
+
7
+ require 'opener/client/processor'
8
+ require 'opener/client/processor_definer'
9
+ require 'opener/client/processors/language_identifier'
10
+ require 'opener/client/processors/tokenizer'
11
+
12
+ require 'opener/client/pipeline'
13
+
14
+ module Opener
15
+ module Client
16
+ end
17
+ end
@@ -0,0 +1,51 @@
1
+ require 'json'
2
+
3
+ module Opener
4
+ module Client
5
+ class Pipeline
6
+ include ProcessorDefiner
7
+ include Processors
8
+
9
+ def self.processor_style(style)
10
+ @@style = style
11
+ end
12
+
13
+ def self.webservice_host(host=nil)
14
+ @@host = host
15
+ end
16
+
17
+ def self.outlet(outlet)
18
+ @@outlet = outlet
19
+ end
20
+
21
+ def pipe
22
+ @pipe ||= self.class.processors.map{|p| p.new(@@host)}
23
+ end
24
+
25
+ def process_sync(input)
26
+ pipe.inject(input) do |memo, pipe|
27
+ memo = pipe.process(memo)
28
+ end
29
+ end
30
+
31
+ def process_async(input)
32
+ endpoints = pipe.map(&:endpoint)
33
+
34
+ callbacks = endpoints[1..-1]
35
+ callbacks << @@outlet
36
+
37
+ pipe[0].process(input, callbacks)
38
+ end
39
+
40
+ def process(input)
41
+ json_to_hash send(:"process_#{@@style}", input)
42
+ end
43
+
44
+ private
45
+
46
+ def json_to_hash(response)
47
+ JSON.parse(response)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,43 @@
1
+ module Opener
2
+ module Client
3
+ module Processor
4
+ attr_reader :host
5
+
6
+ def self.included(base)
7
+ base.extend ClassMethods
8
+ end
9
+
10
+ module ClassMethods
11
+ def processor(processor)
12
+ define_method "processor" do
13
+ return processor
14
+ end
15
+ end
16
+ end
17
+
18
+ def initialize(host)
19
+ @host = host
20
+ end
21
+
22
+ def process(input, callbacks=nil)
23
+ opts = {:input=>input}.merge(options)
24
+ opts[:'callbacks[]'] = callbacks unless callbacks.nil?
25
+
26
+ response = HTTPClient.post(endpoint, opts)
27
+ if response.status == 500
28
+ raise "Internal Server error in: #{self.class.name}, #{response.body}"
29
+ else
30
+ return response.body
31
+ end
32
+ end
33
+
34
+ def endpoint
35
+ [host, processor].join("/")
36
+ end
37
+
38
+ def options
39
+ {}
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,45 @@
1
+ module Opener
2
+ module Client
3
+ module ProcessorDefiner
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ @@processors = []
10
+
11
+ def add_processor(processor)
12
+ @@processors << processor
13
+ end
14
+
15
+ def processors
16
+ @@processors
17
+ end
18
+
19
+ def define_processors(*paths)
20
+ paths.each do |p|
21
+ define_processor(p)
22
+ end
23
+ end
24
+
25
+ def define_processor(p)
26
+ klass_name = p.split("-").map(&:camelize).join
27
+
28
+ if !const_defined?(klass_name)
29
+ klass = const_set(klass_name,Class.new)
30
+ else
31
+ klass = const_get(klass_name)
32
+ end
33
+
34
+ klass.class_eval do
35
+ include Processor
36
+ processor p
37
+ end
38
+
39
+ self.add_processor klass
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,11 @@
1
+ module Opener
2
+ module Client
3
+ module Processors
4
+ class LanguageIdentifier
5
+ def options
6
+ {kaf: true}
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module Opener
2
+ module Client
3
+ class Tokenizer
4
+ def options
5
+ {kaf: false,
6
+ language: "en"}
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module Opener
2
+ module Client
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../lib/opener/client/version', __FILE__)
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "opener-client"
5
+ spec.version = Opener::Client::VERSION
6
+ spec.authors = ["Wilco van Duinkerken"]
7
+ spec.email = ["wilcovanduinkerken@olery.com"]
8
+ spec.summary = %q{A helper gem to make use of OpeNER webservices}
9
+ spec.description = spec.summary
10
+ spec.homepage = "http://opener-project.github.com"
11
+ spec.license = "MIT"
12
+
13
+ spec.files = Dir.glob([
14
+ 'lib/**/*',
15
+ 'LICENSE.txt',
16
+ '*.gemspec',
17
+ 'README.md'
18
+ ]).select { |file| File.file?(file) }
19
+
20
+ spec.add_dependency 'nokogiri'
21
+ spec.add_dependency 'activesupport'
22
+ spec.add_dependency 'httpclient'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opener-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Wilco van Duinkerken
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httpclient
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A helper gem to make use of OpeNER webservices
84
+ email:
85
+ - wilcovanduinkerken@olery.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE.txt
91
+ - README.md
92
+ - lib/opener/client.rb
93
+ - lib/opener/client/pipeline.rb
94
+ - lib/opener/client/processor.rb
95
+ - lib/opener/client/processor_definer.rb
96
+ - lib/opener/client/processors/language_identifier.rb
97
+ - lib/opener/client/processors/tokenizer.rb
98
+ - lib/opener/client/version.rb
99
+ - opener-webservice.gemspec
100
+ homepage: http://opener-project.github.com
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.2.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: A helper gem to make use of OpeNER webservices
124
+ test_files: []
125
+ has_rdoc: