Module: SemanticExtraction
- Defined in:
- lib/semantic_extraction.rb,
lib/semantic_extraction/utility_methods.rb,
lib/semantic_extraction/extractors/yahoo.rb,
lib/semantic_extraction/extractors/alchemy.rb
Defined Under Namespace
Modules: Alchemy, UtilityMethods, Yahoo
Classes: MissingApiKey, NotSupportedExtraction, NotSupportedExtractor
Class Method Summary
collapse
Class Method Details
.find_generic(typer, args) ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/semantic_extraction.rb', line 47
def self.find_generic(typer, args)
if self.is_valid?(typer)
return @@klass.send(typer.to_sym, args)
elsif !@@klass.respond_to?(typer.to_sym)
raise NotSupportedExtraction
else
raise MissingApiKey
end
end
|
.is_valid?(method) ⇒ Boolean
62
63
64
65
66
67
68
69
|
# File 'lib/semantic_extraction.rb', line 62
def self.is_valid?(method)
@@klass = SemanticExtraction.const_get(self..gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase })
if self.requires_api_key.include? self.
(@@klass.respond_to?(method) && defined?(self.send(( + "_api_key").to_sym)) && !(self.send(( + "_api_key").to_sym)).empty?) ? true : false
else
@@klass.respond_to?(method)
end
end
|
.method_missing(method, args) ⇒ Object
57
58
59
|
# File 'lib/semantic_extraction.rb', line 57
def self.method_missing(method, args)
find_generic(method.to_sym, args)
end
|
By default, we assume you want to use Alchemy. To override, just set SemanticExtraction.preferred_extractor somewhere and define the appropriate api_key.
21
22
23
24
25
26
27
|
# File 'lib/semantic_extraction.rb', line 21
def self.(value)
if self..include?(value)
@@preferred_extractor = value
else
raise NotSupportedExtractor
end
end
|