ispras-api 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b020e4ba0262e432405832a5c7b863d4e7a138db
4
- data.tar.gz: 4c16a369d6c20145245078f84a4914d8f7bc6d92
3
+ metadata.gz: 6bcfa8343a980dd19a4ef3c0034994631a8abe0f
4
+ data.tar.gz: e8e9c2339717da7ffc54801902b39b12ffc8cca8
5
5
  SHA512:
6
- metadata.gz: aa4c7930cce79c114e1a875d9134aa9239767282ab2a91f4099704bdab191846ab4f1f84012ae0df4f55319b9160032f4932d6846b9c769fbc04fba14017e86e
7
- data.tar.gz: 82a73cb7ad6325b6c236878f51069faab1ae1bc6e835ea64976ee2075dd350c06a64cbd810bbd94879a43aaccb90948f6efda9ecd8b287707cbb92bb106c298e
6
+ metadata.gz: 8beee1396a7291cea5bd2cbfeb209b465cffad3e54a0be576e4ab0f5881d204ddca20b5cdf158e336d9dd74bf52d20c38650721b7d63a26e8e80aceb9f971d90
7
+ data.tar.gz: 974689d185f7357ec9f6fa0940404aea6146aec8404ce695d1d333d59c266bebf84bee56acdac5ee9d1c7503da9cfacafbc392a197ad3a9e9700655db0db56b6
@@ -1 +1 @@
1
- require_relative 'ispras-api/texterra_api'
1
+ require_relative './ispras-api/texterra_api'
@@ -1,6 +1,6 @@
1
1
  require 'httparty'
2
2
  require 'nori'
3
- require_relative 'api_error'
3
+ require_relative './api_error'
4
4
 
5
5
  class IsprasAPI
6
6
  include HTTParty
@@ -3,43 +3,29 @@ require_relative './kbm_specs'
3
3
  module TexterraKBM
4
4
  include TexterraKBMSpecs
5
5
 
6
- # Determines if Knowledge base contains the specified term
7
- #
8
- # @param term [String] term
9
- # @return [Hash] with :presence field
10
- def term_presence(term)
11
- preset_kbm :termPresence, term
12
- end
13
-
14
- # Returns information measure for the given term. Information measure denotes,
15
- # how often given term is used as link caption among all its occurences
16
- #
17
- # @param term [String] term
18
- # @result [Hash] with :infomeasure field
19
- def term_info_measure(term)
20
- preset_kbm :termInfoMeasure, term
21
- end
22
-
23
- # Return concepts resource from the Knowledge base corresponding
24
- # to the found meanings of the given term
25
- #
26
- # @param term [String] term
27
- # @result [Hash] with :elements field
28
- def term_meanings(term)
29
- preset_kbm :termMeanings, term
30
- end
31
-
32
- # If concept isn't provided, returns concepts with their commonness,
33
- # corresponding to the found meanings of the given term.
34
- # Commonness denotes, how often the given term is associated with the given concept.
35
- # With concept(format is {id}:{kbname}) returns commonness of given concept for the given term.
36
- #
37
- # @param term [String] term
38
- # @param concept [String] concept as {id}:{kbname}
39
- # @result [Hash] with :elements field
40
- def term_commonness(term, concept = '')
41
- concept = "id=#{concept}" unless concept.empty?
42
- preset_kbm :termCommonness, [term, concept]
6
+ # Determines if Knowledge base contains the specified terms and computes features of the specified types for them.
7
+ #
8
+ # @param [String] text Text with term-candidates
9
+ # @param [Array] term_candidates Term-candidates start and end
10
+ # @param [Hash] params Specifies types of features required to compute
11
+ #
12
+ # @result [Array] Texterra annotations
13
+ def representation_terms(text, term_candidates, params={featureType: ['commonness', 'info-measure']})
14
+ path = KBM_SPECS[:representationTerms][:path]
15
+ options = {
16
+ headers: {
17
+ 'Content-Type' => 'application/json'
18
+ },
19
+ query: params,
20
+ body: {
21
+ text: text,
22
+ annotations: {
23
+ 'term-candidate' => term_candidates
24
+ }
25
+ }.to_json
26
+ }
27
+ response = self.class.post "/#{path}", options
28
+ response.code == 200 ? response.parsed_response : check_error(response)
43
29
  end
44
30
 
45
31
  # Return neighbour concepts for the given concepts(list or single concept, each concept is {id}:{kbname}).
@@ -97,7 +83,7 @@ module TexterraKBM
97
83
  preset_kbm :allPairsSimilarity, ["#{wrap_concepts(first_concepts)}linkWeight=#{linkWeight}", wrap_concepts(second_concepts)]
98
84
  end
99
85
 
100
- # 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.
86
+ # 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.
101
87
  # Links of second list concepts(each concept is {id}:{kbname}) are collected together, thus forming a "virtual" article, similarity to which is computed.
102
88
  #
103
89
  # @param [Array<String>] concepts Array of concepts as {id}:{kbname}
@@ -107,7 +93,7 @@ module TexterraKBM
107
93
  preset_kbm :similarityToVirtualArticle, ["#{wrap_concepts(concepts)}linkWeight=#{linkWeight}", wrap_concepts(virtual_aricle)]
108
94
  end
109
95
 
110
- # Compute similarity between two sets of concepts(list or single concept, each concept is {id}:{kbname}) as between "virtual" articles from these sets.
96
+ # Compute similarity between two sets of concepts(list or single concept, each concept is {id}:{kbname}) as between "virtual" articles from these sets.
111
97
  # The links of each virtual article are composed of links of the collection of concepts.
112
98
  #
113
99
  # @param [Array<String>] first_virtual_aricle Array of concepts as {id}:{kbname}
@@ -1,20 +1,8 @@
1
1
  module TexterraKBMSpecs
2
2
  # Path and parameters for preset KBM queries
3
3
  KBM_SPECS = {
4
- termPresence: {
5
- path: 'representation/%s/contained',
6
- params: {}
7
- },
8
- termInfoMeasure: {
9
- path: 'representation/%s/infomeasure',
10
- params: {}
11
- },
12
- termMeanings: {
13
- path: 'representation/%s/meanings',
14
- params: {}
15
- },
16
- termCommonness: {
17
- path: 'representation/%s/commonness/%s',
4
+ representationTerms: {
5
+ path: 'representation/terms',
18
6
  params: {}
19
7
  },
20
8
  neighbours: {
@@ -32,7 +32,7 @@ module TexterraNLPSpecs
32
32
  posTagging: {
33
33
  path: 'nlp/pos',
34
34
  params: {
35
- class: 'ru.ispras.texterra.core.nlp.datamodel.pos.POSToken',
35
+ class: 'pos-token',
36
36
  filtering: 'KEEPING'
37
37
  }
38
38
  },
@@ -60,7 +60,7 @@ module TexterraNLPSpecs
60
60
  disambiguation: {
61
61
  path: 'nlp/disambiguation',
62
62
  params: {
63
- class: 'dmb-phrase',
63
+ class: 'disambiguated-phrase',
64
64
  filtering: 'KEEPING'
65
65
  }
66
66
 
@@ -68,7 +68,7 @@ module TexterraNLPSpecs
68
68
  keyConcepts: {
69
69
  path: 'nlp/keyconcepts',
70
70
  params: {
71
- class: 'keyconcepts-sc',
71
+ class: 'keyconcepts',
72
72
  filtering: 'KEEPING'
73
73
  }
74
74
 
@@ -84,7 +84,7 @@ module TexterraNLPSpecs
84
84
  subjectivityDetection: {
85
85
  path: 'nlp/subjectivity',
86
86
  params: {
87
- class: 'sentiment-subjectivity',
87
+ class: 'subjectivity',
88
88
  filtering: 'KEEPING'
89
89
  }
90
90
 
@@ -92,7 +92,7 @@ module TexterraNLPSpecs
92
92
  polarityDetection: {
93
93
  path: 'nlp/polarity',
94
94
  params: {
95
- class: 'sentiment-polarity',
95
+ class: 'polarity',
96
96
  filtering: 'KEEPING'
97
97
  }
98
98
 
@@ -108,7 +108,7 @@ module TexterraNLPSpecs
108
108
  domainPolarityDetection: {
109
109
  path: 'nlp/domainpolarity%s',
110
110
  params: {
111
- class: %w(domain sentiment-polarity),
111
+ class: %w(domain polarity),
112
112
  filtering: 'KEEPING'
113
113
  }
114
114
 
@@ -1,3 +1,4 @@
1
+ require 'json'
1
2
  require_relative './ispras_api'
2
3
  require_relative './texterra/nlp'
3
4
  require_relative './texterra/kbm'
@@ -10,7 +11,16 @@ class TexterraAPI < IsprasAPI
10
11
  disable_rails_query_string_format
11
12
  nori = Nori.new(parser: :rexml,
12
13
  convert_tags_to: ->(tag) { tag.snakecase.to_sym })
13
- parser proc { |data| nori.parse data }
14
+ parser(
15
+ proc do |data|
16
+ result = nori.parse(data)
17
+ begin
18
+ result = JSON.parse(data, symbolize_names: true) if result.empty?
19
+ rescue
20
+ end
21
+ result
22
+ end
23
+ )
14
24
 
15
25
  def initialize(key, name = nil, ver = nil)
16
26
  name = 'texterra' if name.nil? || name.empty?
@@ -1,12 +1,12 @@
1
1
  module Version
2
2
  MAJOR = 0
3
3
  MINOR = 1
4
- PATCH = 6
4
+ PATCH = 7
5
5
  PRE = nil
6
6
 
7
7
  YEAR = '2016'
8
- MONTH = '08'
9
- DAY = '26'
8
+ MONTH = '09'
9
+ DAY = '09'
10
10
 
11
11
  def self.to_s
12
12
  [MAJOR, MINOR, PATCH, PRE].compact.join('.')
@@ -101,23 +101,17 @@ class TestTexterraAPI < Minitest::Test
101
101
  assert_instance_of Array, @texterra.subjectivity_detection_annotate(@ru_tweet)
102
102
  end
103
103
 
104
- def test_term_presence
105
- res = @texterra.term_presence('Anarchism')
104
+ def test_representation_terms
105
+ term_candidates = [
106
+ { start: 0, end: 5 },
107
+ { start: 6, end: 11 }
108
+ ]
109
+ res = @texterra.representation_terms(@en_text, term_candidates, featureType: ['commonness', 'info-measure'])
106
110
  assert_instance_of Hash, res
107
- assert_equal true, res[:presence]
108
- end
109
-
110
- def test_term_info_measure
111
- assert_instance_of Hash, @texterra.term_info_measure('Anarchism')
112
- end
113
-
114
- def test_term_meanings
115
- assert_instance_of Hash, @texterra.term_meanings('android')
116
- end
117
-
118
- def test_term_commonness
119
- assert_instance_of Hash, @texterra.term_commonness('android')
120
- assert_instance_of Hash, @texterra.term_commonness('android', '713:enwiki')
111
+ assert_equal res[:text], @en_text
112
+ assert_instance_of Hash, res[:annotations]
113
+ assert_instance_of Array, res[:annotations][:commonness]
114
+ assert_instance_of Array, res[:annotations][:'info-measure']
121
115
  end
122
116
 
123
117
  def test_neighbours
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ispras-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Laguta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-26 00:00:00.000000000 Z
11
+ date: 2016-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty