From 89de2bfea7bdcee94ab8373f8febbb62580bc727 Mon Sep 17 00:00:00 2001 From: fitz Date: Wed, 23 Jan 2013 16:42:54 +0100 Subject: [PATCH] Fixing namespace issues --- lib/calais/response.rb | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/calais/response.rb b/lib/calais/response.rb index 49db0fe..4f34d07 100644 --- a/lib/calais/response.rb +++ b/lib/calais/response.rb @@ -88,8 +88,8 @@ def extract_data end doc.root.xpath("rdf:Description/rdf:type[contains(@rdf:resource, '#{MATCHERS[:docinfometa]}')]/..").each do |node| - @language = node['language'] - @submission_date = DateTime.parse node['submissionDate'] + @language = node['c:language'] + @submission_date = DateTime.parse node['c:submissionDate'] attributes = extract_attributes(node.xpath("*[contains(name(), 'c:')]")) @@ -100,7 +100,7 @@ def extract_data end doc.root.xpath("rdf:Description/rdf:type[contains(@rdf:resource, '#{MATCHERS[:docinfo]}')]/..").each do |node| - @request_id = node['calaisRequestID'] + @request_id = node['c:calaisRequestID'] attributes = extract_attributes(node.xpath("*[contains(name(), 'c:')]")) @@ -131,16 +131,14 @@ def extract_data end @relevances = doc.root.xpath("rdf:Description/rdf:type[contains(@rdf:resource, '#{MATCHERS[:relevances]}')]/..").inject({}) do |acc, node| - subject_hash = node.xpath("c:subject[1]").first[:resource].split('/')[-1] + subject_hash = node.xpath("c:subject[1]").first["rdf:resource"].split('/')[-1] acc[subject_hash] = node.xpath("c:relevance[1]").first.content.to_f - node.remove acc end @entities = doc.root.xpath("rdf:Description/rdf:type[contains(@rdf:resource, '#{MATCHERS[:entities]}')]/..").map do |node| - extracted_hash = node['about'].split('/')[-1] rescue nil - + extracted_hash = node['rdf:about'].split('/')[-1] rescue nil entity = Entity.new entity.calais_hash = CalaisHash.find_or_create(extracted_hash, @hashes) entity.type = extract_type(node) @@ -154,7 +152,7 @@ def extract_data end @relations = doc.root.xpath("rdf:Description/rdf:type[contains(@rdf:resource, '#{MATCHERS[:relations]}')]/..").map do |node| - extracted_hash = node['about'].split('/')[-1] rescue nil + extracted_hash = node['rdf:about'].split('/')[-1] rescue nil relation = Relation.new relation.calais_hash = CalaisHash.find_or_create(extracted_hash, @hashes) @@ -168,7 +166,6 @@ def extract_data @geographies = doc.root.xpath("rdf:Description/rdf:type[contains(@rdf:resource, '#{MATCHERS[:geographies]}')]/..").map do |node| attributes = extract_attributes(node.xpath("*[contains(name(), 'c:')]")) - geography = Geography.new geography.name = attributes.delete('name') geography.calais_hash = attributes.delete('subject') @@ -187,25 +184,24 @@ def extract_data def extract_instances(doc, hash) doc.root.xpath("rdf:Description/rdf:type[contains(@rdf:resource, '#{MATCHERS[:instances]}')]/..").select do |instance_node| - instance_node.xpath("c:subject[1]").first[:resource].split("/")[-1] == hash + instance_node.xpath("c:subject[1]").first["rdf:resource"].split("/")[-1] == hash end.map do |instance_node| instance = Instance.from_node(instance_node) instance_node.remove - instance end end def extract_type(node) - node.xpath("*[name()='rdf:type']")[0]['resource'].split('/')[-1] + node.xpath("*[name()='rdf:type']")[0]['rdf:resource'].split('/')[-1] rescue nil end def extract_attributes(nodes) nodes.inject({}) do |hsh, node| - value = if node['resource'] - extracted_hash = node['resource'].split('/')[-1] rescue nil + value = if node['rdf:resource'] + extracted_hash = node['rdf:resource'].split('/')[-1] rescue nil CalaisHash.find_or_create(extracted_hash, @hashes) else node.content