Module: TexterraKBM

Includes:
TexterraKBMSpecs
Included in:
TexterraAPI
Defined in:
lib/ispras-api/texterra/kbm.rb

Constant Summary

Constants included from TexterraKBMSpecs

TexterraKBMSpecs::KBM_SPECS

Instance Method Summary collapse

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.

Parameters:

  • first_concepts (Array<String>)

    Array of concepts as id:kbname

  • second_concepts (Array<String>)

    Array of concepts as id:kbname

  • linkWeight (String) (defaults to: 'MAX')

    Specifies method for computation of link weight in case of multiple link types - check REST Documentation for values



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

Note:

check REST Documentation for supported attributes

Get attributes for concepts(list or single concept, each concept is id:kbname)

Parameters:

  • concepts (String, Array<String>)

    Either concept as id:kbname or array of such concepts

  • attributes (Array<String>) (defaults to: [])

    Specifies attributes to be included into response



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

Parameters:

  • concepts (String, Array<String>)

    either concept as id:kbname or array of such concepts

  • traverse_params (Hash) (defaults to: {})

    optional

Options Hash (traverse_params):

  • :linkType (String)

    searching for neightbour concepts only along these link types

  • :nodeType (String)

    searching for neightbour concepts only of these types

  • :minDepth (Fixnum)

    minimum distance from original to result concepts

  • :maxDepth (Fixnum)

    maximum distance from original to result concepts



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

Note:

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).

Parameters:

  • concepts (String, Array<String>)

    either concept as id:kbname or array of such concepts

  • traverse_params (Hash) (defaults to: {})

    optional

Options Hash (traverse_params):

  • :linkType (String)

    searching for neightbour concepts only along these link types

  • :nodeType (String)

    searching for neightbour concepts only of these types

  • :minDepth (Fixnum)

    minimum distance from original to result concepts

  • :maxDepth (Fixnum)

    maximum distance from original to result concepts



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.

Parameters:

  • text (String)

    Text with term-candidates

  • term_candidates (Array)

    Term-candidates start and end

  • params (Hash) (defaults to: {featureType: ['commonness', 'info-measure']})

    Specifies types of features required to compute



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]
  options = {
    headers: {
      'Content-Type' => 'application/json'
    },
    query: params,
    body: {
      text: text,
      annotations: {
        'term-candidate' => term_candidates
      }
    }.to_json
  }
  response = self.class.post "/#{path}", options
  response.code == 200 ? response.parsed_response : check_error(response)
end

#similar_over_filtered_neighbours(concepts, params = { linkWeight: 'MAX' }) ⇒ Object

Note:

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).

Parameters:

  • concepts (Array<String>)

    Array of concepts as id:kbname

  • params (Hash) (defaults to: { linkWeight: 'MAX' })

Options Hash (params):

  • :linkWeight (String)

    Specifies method for computation of link weight in case of multiple link types

  • :offset (Fixnum)

    Provides a possibility to skip several concepts from the start of the result

  • :limit (Fixnum)

    Provides a possibility to limit size of result

  • :among (String)

    Specifies how to filter neighbour concepts when searching for most similar



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

Note:

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).

Parameters:

  • concepts (Array<String>)

    Array of concepts as id:kbname

  • params (Hash) (defaults to: { linkWeight: 'MAX' })

Options Hash (params):

  • :linkWeight (String)

    Specifies method for computation of link weight in case of multiple link types

  • :offset (Fixnum)

    Provides a possibility to skip several concepts from the start of the result

  • :limit (Fixnum)

    Provides a possibility to limit size of result



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.

Parameters:

  • first_virtual_aricle (Array<String>)

    Array of concepts as id:kbname

  • second_virtual_article (Array<String>)

    Array of concepts as id:kbname

  • linkWeight (String) (defaults to: 'MAX')

    Specifies method for computation of link weight in case of multiple link types - check REST Documentation for values



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).

Parameters:

  • concepts (Array<String>)

    Array of concepts as id:kbname

  • linkWeight (String) (defaults to: 'MAX')

    Specifies method for computation of link weight in case of multiple link types - check REST Documentation for values



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.

Parameters:

  • concepts (Array<String>)

    Array of concepts as id:kbname

  • virtual_aricle (Array<String>)

    Array of concepts as id:kbname

  • linkWeight (String) (defaults to: 'MAX')

    Specifies method for computation of link weight in case of multiple link types - check REST Documentation for values



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