jakal 0.0.8 → 0.0.9
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/features/calais.feature
CHANGED
@@ -17,6 +17,12 @@ Feature: Calais-Specific features
|
|
17
17
|
Then I should get a response
|
18
18
|
And I should receive some tags
|
19
19
|
|
20
|
+
@connection_needed
|
21
|
+
Scenario: Get nested tags from calais
|
22
|
+
Given I have some simple text
|
23
|
+
When I request the nested entities from calais
|
24
|
+
Then I should get a decent response
|
25
|
+
|
20
26
|
Scenario: Clean up blank items from a calais response
|
21
27
|
Given I have a mock calais response
|
22
28
|
When I remove the unwanted items
|
@@ -35,4 +41,3 @@ Feature: Calais-Specific features
|
|
35
41
|
Scenario: Go through the calais response tags as a single array
|
36
42
|
Given I have a mock calais response
|
37
43
|
Then I should be able to see the whole lot of tags as one block
|
38
|
-
|
@@ -42,3 +42,11 @@ Then /^I should be able to see the whole lot of tags as one block$/ do
|
|
42
42
|
tags.length.should > 0
|
43
43
|
end
|
44
44
|
|
45
|
+
When /^I request the nested entities from calais$/ do
|
46
|
+
key = YAML::load_file('config/keys.yml')['calais']
|
47
|
+
@response = Jkl::get_calais_metadata key, @text
|
48
|
+
end
|
49
|
+
|
50
|
+
Then /^I should get a decent response$/ do
|
51
|
+
@response.eql?({"Person"=>["Barack Obama", "Hillary Clinton"], "Position"=>["Secretary of State"]}).should == true
|
52
|
+
end
|
data/lib/jkl/calais_client.rb
CHANGED
@@ -29,10 +29,11 @@ module Jkl
|
|
29
29
|
cleaned_result
|
30
30
|
end
|
31
31
|
|
32
|
-
def self.get_calais_metadata(
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def self.get_calais_metadata(key, text)
|
33
|
+
name_value_pairs = Jkl::tags(key, text).entities.map{|e| {e.type => [e.attributes["name"]]}}
|
34
|
+
nested_list = {}
|
35
|
+
name_value_pairs.each { |a| nested_list = nested_list.merge!(a){ |key,v1,v2| v1+v2 }}
|
36
|
+
nested_list
|
36
37
|
end
|
37
38
|
|
38
39
|
#jkl doesn't work with these aspects of the calais response, also removing blanks
|