Class: TexterraAPI

Inherits:
IsprasAPI show all
Includes:
TexterraKBM, TexterraNLP
Defined in:
lib/ispapi/texterra_api.rb

Constant Summary

Constants included from TexterraNLPSpecs

TexterraNLPSpecs::NLPSpecs

Constants included from TexterraKBMSpecs

TexterraKBMSpecs::KBMSpecs

Constants inherited from IsprasAPI

IsprasAPI::ROOT_URL

Instance Method Summary collapse

Methods included from TexterraNLP

#disambiguation_annotate, #domain_detection_annotate, #domain_polarity_detection_annotate, #key_concepts_annotate, #language_detection_annotate, #lemmatization_annotate, #named_entities_annotate, #polarity_detection_annotate, #pos_tagging_annotate, #sentence_detection, #spelling_correction_annotate, #subjectivity_detection_annotate, #term_detection_annotate, #tokenization_annotate, #tweet_normalization

Methods included from TexterraKBM

#all_pairs_similarity, #get_attributes, #neighbours, #neighbours_size, #similar_over_filtered_neighbours, #similar_over_first_neighbours, #similarity_between_virtual_articles, #similarity_graph, #similarity_to_virtual_article, #term_commonness, #term_info_measure, #term_meanings, #term_presence

Methods inherited from IsprasAPI

#GET, #POST

Constructor Details

#initialize(key, name, ver) ⇒ TexterraAPI

Returns a new instance of TexterraAPI.



11
12
13
14
15
# File 'lib/ispapi/texterra_api.rb', line 11

def initialize(key, name, ver)
  name='texterra' if name.nil? || name.empty?
  ver='v3.1' if ver.nil? || ver.empty?
  super(key, name, ver)
end

Instance Method Details

#custom_query(path, query, form = nil) ⇒ Object



74
75
76
# File 'lib/ispapi/texterra_api.rb', line 74

def custom_query(path, query, form=nil)
  form.nil? ? GET(path, query) : POST(path, query, form)
end

#disambiguation(text) ⇒ Array

Detects the most appropriate meanings (concepts) for terms occurred in a given text

Parameters:

  • text (String)

    Text to process

Returns:

  • (Array)

    Texterra annotations



70
71
72
# File 'lib/ispapi/texterra_api.rb', line 70

def disambiguation(text)
  disambiguation_annotate(text)
end

#domain_sentiment_analysis(text, domain = '') ⇒ Hash

Detects whether the given text has positive, negative, or no sentiment, with respect to domain. If domain isn’t provided, Domain detection is applied, this way method tries to achieve best results. If no domain is detected general domain algorithm is applied

Parameters:

  • text (String)

    Text to process

  • domain (String) (defaults to: '')

    domain to use. Can be empty

Returns:

  • (Hash)

    used :domain and detected :polarity



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ispapi/texterra_api.rb', line 53

def domain_sentiment_analysis(text, domain='')
  used_domain = 'general'
  sentiment = 'NEUTRAL'
  (domain_polarity_detection_annotate(text, domain) || []).each { |an|
    sentiment = an[:value] if an[:@class].include? 'SentimentPolarity'
    used_domain = an[:value] if an[:@class].include? 'DomainAnnotation'
  }
  {
    domain: used_domain,
    polarity: sentiment
  }
end

#key_concepts(text) ⇒ Array

Key concepts are the concepts providing short (conceptual) and informative text description. This service extracts a set of key concepts for a given text

Parameters:

  • text (String)

    Text to process

Returns:

  • (Array)

    Array of weighted key concepts



25
26
27
28
29
30
31
32
# File 'lib/ispapi/texterra_api.rb', line 25

def key_concepts(text)
  key_concepts = key_concepts_annotate(text)[0][:value][:concepts_weights][:entry] || []
  key_concepts = [].push key_concepts unless key_concepts.is_a? Array
  key_concepts.map { |kc| 
    kc[:concept][:weight] = kc[:double] 
    kc[:concept]
  }
end

#sentiment_analysis(text) ⇒ Array

Detects whether the given text has positive, negative or no sentiment

Parameters:

  • text (String)

    Text to process

Returns:

  • (Array)

    Sentiment of the text



38
39
40
41
42
43
44
# File 'lib/ispapi/texterra_api.rb', line 38

def sentiment_analysis(text)
  begin
    polarity_detection_annotate(text)[0][:value].to_s || 'NEUTRAL'
  rescue NoMethodError
    'NEUTRAL'
  end
end