semcheck 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2c30e33bea4115317cb43d3d3b7a2a1fcab2dfc
4
- data.tar.gz: 44eccf1d572c6bf3085528a7d9542bf87a9046e4
3
+ metadata.gz: 86cc36a7b53254d4886c6f682e16d889298af766
4
+ data.tar.gz: 63807a3da853c9bbb1be6deef12067f2f46151ca
5
5
  SHA512:
6
- metadata.gz: 0f629ffcb0eea77eb01bfc0a97a98b20f96ec5fb61a67c6a013f37b2e6c9b0cbb13e7869b56c1345ba38314dc5e72939f799fe19238a8b0cbf7f05950281aaab
7
- data.tar.gz: 2944cfdbbf6a90bd48a63c67ce85e698a5ebf4a0d3c88f911228f569e4a69cf4eee96dcbe81b356d8d228f54a8b4922d9cf30cf3f6c0e79c06407c925b0c53a3
6
+ metadata.gz: 0bf9d9fe27fb8ca5f0cbffce1e26fd00bb0f1a82e9bae12140b6f43ad7dfcc04cebfe8cf4c34b0cd4d5f2d414aa4d29dced8770f443088f1820b101fd09bc0d9
7
+ data.tar.gz: d3f0b358d727ac0765656f2906fa89dec2b511ad694623f6c0c2b9e9cc0bdc67d47c7cc959d80222e12c68639b8f53e9fbced2885c40de90e5c9d5bcb12a17f1
data/README.md CHANGED
@@ -51,6 +51,10 @@ Or install it yourself as:
51
51
 
52
52
  $ gem install semcheck
53
53
 
54
+ To make use of a more extensive thesaurus, you will need to get an API key from [Big Huge Thesaurus](http://words.bighugelabs.com/) and have internet access. Then set:
55
+
56
+ $ export BHT_API_KEY=yourkey
57
+
54
58
  ## Usage
55
59
  Currently, you must have internet access to use this tool because there's not an easily available database of Schema.org's contents. But using RDF::Querys of a graph database of its schemas may be included in a future minor version.
56
60
 
@@ -58,6 +62,10 @@ Currently, you must have internet access to use this tool because there's not an
58
62
  bin/semcheck restaurant
59
63
  => Searching semweb resources for: ["restaurant"]
60
64
  => Possible schema matches: https://schema.org/Restaurant
65
+ # if you want to make use of the extended thesaurus
66
+ bin/semcheck -M machine
67
+
68
+ Using `-M` requires an extra API call but will often give you fewer results. Why? Because the synonyms it chooses are often more specificly related than the more general smattering you'll get from the local thesaurus (sometimes it won't even find a synonym, for even common words like "food").
61
69
 
62
70
  ## Development
63
71
 
data/lib/semcheck.rb CHANGED
@@ -6,12 +6,18 @@ require 'google-search'
6
6
  # require 'rest-client'
7
7
  # require 'crack' # for xml and json
8
8
 
9
+ BHT_API_KEY = ENV['BHT_API_KEY']
10
+ Dinosaurus.configure do |config|
11
+ config.api_key = BHT_API_KEY
12
+ end
13
+
9
14
  module Semcheck
10
15
  class Application
11
16
  attr_accessor :terms, :synonyms, :schemas
17
+ attr_accessor :flags
12
18
 
13
19
  def initialize(args)
14
- @terms = args
20
+ set_terms_and_flags_from(args)
15
21
  @synonyms = []
16
22
  @schemas = []
17
23
  end
@@ -21,7 +27,12 @@ module Semcheck
21
27
 
22
28
  string_or_array_of(terms).each do |term|
23
29
  # bronto gives us a sparse, but local dict
24
- results = Bronto::Thesaurus.new.lookup(term)
30
+ results = Bronto::Thesaurus.new.lookup(term) || {}
31
+
32
+ if !BHT_API_KEY.nil? && flags.include?("-M")
33
+ results.merge!(Dinosaurus.lookup(term))
34
+ end
35
+
25
36
  if !results.nil?
26
37
  results.keys.each do |word_type|
27
38
  synonyms << results[word_type][:syn]
@@ -29,7 +40,6 @@ module Semcheck
29
40
  end
30
41
  end
31
42
  synonyms.flatten!
32
-
33
43
  # schema.org just uses google to do search
34
44
  schemas << Google::Search::Web.new do |search|
35
45
  search.query = "site:schema.org " + maybe_array_of(terms).join(" OR ")
@@ -50,6 +60,17 @@ module Semcheck
50
60
  return self
51
61
  end
52
62
 
63
+ def set_terms_and_flags_from(args)
64
+ set_flags_from(string_or_array_of(args))
65
+ set_terms_from(string_or_array_of(args))
66
+ end
67
+ def set_flags_from(args)
68
+ @flags = args.select {|arg| arg =~ /^-[M]/}
69
+ end
70
+ def set_terms_from(args)
71
+ @terms = args.reject {|arg| arg =~ /^-[M]/}
72
+ end
73
+
53
74
  private
54
75
  def string_or_array_of(terms)
55
76
  if terms.is_a? Array
@@ -1,3 +1,3 @@
1
1
  module Semcheck
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semcheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Moore-Niemi