calais 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +5 -0
- data/Manifest.txt +1 -0
- data/init.rb +1 -0
- data/lib/calais.rb +1 -1
- data/lib/calais/name.rb +14 -0
- data/lib/calais/response.rb +6 -0
- data/spec/calais_spec.rb +40 -2
- data/spec/fixtures/bicycles_austrailia.xml +1 -1
- metadata +2 -1
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/lib/calais'
|
data/lib/calais.rb
CHANGED
data/lib/calais/name.rb
CHANGED
@@ -2,6 +2,20 @@ module Calais
|
|
2
2
|
class Name
|
3
3
|
attr_accessor :name, :type, :hash, :locations
|
4
4
|
|
5
|
+
TYPES = {
|
6
|
+
"cities" => "City",
|
7
|
+
"companies" => "Company",
|
8
|
+
"continents" => "Continent",
|
9
|
+
"countries" => "Country",
|
10
|
+
"industry_terms" => "IndustryTerm",
|
11
|
+
"money_amounts" => "MoneyAmount",
|
12
|
+
"organizations" => "Organization",
|
13
|
+
"people" => "Person",
|
14
|
+
"provinces_and_states" => "ProvinceOrState",
|
15
|
+
"regions" => "Region",
|
16
|
+
"urls" => "URL"
|
17
|
+
}
|
18
|
+
|
5
19
|
def initialize(args={})
|
6
20
|
args.each {|k,v| send("#{k}=", v)}
|
7
21
|
end
|
data/lib/calais/response.rb
CHANGED
@@ -18,6 +18,12 @@ module Calais
|
|
18
18
|
h_doc = parse_relationships(h_doc)
|
19
19
|
end
|
20
20
|
|
21
|
+
Name::TYPES.each_pair do |method_name, type|
|
22
|
+
define_method method_name.to_sym do
|
23
|
+
@names.map {|name| name if name.type == type }.compact
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
21
27
|
private
|
22
28
|
def parse_rdf(raw)
|
23
29
|
@rdf = CGI::unescapeHTML Hpricot.XML(raw).at("/string").inner_html
|
data/spec/calais_spec.rb
CHANGED
@@ -46,7 +46,7 @@ describe Calais, ".process_document" do
|
|
46
46
|
it "returns names" do
|
47
47
|
@response.names.should_not be_nil
|
48
48
|
@response.names.should_not be_empty
|
49
|
-
@response.names.map {|n| n.name }.sort.should == ["Australia", "Australia", "Cycling Promotion Fund", "Ian Christie", "car manufacturers", "car market", "car sales", "company car"]
|
49
|
+
@response.names.map {|n| n.name }.sort.should == ["Australia", "Australia", "Cycling Promotion Fund", "Hobart", "Ian Christie", "Tasmania", "car manufacturers", "car market", "car sales", "company car"]
|
50
50
|
end
|
51
51
|
|
52
52
|
it "returns relationships" do
|
@@ -75,6 +75,44 @@ describe Calais::Client, ".params_xml" do
|
|
75
75
|
it "returns an xml encoded string" do
|
76
76
|
client = Calais::Client.new(:content => SAMPLE_DOCUMENT, :content_type => :xml, :license_id => LICENSE_ID)
|
77
77
|
client.send("params_xml").should_not be_nil
|
78
|
-
client.send("params_xml").should == %[<c:params xmlns:c=\"http://s.opencalais.com/1/pred/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"><c:processingDirectives c:contentType=\"TEXT/XML\" c:outputFormat=\"XML/RDF\"></c:processingDirectives><c:userDirectives c:allowDistribution=\"false\" c:allowSearch=\"false\" c:externalID=\"
|
78
|
+
client.send("params_xml").should == %[<c:params xmlns:c=\"http://s.opencalais.com/1/pred/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"><c:processingDirectives c:contentType=\"TEXT/XML\" c:outputFormat=\"XML/RDF\"></c:processingDirectives><c:userDirectives c:allowDistribution=\"false\" c:allowSearch=\"false\" c:externalID=\"f14fd3588ba6bfb91a9294240d2d081cfbdc079c\" c:submitter=\"calais.rb\"></c:userDirectives><c:externalMetadata></c:externalMetadata></c:params>]
|
79
79
|
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "a Calais response, @response" do
|
83
|
+
before(:all) do
|
84
|
+
@response = Calais.process_document(:content => SAMPLE_DOCUMENT, :content_type => :xml, :license_id => LICENSE_ID)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "returns a list of the people Calais identified (@response.people)" do
|
88
|
+
@response.people.should_not be_nil
|
89
|
+
@response.people.should have(1).people
|
90
|
+
@response.people.first.name.should == "Ian Christie"
|
91
|
+
end
|
92
|
+
|
93
|
+
it "returns a list of the organizations Calais identified (@response.organizations)" do
|
94
|
+
@response.organizations.should_not be_nil
|
95
|
+
@response.should have(1).organizations
|
96
|
+
@response.organizations.first.name.should == "Cycling Promotion Fund"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "returns a list of the provinces and states Calais identified (@response.provinces_and_states)" do
|
100
|
+
@response.provinces_and_states.should_not be_nil
|
101
|
+
@response.should have(1).provinces_and_states
|
102
|
+
@response.provinces_and_states.first.name.should == "Tasmania"
|
103
|
+
end
|
104
|
+
|
105
|
+
it "returns a list of the cities Calais identified (@response.cities)" do
|
106
|
+
@response.cities.should_not be_nil
|
107
|
+
@response.should have(1).cities
|
108
|
+
@response.cities.first.name.should == "Hobart"
|
109
|
+
end
|
110
|
+
|
111
|
+
it "returns a list of the countries Calais identified (@response.countries)" do
|
112
|
+
@response.countries.should_not be_nil
|
113
|
+
@response.should have(1).countries
|
114
|
+
@response.countries.first.name.should == "Australia"
|
115
|
+
end
|
116
|
+
|
117
|
+
|
80
118
|
end
|
@@ -7,7 +7,7 @@ Bicycle sales in Australia have recorded record sales of 1,273,781 units for 200
|
|
7
7
|
|
8
8
|
The Cycling Promotion Fund (CPF) spokesman Ian Christie said Australians were increasingly using bicycles as an alternative to cars. Sales rose nine percent in 2006 while the car market stalled. Mr Christie said people were looking to cut their fuel costs and improve their fitness.
|
9
9
|
|
10
|
-
Mr Christie said organisations were beginning to supply bicycles as a company vehicle. "There is an emerging trend towards people using bikes as their official company-supplied vehicle in place of the traditional company car," he said.
|
10
|
+
Mr Christie, a native of Hobart, Tasmania said organisations were beginning to supply bicycles as a company vehicle. "There is an emerging trend towards people using bikes as their official company-supplied vehicle in place of the traditional company car," he said.
|
11
11
|
|
12
12
|
"Some of Australia's biggest corporations now have bicycle fleets, and when you add in government organisations, we now know of at least 50 organisations which operate fleets of bikes."
|
13
13
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calais
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abhay Kumar
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- Manifest.txt
|
59
59
|
- README.txt
|
60
60
|
- Rakefile
|
61
|
+
- init.rb
|
61
62
|
- lib/calais.rb
|
62
63
|
- lib/calais/client.rb
|
63
64
|
- lib/calais/name.rb
|
metadata.gz.sig
CHANGED
Binary file
|