burghers 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: defd1c5e3e6fb553ea3c2f86d99865c8f29bb888
4
+ data.tar.gz: b9f5a028a13e0deae8a439a86604ba7d235e8bfd
5
+ SHA512:
6
+ metadata.gz: ffccaf465da9168da37a664a30547537232dec026e09d136ad1047a74802939215da520ca768f28587884bfd3e434e575f62f088cdb9fc2ed35b24ada765467c
7
+ data.tar.gz: 313b260e7b743b4f5aeb3652378ea8e432a635dfb7ec14bfb5a7ae1bac6fb38c68f3bc1665dcb8f32e8b0963f23c9b14e063e7c2bddc1e7821cb8a18f3a60c29
@@ -0,0 +1,18 @@
1
+ docs
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p451
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in robostripper.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Brian Muller
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.
@@ -0,0 +1,46 @@
1
+ = Burghers : Gem for {OpenCalais}[http://www.opencalais.com]
2
+
3
+ Burghers is a Ruby gem for {Open Calais}[http://www.opencalais.com]. Unlike some of the other gems out there, Burghers {works with Ruby 2}[https://github.com/abhay/calais/pull/5] and does not {hardcode scores}[https://github.com/PRX/open_calais/blob/master/lib/open_calais/response.rb#L45] or {add arbitrary methods to Ruby's String class}[https://github.com/PRX/open_calais/blob/master/open_calais.gemspec#L28]. Also it's freakin small. And it will accept URL's!
4
+
5
+ == Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'burghers'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install burghers
18
+
19
+ == Usage
20
+
21
+ client = Burghers::Client.new("your api key")
22
+
23
+ # call enrich on client with text or html content - Burghers will figure out what the
24
+ # content type is automagically
25
+
26
+ # give some Text
27
+ content = "The government of the United Kingdom has given corporations like fast food chain McDonald's the right to award high school qualifications to employees who complete a company training program."
28
+ puts client.enrich(content).topics
29
+ => [{:name=>"Education", :score=>1.0}, {:name=>"Labor", :score=>0.952}, {:name=>"Business_Finance", :score=>0.875}, {:name=>"Politics", :score=>0.566}]
30
+
31
+ # give some HTML
32
+ content = "<html><body>The government of the United Kingdom has given corporations like fast food chain McDonald's the right to award high school qualifications to employees who complete a company training program.</html></body>"
33
+ puts client.enrich(content).topics
34
+ => [{:name=>"Education", :score=>1.0}, {:name=>"Labor", :score=>0.952}, {:name=>"Business_Finance", :score=>0.875}, {:name=>"Politics", :score=>0.566}]
35
+
36
+ # But wait, THERE'S MORE - you can give a url too:
37
+ content = "http://www.washingtonpost.com/lifestyle/style/rep-vance-mcallister-kissed-now-can-he-make-up-with-voters-after-the-scandal/2014/04/16/9a898fde-c57c-11e3-9f37-7ce307c56815_story.html"
38
+ puts client.enrich(content).topics
39
+ => [{:name=>"Politics", :score=>0.57}]
40
+
41
+ Responses to enrich will all respond to topics, tags, entities, and relations with the result from the API call.
42
+
43
+ == Documentation
44
+ Run:
45
+
46
+ bundle exec rake doc
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rdoc/task'
3
+
4
+ RDoc::Task.new("doc") { |rdoc|
5
+ rdoc.title = "Burghers - Yet another Open Calais gem"
6
+ rdoc.rdoc_dir = 'docs'
7
+ rdoc.rdoc_files.include('README.rdoc')
8
+ rdoc.rdoc_files.include('lib/**/*.rb')
9
+ }
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'burghers/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "burghers"
7
+ gem.version = Burghers::VERSION
8
+ gem.authors = ["Brian Muller"]
9
+ gem.email = ["bamuller@gmail.com"]
10
+ gem.description = %q{Use Open Calais. Easily.}
11
+ gem.summary = %q{Use Open Calais. Easily.}
12
+ gem.homepage = "https://github.com/bmuller/burghers"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+ gem.add_dependency("httparty", ">= 0.9.0")
19
+ gem.add_development_dependency("rake")
20
+ gem.add_development_dependency("rdoc")
21
+ end
@@ -0,0 +1,3 @@
1
+ require "burghers/version"
2
+ require "burghers/response"
3
+ require "burghers/client"
@@ -0,0 +1,37 @@
1
+ require 'httparty'
2
+
3
+ module Burghers
4
+ class Client
5
+ URI = "http://api.opencalais.com/tag/rs/enrich"
6
+
7
+ def initialize(license)
8
+ @license = license
9
+ end
10
+
11
+ def enrich(content, content_type=nil, headers = nil)
12
+ if content.start_with?('http://') or content.start_with?('https://')
13
+ content = HTTParty.get(content).body
14
+ content_type = "text/html"
15
+ end
16
+
17
+ if content_type.nil? and content.include?("<") and content.include(">")
18
+ content_type = "text/html"
19
+ elsif content_type.nil?
20
+ content_type = "text/raw"
21
+ end
22
+
23
+ headers = {
24
+ 'accept' => 'application/json',
25
+ 'x-calais-licenseID' => @license,
26
+ 'content-type' => content_type
27
+ }.merge(headers || {})
28
+
29
+ response = HTTParty.post(URI, :body => content, :headers => headers)
30
+ if response.code != 200
31
+ raise "Got response code of #{response.code}: #{response}"
32
+ end
33
+
34
+ Response.new response.parsed_response
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ module Burghers
2
+ class Response
3
+ attr_reader :topics, :tags, :entities, :raw
4
+
5
+ def initialize(json)
6
+ @raw = json
7
+
8
+ @topics = []
9
+ @tags = []
10
+ @entities = []
11
+ @relations = []
12
+
13
+ if @raw['doc']['meta']['language'] == "InputTextTooShort"
14
+ raise "Document too short to process."
15
+ end
16
+
17
+ @raw.each do |key, value|
18
+ case value["_typeGroup"]
19
+ when 'topics'
20
+ @topics << { name: value['categoryName'], score: value['score'].to_f }
21
+ when 'socialTag'
22
+ @tags << { name: value['name'], :score => value['importance'].to_f }
23
+ when 'entities'
24
+ @entities << value
25
+ when 'relations'
26
+ @relations << value
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Burghers
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: burghers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brian Muller
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.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.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Use Open Calais. Easily.
56
+ email:
57
+ - bamuller@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .ruby-version
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.rdoc
67
+ - Rakefile
68
+ - burghers.gemspec
69
+ - lib/burghers.rb
70
+ - lib/burghers/client.rb
71
+ - lib/burghers/response.rb
72
+ - lib/burghers/version.rb
73
+ homepage: https://github.com/bmuller/burghers
74
+ licenses: []
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Use Open Calais. Easily.
96
+ test_files: []