Module: TexterraKBM
Constant Summary
Constants included from TexterraKBMSpecs
Instance Method Summary collapse
-
#all_pairs_similarity(first_concepts, second_concepts, linkWeight = 'MAX') ⇒ Object
Computes sum of similarities from each concepts(list or single concept, each concept is id:kbname) from the first list to all concepts(list or single concept, each concept is id:kbname) from the second one.
-
#get_attributes(concepts, attributes = []) ⇒ Object
Get attributes for concepts(list or single concept, each concept is id:kbname).
-
#neighbours(concepts, traverse_params = {}) ⇒ Object
Return neighbour concepts for the given concepts(list or single concept, each concept is id:kbname).
-
#neighbours_size(concepts, traverse_params = {}) ⇒ Object
Return neighbour concepts size for the given concepts(list or single concept, each concept is id:kbname).
-
#representation_terms(text, term_candidates, params = {featureType: ['commonness', 'info-measure']}) ⇒ Object
Determines if Knowledge base contains the specified terms and computes features of the specified types for them.
-
#similar_over_filtered_neighbours(concepts, params = { linkWeight: 'MAX' }) ⇒ Object
Search for similar concepts over filtered set of the first and the second neighbours of the given ones(list or single concept, each concept is id:kbname).
-
#similar_over_first_neighbours(concepts, params = { linkWeight: 'MAX' }) ⇒ Object
Search for similar concepts among the first neighbours of the given ones(list or single concept, each concept is id:kbname).
-
#similarity_between_virtual_articles(first_virtual_aricle, second_virtual_article, linkWeight = 'MAX') ⇒ Object
Compute similarity between two sets of concepts(list or single concept, each concept is id:kbname) as between “virtual” articles from these sets.
-
#similarity_graph(concepts, linkWeight = 'MAX') ⇒ Object
Compute similarity for each pair of concepts(list or single concept, each concept is id:kbname).
-
#similarity_to_virtual_article(concepts, virtual_aricle, linkWeight = 'MAX') ⇒ Object
Compute similarity from each concept from the first list to all concepts(list or single concept, each concept is id:kbname) from the second list as a whole.
Instance Method Details
#all_pairs_similarity(first_concepts, second_concepts, linkWeight = 'MAX') ⇒ Object
Computes sum of similarities from each concepts(list or single concept, each concept is id:kbname) from the first list to all concepts(list or single concept, each concept is id:kbname) from the second one.
82 83 84 |
# File 'lib/ispras-api/texterra/kbm.rb', line 82 def all_pairs_similarity(first_concepts, second_concepts, linkWeight = 'MAX') preset_kbm :allPairsSimilarity, ["#{wrap_concepts(first_concepts)}linkWeight=#{linkWeight}", wrap_concepts(second_concepts)] end |
#get_attributes(concepts, attributes = []) ⇒ Object
check REST Documentation for supported attributes
Get attributes for concepts(list or single concept, each concept is id:kbname)
139 140 141 |
# File 'lib/ispras-api/texterra/kbm.rb', line 139 def get_attributes(concepts, attributes = []) preset_kbm :getAttributes, wrap_concepts(concepts), attribute: attributes end |
#neighbours(concepts, traverse_params = {}) ⇒ Object
Return neighbour concepts for the given concepts(list or single concept, each concept is id:kbname).
If at least one traverse parameter(check REST Documentation for values) is specified, all other parameters should also be specified
43 44 45 46 47 48 |
# File 'lib/ispras-api/texterra/kbm.rb', line 43 def neighbours(concepts, traverse_params = {}) traverse = traverse_params.inject('') do |res, (name, value)| res + ";#{name}=#{value}" end unless traverse_params.empty? preset_kbm :neighbours, [wrap_concepts(concepts), traverse] end |
#neighbours_size(concepts, traverse_params = {}) ⇒ Object
If at least one traverse parameter(check REST Documentation for values) is specified, all other parameters should also be specified
Return neighbour concepts size for the given concepts(list or single concept, each concept is id:kbname).
62 63 64 65 66 67 |
# File 'lib/ispras-api/texterra/kbm.rb', line 62 def neighbours_size(concepts, traverse_params = {}) traverse = traverse_params.inject('') do |res, (name, value)| res + ";#{name}=#{value}" end unless traverse_params.empty? preset_kbm :neighbours, [wrap_concepts(concepts), "#{traverse}/size"] end |
#representation_terms(text, term_candidates, params = {featureType: ['commonness', 'info-measure']}) ⇒ Object
Determines if Knowledge base contains the specified terms and computes features of the specified types for them.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ispras-api/texterra/kbm.rb', line 13 def representation_terms(text, term_candidates, params={featureType: ['commonness', 'info-measure']}) path = KBM_SPECS[:representationTerms][:path] = { headers: { 'Content-Type' => 'application/json' }, query: params, body: { text: text, annotations: { 'term-candidate' => term_candidates } }.to_json } response = self.class.post "/#{path}", response.code == 200 ? response.parsed_response : check_error(response) end |
#similar_over_filtered_neighbours(concepts, params = { linkWeight: 'MAX' }) ⇒ Object
check REST Documentation for values
Search for similar concepts over filtered set of the first and the second neighbours of the given ones(list or single concept, each concept is id:kbname).
129 130 131 132 |
# File 'lib/ispras-api/texterra/kbm.rb', line 129 def similar_over_filtered_neighbours(concepts, params = { linkWeight: 'MAX' }) params[:among] ||= '' preset_kbm :similarOverFilteredNeighbours, "#{wrap_concepts(concepts)};linkWeight=#{params[:linkWeight]}", params end |
#similar_over_first_neighbours(concepts, params = { linkWeight: 'MAX' }) ⇒ Object
check REST Documentation for values
Search for similar concepts among the first neighbours of the given ones(list or single concept, each concept is id:kbname).
115 116 117 |
# File 'lib/ispras-api/texterra/kbm.rb', line 115 def similar_over_first_neighbours(concepts, params = { linkWeight: 'MAX' }) preset_kbm :similarOverFirstNeighbours, "#{wrap_concepts(concepts)};linkWeight=#{params[:linkWeight]}", params end |
#similarity_between_virtual_articles(first_virtual_aricle, second_virtual_article, linkWeight = 'MAX') ⇒ Object
Compute similarity between two sets of concepts(list or single concept, each concept is id:kbname) as between “virtual” articles from these sets. The links of each virtual article are composed of links of the collection of concepts.
102 103 104 |
# File 'lib/ispras-api/texterra/kbm.rb', line 102 def similarity_between_virtual_articles(first_virtual_aricle, second_virtual_article, linkWeight = 'MAX') preset_kbm :similarityBetweenVirtualArticle, ["#{wrap_concepts(first_virtual_aricle)}linkWeight=#{linkWeight}", wrap_concepts(second_virtual_article)] end |
#similarity_graph(concepts, linkWeight = 'MAX') ⇒ Object
Compute similarity for each pair of concepts(list or single concept, each concept is id:kbname).
73 74 75 |
# File 'lib/ispras-api/texterra/kbm.rb', line 73 def similarity_graph(concepts, linkWeight = 'MAX') preset_kbm :similarityGraph, "#{wrap_concepts(concepts)}linkWeight=#{linkWeight}" end |
#similarity_to_virtual_article(concepts, virtual_aricle, linkWeight = 'MAX') ⇒ Object
Compute similarity from each concept from the first list to all concepts(list or single concept, each concept is id:kbname) from the second list as a whole. Links of second list concepts(each concept is id:kbname) are collected together, thus forming a “virtual” article, similarity to which is computed.
92 93 94 |
# File 'lib/ispras-api/texterra/kbm.rb', line 92 def similarity_to_virtual_article(concepts, virtual_aricle, linkWeight = 'MAX') preset_kbm :similarityToVirtualArticle, ["#{wrap_concepts(concepts)}linkWeight=#{linkWeight}", wrap_concepts(virtual_aricle)] end |