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



96
97
98
# File 'lib/ispras-api/texterra/kbm.rb', line 96

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



153
154
155
# File 'lib/ispras-api/texterra/kbm.rb', line 153

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



57
58
59
60
61
62
# File 'lib/ispras-api/texterra/kbm.rb', line 57

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



76
77
78
79
80
81
# File 'lib/ispras-api/texterra/kbm.rb', line 76

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

#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



143
144
145
146
# File 'lib/ispras-api/texterra/kbm.rb', line 143

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



129
130
131
# File 'lib/ispras-api/texterra/kbm.rb', line 129

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



116
117
118
# File 'lib/ispras-api/texterra/kbm.rb', line 116

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



87
88
89
# File 'lib/ispras-api/texterra/kbm.rb', line 87

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



106
107
108
# File 'lib/ispras-api/texterra/kbm.rb', line 106

def similarity_to_virtual_article(concepts, virtual_aricle, linkWeight = 'MAX')
  preset_kbm :similarityToVirtualArticle, ["#{wrap_concepts(concepts)}linkWeight=#{linkWeight}", wrap_concepts(virtual_aricle)]
end

#term_commonness(term, concept = '') ⇒ Object

If concept isn’t provided, returns concepts with their commonness, corresponding to the found meanings of the given term. Commonness denotes, how often the given term is associated with the given concept. With concept(format is id:kbname) returns commonness of given concept for the given term.

Parameters:

  • term (String)

    term

  • concept (String) (defaults to: '')

    concept as id:kbname



40
41
42
43
# File 'lib/ispras-api/texterra/kbm.rb', line 40

def term_commonness(term, concept = '')
  concept = "id=#{concept}" unless concept.empty?
  preset_kbm :termCommonness, [term, concept]
end

#term_info_measure(term) ⇒ Object

Returns information measure for the given term. Information measure denotes, how often given term is used as link caption among all its occurences

Parameters:

  • term (String)

    term



19
20
21
# File 'lib/ispras-api/texterra/kbm.rb', line 19

def term_info_measure(term)
  preset_kbm :termInfoMeasure, term
end

#term_meanings(term) ⇒ Object

Return concepts resource from the Knowledge base corresponding to the found meanings of the given term

Parameters:

  • term (String)

    term



28
29
30
# File 'lib/ispras-api/texterra/kbm.rb', line 28

def term_meanings(term)
  preset_kbm :termMeanings, term
end

#term_presence(term) ⇒ Hash

Determines if Knowledge base contains the specified term

Parameters:

  • term (String)

    term

Returns:

  • (Hash)

    with :presence field



10
11
12
# File 'lib/ispras-api/texterra/kbm.rb', line 10

def term_presence(term)
  preset_kbm :termPresence, term
end