tickerizer 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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tickerizer.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 jimmayes
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,53 @@
1
+ # Tickerizer
2
+
3
+ Tickerizer extracts company names and stock symbols from content strings.
4
+
5
+ ## Requirements
6
+
7
+ An OpenCalais account is required to make use of this gem. Create your account and request an API key at http://www.opencalais.com/APIkey
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+ ```
13
+ gem 'tickerizer'
14
+ ```
15
+
16
+ And then execute:
17
+ ```
18
+ $ bundle
19
+ ```
20
+
21
+ Or install it yourself as:
22
+ ```
23
+ $ gem install tickerizer
24
+ ```
25
+
26
+ ## Configuration
27
+ Provide your OenCalais API Key in familiar config block fashion
28
+ ```ruby
29
+ Tickerizer.configure do |config|
30
+ config.license_id = 'YOUR_API_KEY_HERE'
31
+ end
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ ### Extracting Company Information
37
+
38
+ Provide a string of content to Tickerizer's extract method and it will return any array containing the company references found ordered by their semantic relevance to the content string
39
+
40
+ ```ruby
41
+ content = "Ford CEO Alan Mulally is reportedly among the names being discussed by Microsoft's board of directors as a successor to Steve Ballmer, who'll be retiring within a year. Would such a move make sense for Microsoft?"
42
+
43
+ companies = Tickerizer.extract(content)
44
+
45
+ #=> [{:name=>"Microsoft", :relevance=>0.667, :ticker=>"MSFT", :symbol=>"MSFT.OQ"}, {:name=>"Ford", :relevance=>0.476, :ticker=>"F", :symbol=>"F.N"}]
46
+ ```
47
+
48
+ It is therefore, non-trivial to retrieve a "primary ticker" (most relevant) for the provided content string
49
+
50
+ ```ruby
51
+ companies.first[:ticker]
52
+ #=> "MSFT"
53
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module Tickerizer
2
+ VERSION = "0.0.1"
3
+ end
data/lib/tickerizer.rb ADDED
@@ -0,0 +1,54 @@
1
+ require "tickerizer/version"
2
+
3
+ module Tickerizer
4
+ class Configuration
5
+ attr_accessor :license_id
6
+
7
+ def initialize
8
+ self.license_id = nil
9
+ end
10
+ end
11
+
12
+ def self.configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ def self.configure
17
+ yield(configuration) if block_given?
18
+ end
19
+
20
+ class << self
21
+ attr_accessor :license_id
22
+
23
+ def license_id
24
+ raise "OpenCalais License ID is required" unless @license_id
25
+ @license_id
26
+ end
27
+ end
28
+
29
+ def self.extract(content)
30
+ resp = Calais.enlighten(
31
+ :content => content,
32
+ :content_type => :raw,
33
+ :output_format => :json,
34
+ :license_id => Tickerizer.configuration.license_id
35
+ )
36
+
37
+ self.process( JSON.parse(resp) )
38
+ end
39
+
40
+ def self.process(data)
41
+ companies = Array.new
42
+
43
+ data.each do |node|
44
+ if node[1]["_type"] == "Company"
45
+ company = {:name => node[1]["name"], :relevance => node[1]["relevance"].to_f}
46
+ company[:ticker] = node[1]["resolutions"][0]["ticker"] if node[1]["resolutions"]
47
+
48
+ companies << company
49
+ end
50
+ end
51
+
52
+ companies.sort_by{|company| company[:relevance]}.reverse!
53
+ end
54
+ end
@@ -0,0 +1,9 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ #
8
+ require 'Tickerizer'
9
+ require 'json'
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tickerizer do
4
+ context "has a response" do
5
+ # Test parser against expected format
6
+
7
+ # example OpenCalais response for "Google, Inc"
8
+ data = JSON.parse("{\"doc\":{\"info\":{\"calaisRequestID\":\"4a3565f4-4180-e419-1419-02b26a32c0b3\",\"id\":\"http://id.opencalais.com/LvyWK4U7P6xyJEGM1u9mew\",\"docId\":\"http://d.opencalais.com/dochash-1/835e8fef-a4e4-3b91-89af-6060372f215b\",\"document\":\"Google, Inc\",\"docTitle\":\"\",\"docDate\":\"2013-10-06 18:47:29.169\"},\"meta\":{\"contentType\":\"text/raw\",\"emVer\":\"7.1.1103.5\",\"langIdVer\":\"DefaultLangId\",\"processingVer\":\"CalaisJob01\",\"submissionDate\":\"2013-10-06 18:47:29.059\",\"submitterCode\":\"8ff5522d-bcb1-c039-11e2-4512df0dcbd9\",\"signature\":\"digestalg-1|6cRb/b8lNBNmGWvmnJfUzVqYEGg=|EqIXLG3DYFkjtLYC8Ga1ILuTHmN/i06L+DVAHC4mRPxXJGlzcB8ARQ==\",\"language\":\"InputTextTooShort\"}},\"http://d.opencalais.com/dochash-1/835e8fef-a4e4-3b91-89af-6060372f215b/lid/DefaultLangId\":{\"_typeGroup\":\"language\",\"language\":\"http://d.opencalais.com/lid/DefaultLangId/InputTextTooShort\"},\"http://d.opencalais.com/comphash-1/230b96d5-1757-3e7f-8e8b-e81f7861a91a\":{\"_typeGroup\":\"entities\",\"_type\":\"Company\",\"name\":\"Google Inc\",\"nationality\":\"N/A\",\"_typeReference\":\"http://s.opencalais.com/1/type/em/e/Company\",\"instances\":[{\"detection\":\"[]Google, Inc[]\",\"exact\":\"Google, Inc\",\"offset\":0,\"length\":11}],\"relevance\":0.857,\"resolutions\":[{\"id\":\"http://d.opencalais.com/er/company/ralg-tr1r/ce181d44-1915-3387-83da-0dc4ec01c6da\",\"score\":1,\"name\":\"GOOGLE INC.\",\"shortname\":\"Google\",\"ticker\":\"GOOG\",\"symbol\":\"GOOG.OQ\"}]}}")
9
+
10
+ it "should retrieve company name" do
11
+ name = Tickerizer.process( data ).first[:name]
12
+
13
+ name.should eq("Google Inc")
14
+ end
15
+
16
+ it "should retrieve a relevance score" do
17
+ relevance = Tickerizer.process( data ).first[:relevance]
18
+
19
+ relevance.should eq(0.857)
20
+ end
21
+
22
+ it "should retrieve stock ticker" do
23
+ ticker = Tickerizer.process( data ).first[:ticker]
24
+
25
+ ticker.should eq("GOOG")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/tickerizer/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["jimmayes"]
6
+ gem.email = ["jim.mayes@gmail.com"]
7
+ gem.description = %q{Parses content and extras stock tickers for companies mentioned}
8
+ gem.summary = %q{Parse content for stock tickers}
9
+ gem.homepage = ""
10
+
11
+ gem.add_dependency "calais"
12
+ gem.add_dependency "json"
13
+
14
+ gem.add_development_dependency "rspec"
15
+
16
+ gem.files = `git ls-files`.split($\)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.name = "tickerizer"
20
+ gem.require_paths = ["lib"]
21
+ gem.version = Tickerizer::VERSION
22
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tickerizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - jimmayes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: calais
16
+ requirement: &70175413746700 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70175413746700
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ requirement: &70175413750400 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70175413750400
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70175413726720 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70175413726720
47
+ description: Parses content and extras stock tickers for companies mentioned
48
+ email:
49
+ - jim.mayes@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rspec
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - lib/tickerizer.rb
61
+ - lib/tickerizer/version.rb
62
+ - spec/spec_helper.rb
63
+ - spec/tickerizer_spec.rb
64
+ - tickerizer.gemspec
65
+ homepage: ''
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.10
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Parse content for stock tickers
89
+ test_files:
90
+ - spec/spec_helper.rb
91
+ - spec/tickerizer_spec.rb