Class: TexterraAPI

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

Constant Summary

Constants included from TexterraNLPSpecs

TexterraNLPSpecs::NLP_SPECS

Constants included from TexterraKBMSpecs

TexterraKBMSpecs::KBM_SPECS

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_annotate, #spelling_correction_annotate, #subjectivity_detection_annotate, #syntax_detection, #term_detection_annotate, #tokenization_annotate, #tweet_normalization

Methods included from TexterraKBM

#all_pairs_similarity, #get_attributes, #neighbours, #neighbours_size, #representation_terms, #similar_over_filtered_neighbours, #similar_over_first_neighbours, #similarity_between_virtual_articles, #similarity_graph, #similarity_to_virtual_article

Methods inherited from IsprasAPI

#GET, #POST

Constructor Details

#initialize(key, name = nil, ver = nil) ⇒ TexterraAPI

Returns a new instance of TexterraAPI.



25
26
27
28
29
# File 'lib/ispras-api/texterra_api.rb', line 25

def initialize(key, name = nil, ver = nil)
  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



84
85
86
# File 'lib/ispras-api/texterra_api.rb', line 84

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



80
81
82
# File 'lib/ispras-api/texterra_api.rb', line 80

def disambiguation(text)
  disambiguation_annotate(text)[:annotations][:'disambiguated-phrase']
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



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ispras-api/texterra_api.rb', line 61

def domain_sentiment_analysis(text, domain = '')
  used_domain = 'general'
  sentiment = 'NEUTRAL'
  annotations = domain_polarity_detection_annotate(text, domain)[:annotations]
  begin
    used_domain = annotations[:domain][0][:value]
    sentiment = annotations[:polarity][0][:value]
  rescue NoMethodError
  end
  {
    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



40
41
42
# File 'lib/ispras-api/texterra_api.rb', line 40

def key_concepts(text)
  key_concepts = key_concepts_annotate(text)[:annotations][:keyconcepts][0][:value] || []
end

#sentiment_analysis(text) ⇒ String

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

Parameters:

  • text (String)

    Text to process

Returns:

  • (String)

    Sentiment of the text



48
49
50
51
52
# File 'lib/ispras-api/texterra_api.rb', line 48

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