Created
October 17, 2011 18:00
-
-
Save emckean/1293297 to your computer and use it in GitHub Desktop.
This file contains 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
require 'wordnik' | |
%w(rubygems wordnik).each {|lib| require lib} | |
Wordnik.configure do |config| | |
config.api_key = '' | |
config.response_format = 'xml' | |
end | |
#unless ARGV.length == 2 | |
# puts "Usage: need two files: input and output file" | |
# exit | |
#end | |
#read in glossary terms file -- get rid of newlines | |
glossary_terms = File.open(ARGV[0]).readlines.collect do | line | | |
line.chomp | |
end | |
#foreach term in file, grab entries via Wordnik API | |
glossary_terms.each do | line | | |
# puts line | |
entry = Wordnik.word.get_entries("#{line}", :tags => 'true', :etymologies => 'true').chomp | |
examples = Wordnik.word.get_examples("#{line}", :includeDuplicates => 'false', :contentProvider => 'wsj', :limit => 10).chomp | |
if entry == '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><entries></entries>' && examples == '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><exampleSearchResults/>' | |
puts "#{line} no entry no examples" | |
else | |
puts entry | |
puts examples | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment