Class: TexterraAPI
- Includes:
- TexterraKBM, TexterraNLP
- Defined in:
- lib/ispapi/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, ver) ⇒ 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, #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
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
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
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
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
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 |