-
-
Save jacqui/c98f6743c771e46ba18c to your computer and use it in GitHub Desktop.
quick hack to pull concepts, keywords or entities out of any url using AlchemyAPI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# USAGE: | |
# | |
# ./alc [action] [url] | |
# ex: | |
# ./alc keyword http://www.bbc.co.uk/news/magazine-31556802 | |
# ./alc concept http://www.bbc.co.uk/news/magazine-31556802 | |
# ./alc entity http://www.bbc.co.uk/news/magazine-31556802 | |
# | |
# Returns the top 10 of each | |
require 'json' | |
require 'open-uri' | |
require 'cgi' | |
if ARGV[0] == 'concept' | |
alc_url = "http://access.alchemyapi.com/calls/url/URLGetRankedConcepts?apikey=a803288dc1c31d49824b2b88b5f9aaa0d438f2e5&url=#{CGI::escape(ARGV[1])}&outputMode=json" | |
puts alc_url | |
puts JSON.parse(open(alc_url).read)["concepts"].first(10).map{|c| c["text"] } | |
elsif ARGV[0] == 'keyword' | |
alc_url = "http://access.alchemyapi.com/calls/url/URLGetRankedKeywords?apikey=a803288dc1c31d49824b2b88b5f9aaa0d438f2e5&url=#{CGI::escape(ARGV[1])}&outputMode=json" | |
puts alc_url | |
puts JSON.parse(open(alc_url).read)["keywords"].first(10).map{|c| c["text"] } | |
elsif ARGV[0] == 'entity' | |
alc_url = "http://access.alchemyapi.com/calls/url/URLGetRankedNamedEntities?apikey=a803288dc1c31d49824b2b88b5f9aaa0d438f2e5&url=#{CGI::escape(ARGV[1])}&outputMode=json" | |
puts alc_url | |
puts JSON.parse(open(alc_url).read)["entities"].first(10).map{|c| "#{c['type']}: #{c['text']}" } | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment