lib/calais/response.rb in calais-0.0.6 vs lib/calais/response.rb in calais-0.0.7

- old
+ new

@@ -27,19 +27,19 @@ extract_data end class Entity - attr_accessor :hash, :type, :attributes, :relevance, :instances + attr_accessor :calais_hash, :type, :attributes, :relevance, :instances end class Relation - attr_accessor :hash, :type, :attributes, :instances + attr_accessor :calais_hash, :type, :attributes, :instances end class Geography - attr_accessor :name, :hash, :attributes + attr_accessor :name, :calais_hash, :attributes end class Category attr_accessor :name, :score end @@ -76,10 +76,14 @@ private def extract_data doc = XML::Parser.string(@raw_response).parse + if doc.root.find("/Error").first + raise Calais::Error, doc.root.find("/Error/Exception").first.content + end + doc.root.find("rdf:Description/rdf:type[contains(@rdf:resource, '#{MATCHERS[:docinfometa]}')]/..").each do |node| @language = node['language'] @submission_date = DateTime.parse node['submissionDate'] attributes = extract_attributes(node.find("*[contains(name(), 'c:')]")) @@ -102,11 +106,12 @@ end @categories = doc.root.find("rdf:Description/rdf:type[contains(@rdf:resource, '#{MATCHERS[:doccat]}')]/..").map do |node| category = Category.new category.name = node.find_first("c:categoryName").content - category.score = node.find_first("c:score").content.to_f + score = node.find_first("c:score") + category.score = score.content.to_f unless score.nil? node.remove! category end @@ -120,11 +125,11 @@ @entities = doc.root.find("rdf:Description/rdf:type[contains(@rdf:resource, '#{MATCHERS[:entities]}')]/..").map do |node| extracted_hash = node['about'].split('/')[-1] rescue nil entity = Entity.new - entity.hash = CalaisHash.find_or_create(extracted_hash, @hashes) + entity.calais_hash = CalaisHash.find_or_create(extracted_hash, @hashes) entity.type = extract_type(node) entity.attributes = extract_attributes(node.find("*[contains(name(), 'c:')]")) entity.relevance = @relevances[extracted_hash] entity.instances = extract_instances(doc, extracted_hash) @@ -135,11 +140,11 @@ @relations = doc.root.find("rdf:Description/rdf:type[contains(@rdf:resource, '#{MATCHERS[:relations]}')]/..").map do |node| extracted_hash = node['about'].split('/')[-1] rescue nil relation = Relation.new - relation.hash = CalaisHash.find_or_create(extracted_hash, @hashes) + relation.calais_hash = CalaisHash.find_or_create(extracted_hash, @hashes) relation.type = extract_type(node) relation.attributes = extract_attributes(node.find("*[contains(name(), 'c:')]")) relation.instances = extract_instances(doc, extracted_hash) node.remove! @@ -149,10 +154,10 @@ @geographies = doc.root.find("rdf:Description/rdf:type[contains(@rdf:resource, '#{MATCHERS[:geographies]}')]/..").map do |node| attributes = extract_attributes(node.find("*[contains(name(), 'c:')]")) geography = Geography.new geography.name = attributes.delete('name') - geography.hash = attributes.delete('subject') + geography.calais_hash = attributes.delete('subject') geography.attributes = attributes node.remove! geography end \ No newline at end of file