Created
December 8, 2014 23:23
-
-
Save hkparker/c7419b6a7e0dde6b9d78 to your computer and use it in GitHub Desktop.
Ruby script to determine part of speech of a word
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 | |
require 'httpclient' | |
require 'nokogiri' | |
def part_of_speech(word) | |
parts_of_speech = [] | |
client = HTTPClient.new | |
body = client.get("http://dictionary.reference.com/browse/#{word}?s=t").body | |
structure = Nokogiri::HTML(body) | |
structure.xpath("//div[contains(@class,'def-list')]").search(".dbox-pg").each do |part| | |
text = part.text | |
if !parts_of_speech.include? text | |
parts_of_speech << text | |
end | |
end | |
return parts_of_speech | |
end | |
puts part_of_speech(ARGV[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment