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 +4 -4
- data/lib/ispras-api.rb +1 -1
- data/lib/ispras-api/ispras_api.rb +1 -1
- data/lib/ispras-api/texterra/kbm.rb +25 -39
- data/lib/ispras-api/texterra/kbm_specs.rb +2 -14
- data/lib/ispras-api/texterra/nlp_specs.rb +6 -6
- data/lib/ispras-api/texterra_api.rb +11 -1
- data/lib/ispras-api/version.rb +3 -3
- data/test/test_texterra_api.rb +10 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bcfa8343a980dd19a4ef3c0034994631a8abe0f
|
4
|
+
data.tar.gz: e8e9c2339717da7ffc54801902b39b12ffc8cca8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8beee1396a7291cea5bd2cbfeb209b465cffad3e54a0be576e4ab0f5881d204ddca20b5cdf158e336d9dd74bf52d20c38650721b7d63a26e8e80aceb9f971d90
|
7
|
+
data.tar.gz: 974689d185f7357ec9f6fa0940404aea6146aec8404ce695d1d333d59c266bebf84bee56acdac5ee9d1c7503da9cfacafbc392a197ad3a9e9700655db0db56b6
|
data/lib/ispras-api.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require_relative 'ispras-api/texterra_api'
|
1
|
+
require_relative './ispras-api/texterra_api'
|
@@ -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
|
7
|
-
#
|
8
|
-
# @param
|
9
|
-
# @
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
5
|
-
path: 'representation
|
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: '
|
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: '
|
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
|
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: '
|
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: '
|
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
|
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
|
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?
|
data/lib/ispras-api/version.rb
CHANGED
data/test/test_texterra_api.rb
CHANGED
@@ -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
|
105
|
-
|
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
|
108
|
-
|
109
|
-
|
110
|
-
|
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.
|
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-
|
11
|
+
date: 2016-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|