Skip to content

Instantly share code, notes, and snippets.

@RedFred7
Last active Dec 25, 2015
Embed
What would you like to do?
Using DoverToCalais to semantically tag all files in a directory
require 'dover_to_calais'
EM.run do
# use Control + C to stop the EM
Signal.trap('INT') { EventMachine.stop }
Signal.trap('TERM') { EventMachine.stop }
DoverToCalais::API_KEY = 'my_opencalais_key'
directory = '/home/fred/Documents/'
#create a list of all our documents as Dover objects
dovers = []
Dir.foreach(directory) do |filename|
next if filename == '.' or filename == '..'
dovers << DoverToCalais::Dover.new(directory + '/' + filename)
end
#set callbacks for each dover
dovers.each do |dover|
dover.to_calais do |response|
puts "----------------------------------------"
if response.error
puts "Data source #{dover.data_src} -error: #{response.error}"
else
puts "Data source #{dover.data_src}: #{response}"
end #if
end #block
end #each
#analyse our dovers
dovers.each do |dover|
dover.analyse_this
end
end #EM run
@RedFred7
Copy link
Author

RedFred7 commented Feb 11, 2014

updated gist for dover_ro_calais-0.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment