Class: Semcheck::Application
- Inherits:
-
Object
- Object
- Semcheck::Application
- Defined in:
- lib/semcheck.rb
Instance Attribute Summary collapse
-
#flags ⇒ Object
Returns the value of attribute flags.
-
#schemas ⇒ Object
Returns the value of attribute schemas.
-
#synonyms ⇒ Object
Returns the value of attribute synonyms.
-
#terms ⇒ Object
Returns the value of attribute terms.
Instance Method Summary collapse
-
#initialize(args) ⇒ Application
constructor
A new instance of Application.
- #run ⇒ Object
- #set_flags_from(args) ⇒ Object
- #set_terms_and_flags_from(args) ⇒ Object
- #set_terms_from(args) ⇒ Object
Constructor Details
#initialize(args) ⇒ Application
Returns a new instance of Application.
19 20 21 22 23 |
# File 'lib/semcheck.rb', line 19 def initialize(args) set_terms_and_flags_from(args) @synonyms = [] @schemas = [] end |
Instance Attribute Details
#flags ⇒ Object
Returns the value of attribute flags.
17 18 19 |
# File 'lib/semcheck.rb', line 17 def flags @flags end |
#schemas ⇒ Object
Returns the value of attribute schemas.
16 17 18 |
# File 'lib/semcheck.rb', line 16 def schemas @schemas end |
#synonyms ⇒ Object
Returns the value of attribute synonyms.
16 17 18 |
# File 'lib/semcheck.rb', line 16 def synonyms @synonyms end |
#terms ⇒ Object
Returns the value of attribute terms.
16 17 18 |
# File 'lib/semcheck.rb', line 16 def terms @terms end |
Instance Method Details
#run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/semcheck.rb', line 25 def run puts "Searching semweb resources for: #{terms}" string_or_array_of(terms).each do |term| # bronto gives us a sparse, but local dict results = Bronto::Thesaurus.new.lookup(term) || {} if !BHT_API_KEY.nil? && flags.include?("-M") results.merge!(Dinosaurus.lookup(term)) end if !results.nil? results.keys.each do |word_type| synonyms << results[word_type][:syn] end end end synonyms.flatten! # schema.org just uses google to do search schemas << Google::Search::Web.new do |search| search.query = "site:schema.org " + maybe_array_of(terms).join(" OR ") end.map(&:uri) # oddly, if i just do a giant or chain i can lose # the results i wouldve gotten from the single term schemas << Google::Search::Web.new do |search| search.query = "site:schema.org " + maybe_array_of(synonyms).join(" OR ") end.map(&:uri) @schemas = schemas.flatten.reject! do |url| blacklist.include?(url) || url =~ schema_blog end.uniq puts "Possible schema matches:\n#{schemas.join("\n")}" return self end |
#set_flags_from(args) ⇒ Object
67 68 69 |
# File 'lib/semcheck.rb', line 67 def set_flags_from(args) @flags = args.select {|arg| arg =~ /^-[M]/} end |
#set_terms_and_flags_from(args) ⇒ Object
63 64 65 66 |
# File 'lib/semcheck.rb', line 63 def set_terms_and_flags_from(args) set_flags_from(string_or_array_of(args)) set_terms_from(string_or_array_of(args)) end |
#set_terms_from(args) ⇒ Object
70 71 72 |
# File 'lib/semcheck.rb', line 70 def set_terms_from(args) @terms = args.reject {|arg| arg =~ /^-[M]/} end |