lib/jkl.rb in jakal-0.0.9 vs lib/jkl.rb in jakal-0.1.0
- old
+ new
@@ -4,45 +4,53 @@
require "jkl/calais_client.rb"
require "jkl/url_doc_handler.rb"
module Jkl
- def self.headlines(feed, keyphrase)
- get_from_as_xml "#{feed}#{keyphrase}"
- end
+ class << self
- def self.pages(headlines)
- items = get_items_from headlines
- descriptions = ""
- items.each do |item|
- descriptions << attribute_from(item, :description).gsub("<![CDATA[","").gsub("]]>","")
+ def headlines(feed, keyphrase)
+ get_from_as_xml "#{feed}#{keyphrase}"
end
- descriptions
- end
-
- def self.descriptions(headlines)
- items = get_items_from headlines
- descriptions = []
- items.each do |item|
- descriptions << attribute_from(item, :description).gsub("<![CDATA[","").gsub("]]>","")
+
+ def pages(headlines)
+ items = get_items_from headlines
+ descriptions = ""
+ items.each do |item|
+ descriptions << attribute_from(item, :description).gsub("<![CDATA[","").gsub("]]>","")
+ end
+ descriptions
end
- descriptions
- end
-
- def self.links(headlines)
- items = get_items_from headlines
- links = []
- items.each do |item|
- links << attribute_from(item, :link)
+
+ def descriptions(headlines)
+ items = get_items_from headlines
+ descriptions = []
+ items.each do |item|
+ descriptions << attribute_from(item, :description).gsub("<![CDATA[","").gsub("]]>","")
+ end
+ descriptions
end
- links
- end
- def self.tags(key, pages)
- Calais.process_document(
- :content => pages,
- :content_type => :text,
- :license_id => key
- )
+ def links(headlines)
+ items = get_items_from headlines
+ links = []
+ items.each do |item|
+ links << attribute_from(item, :link)
+ end
+ links
+ end
+
+ def tags(key, text)
+ nested_list = {}
+ entities(key,text).each do |a|
+ nested_list = nested_list.merge!(a){ |key,v1,v2| v1+v2 }
+ end
+ nested_list
+ end
+
+ def entities(key,text)
+ calais_response(key, text).entities.map{|e| {e.type => [e.attributes["name"]]}}
+ end
+
end
end