Class: TextRazor

Inherits:
Object
  • Object
show all
Defined in:
lib/text_razor.rb,
lib/text_razor/word.rb,
lib/text_razor/topic.rb,
lib/text_razor/entity.rb,
lib/text_razor/version.rb,
lib/text_razor/sentence.rb,
lib/text_razor/coarse_topic.rb

Defined Under Namespace

Classes: CoarseTopic, Entity, Sentence, Topic, Word

Constant Summary collapse

URL =
'http://api.textrazor.com'
VERSION =
"0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TextRazor

Returns a new instance of TextRazor.



15
16
17
18
19
20
# File 'lib/text_razor.rb', line 15

def initialize(options={})
  @api_key    = options[:api_key]
  @text       = options[:text]
  @extractors = options[:extractors]
  @json       = nil
end

Instance Attribute Details

#coarse_topicsObject (readonly)

Returns the value of attribute coarse_topics.



11
12
13
# File 'lib/text_razor.rb', line 11

def coarse_topics
  @coarse_topics
end

#entitiesObject (readonly)

Returns the value of attribute entities.



11
12
13
# File 'lib/text_razor.rb', line 11

def entities
  @entities
end

#sentencesObject (readonly)

Returns the value of attribute sentences.



11
12
13
# File 'lib/text_razor.rb', line 11

def sentences
  @sentences
end

#topicsObject (readonly)

Returns the value of attribute topics.



11
12
13
# File 'lib/text_razor.rb', line 11

def topics
  @topics
end

Instance Method Details

#create_coarse_topics(coarse_topics) ⇒ Object



48
49
50
# File 'lib/text_razor.rb', line 48

def create_coarse_topics(coarse_topics)
  @coarse_topics = coarse_topics.collect{|coarse_topic| CoarseTopic.new(coarse_topic)} if coarse_topics
end

#create_entities(entities) ⇒ Object



40
41
42
# File 'lib/text_razor.rb', line 40

def create_entities(entities)
  @entities = entities.collect {|entity| Entity.new(entity)} if entities
end

#create_sentences(sentences) ⇒ Object



52
53
54
# File 'lib/text_razor.rb', line 52

def create_sentences(sentences)
  @sentences = sentences.collect{|sentence| Sentence.new(sentence)} if sentences
end

#create_topics(topics) ⇒ Object



44
45
46
# File 'lib/text_razor.rb', line 44

def create_topics(topics)
  @topics = topics.collect{|topic| Topic.new(topic)} if topics
end

#is_reliable?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/text_razor.rb', line 36

def is_reliable?
  @json['languageIsReliable']
end

#languageObject



32
33
34
# File 'lib/text_razor.rb', line 32

def language
  @json['language']
end

#processObject



22
23
24
25
26
27
28
29
30
# File 'lib/text_razor.rb', line 22

def process
  response = RestClient.post URL, {apiKey: @api_key, text: @text, extractors: @extractors}
  @json = JSON.parse(response)['response']

  create_entities(@json['entities'])
  create_topics(@json['topics'])
  create_coarse_topics(@json['coarseTopics'])
  create_sentences(@json['sentences'])
end