Class: TexterraAPI
- Includes:
- TexterraKBM, TexterraNLP
- Defined in:
- lib/ispras-api/texterra_api.rb
Constant Summary
Constants included from TexterraNLPSpecs
Constants included from TexterraKBMSpecs
Constants inherited from IsprasAPI
Instance Method Summary collapse
- #custom_query(path, query, form = nil) ⇒ Object
-
#disambiguation(text) ⇒ Array
Detects the most appropriate meanings (concepts) for terms occurred in a given text.
-
#domain_sentiment_analysis(text, domain = '') ⇒ Hash
Detects whether the given text has positive, negative, or no sentiment, with respect to domain.
-
#initialize(key, name = nil, ver = nil) ⇒ TexterraAPI
constructor
A new instance of TexterraAPI.
-
#key_concepts(text) ⇒ Array
Key concepts are the concepts providing short (conceptual) and informative text description.
-
#sentiment_analysis(text) ⇒ Array
Detects whether the given text has positive, negative or no sentiment.
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, #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
Constructor Details
#initialize(key, name = nil, ver = nil) ⇒ TexterraAPI
Returns a new instance of TexterraAPI.
15 16 17 18 19 |
# File 'lib/ispras-api/texterra_api.rb', line 15 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
77 78 79 |
# File 'lib/ispras-api/texterra_api.rb', line 77 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
73 74 75 |
# File 'lib/ispras-api/texterra_api.rb', line 73 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
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ispras-api/texterra_api.rb', line 56 def domain_sentiment_analysis(text, domain = '') used_domain = 'general' sentiment = 'NEUTRAL' (domain_polarity_detection_annotate(text, domain) || []).each do |an| sentiment = an[:value] if an[:@class].include? 'SentimentPolarity' used_domain = an[:value] if an[:@class].include? 'DomainAnnotation' 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
30 31 32 33 34 35 36 37 |
# File 'lib/ispras-api/texterra_api.rb', line 30 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 do |kc| kc[:concept][:weight] = kc[:double] kc[:concept] end end |
#sentiment_analysis(text) ⇒ Array
Detects whether the given text has positive, negative or no sentiment
43 44 45 46 47 |
# File 'lib/ispras-api/texterra_api.rb', line 43 def sentiment_analysis(text) polarity_detection_annotate(text)[0][:value].to_s || 'NEUTRAL' rescue NoMethodError 'NEUTRAL' end |