lib/calais/response.rb in calais-0.0.9 vs lib/calais/response.rb in calais-0.0.10

- old
+ new

@@ -11,22 +11,23 @@ :instances => 'type/sys/InstanceInfo', :relevances => 'type/sys/RelevanceInfo', } attr_accessor :submitter_code, :signature, :language, :submission_date, :request_id, :doc_title, :doc_date - attr_accessor :hashes, :entities, :relations, :geographies, :categories + attr_accessor :hashes, :entities, :relations, :geographies, :categories, :socialtags def initialize(rdf_string) @raw_response = rdf_string @hashes = [] @entities = [] @relations = [] @geographies = [] @relevances = {} # key = String hash, val = Float relevance @categories = [] - + @socialtags = [] + extract_data end class Entity attr_accessor :calais_hash, :type, :attributes, :relevance, :instances @@ -42,10 +43,14 @@ class Category attr_accessor :name, :score end + class SocailTag + attr_accessor :name, :importance + end + class Instance attr_accessor :prefix, :exact, :suffix, :offset, :length # Makes a new Instance object from an appropriate Nokogiri::XML::Node. def self.from_node(node) @@ -101,9 +106,19 @@ @doc_title = attributes.delete('docTitle') @doc_date = Date.parse(attributes.delete('docDate')) node.remove + end + + @socialtags = doc.root.xpath("rdf:Description/c:socialtag/..").map do |node| + tag = SocailTag.new + tag.name = node.xpath("c:name[1]").first.content + tag.importance = node.xpath("c:importance[1]").first.content.to_i + + node.remove if node.xpath("c:categoryName[1]").first.nil? + + tag end @categories = doc.root.xpath("rdf:Description/rdf:type[contains(@rdf:resource, '#{MATCHERS[:doccat]}')]/..").map do |node| category = Category.new category.name = node.xpath("c:categoryName[1]").first.content \ No newline at end of file