sentra 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sentra/sents.rb +37 -0
- data/lib/sentra/version.rb +1 -1
- data/lib/sentra.rb +31 -29
- data/tools/multithread_check.rb +64 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03bd62dfaa1b99334cb24f70268ff008e7b75105
|
4
|
+
data.tar.gz: 0151facbc528f27196a4e53242c81838a8382696
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c51381d084bcc6909964d37e6d3f755a3c438699f75c4bbbd0887f46b771daf41f093a8fff5c14414e05293d8713dee1e15df192d05d9f12247e335efaa92ef8
|
7
|
+
data.tar.gz: 67db4c28ceb97d91e3a20dd4d2b7c0753292df306cf8f2a827d9ef6a36d8a018ec11c507dcc3fa6dffbbb128363ab16f97d155cdd83adbd046c4757858ce2e99
|
data/lib/sentra/sents.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Sentra
|
2
|
+
class ProcessingClient
|
3
|
+
def initialize
|
4
|
+
@tweet = OprData::Article.new
|
5
|
+
|
6
|
+
p "initializing"
|
7
|
+
end
|
8
|
+
def prepare_article content, url, title,domain='GENERAL'
|
9
|
+
calendar = Util::Calendar.getInstance();
|
10
|
+
@tweet.setUrl(Net::URL.new(url));
|
11
|
+
@tweet.setDate(calendar.getTime)
|
12
|
+
@tweet.setTitle(title)
|
13
|
+
@tweet.setChannel(domain)
|
14
|
+
@tweet.setContent(content)
|
15
|
+
end
|
16
|
+
def send
|
17
|
+
|
18
|
+
p 'sending'
|
19
|
+
queue = SemanticService::UnixSocketClient.new()
|
20
|
+
queue.writeArticle(@tweet)
|
21
|
+
p 'receiving'
|
22
|
+
result = queue.readArticle()
|
23
|
+
p 'read done'
|
24
|
+
result.getMetadata('twitter').getFacts()
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def process_result statistics
|
29
|
+
response = {}
|
30
|
+
response['negative'] = statistics[0].getValue.to_f / statistics[3].getValue.to_f
|
31
|
+
response['positive'] = statistics[1].getValue.to_f / statistics[3].getValue.to_f
|
32
|
+
response['neutral'] = statistics[2].getValue.to_f / statistics[3].getValue.to_f
|
33
|
+
response['details'] = {}
|
34
|
+
response
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/sentra/version.rb
CHANGED
data/lib/sentra.rb
CHANGED
@@ -5,6 +5,8 @@ require 'trinidad'
|
|
5
5
|
require 'json'
|
6
6
|
require 'sentra/opr'
|
7
7
|
require 'sentra/rest_client'
|
8
|
+
require "sentra/sents"
|
9
|
+
|
8
10
|
|
9
11
|
module Sentra
|
10
12
|
# Your code goes here...
|
@@ -27,40 +29,40 @@ module Sentra
|
|
27
29
|
|
28
30
|
|
29
31
|
post '/sentra/analyzer/atomic' do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
queue = SemanticService::UnixSocketClient.new()
|
46
|
-
queue.writeArticle(article)
|
47
|
-
result = queue.readArticle()
|
48
|
-
|
49
|
-
|
50
|
-
statistics = result.getMetadata('twitter').getFacts()
|
51
|
-
|
52
|
-
response = {}
|
53
|
-
response['negative'] = statistics[0].getValue.to_f / statistics[3].getValue.to_f
|
54
|
-
response['positive'] = statistics[1].getValue.to_f / statistics[3].getValue.to_f
|
55
|
-
response['neutral'] = statistics[2].getValue.to_f / statistics[3].getValue.to_f
|
56
|
-
response['details'] = {}
|
32
|
+
query = request.body.read.to_s
|
33
|
+
query = JSON.parse(query)
|
34
|
+
if params['key'] and params['key'] =="QD3F7Yr2u098RfaB" and query['content']
|
35
|
+
p 'new'
|
36
|
+
processing_client = Sentra::ProcessingClient.new
|
37
|
+
processing_client.prepare_article query['content'], "http://zoral.com.ua", "Test1"
|
38
|
+
response = processing_client.send
|
39
|
+
processing_client.process_result(response).to_json
|
40
|
+
|
41
|
+
elsif params['key'] and params['key'] =="QD3F7Yr2u098RfaB" and not query['content']
|
42
|
+
return "There is no text to process"
|
43
|
+
else
|
44
|
+
return "Not authorized"
|
45
|
+
end
|
46
|
+
end
|
57
47
|
|
58
48
|
|
59
|
-
|
49
|
+
post '/sentra/analyzer/batch' do
|
50
|
+
query = request.body.read.to_s
|
51
|
+
query = JSON.parse(query)
|
52
|
+
if params['key'] and params['key'] =="QD3F7Yr2u098RfaB" and query['tweets']
|
53
|
+
responses = []
|
54
|
+
processing_client = Sentra::ProcessingClient.new
|
55
|
+
query['tweets'].each_with_index do |tweet, index|
|
56
|
+
processing_client.prepare_article tweet['content'], "http://zoral.com.ua/" + index.to_s, "Test" + index.to_s
|
57
|
+
response = processing_client.send
|
58
|
+
responses.push(processing_client.process_result(response))
|
59
|
+
end
|
60
|
+
responses.to_json
|
61
|
+
elsif params['key'] and params['key'] =="QD3F7Yr2u098RfaB" and not query['content']
|
62
|
+
return "There is no text to process"
|
60
63
|
else
|
61
64
|
return "Not authorized"
|
62
65
|
end
|
63
|
-
|
64
66
|
end
|
65
67
|
|
66
68
|
|
@@ -0,0 +1,64 @@
|
|
1
|
+
java_import 'java.util.concurrent.Callable'
|
2
|
+
java_import 'java.util.concurrent.FutureTask'
|
3
|
+
java_import 'java.util.concurrent.LinkedBlockingQueue'
|
4
|
+
java_import 'java.util.concurrent.ThreadPoolExecutor'
|
5
|
+
java_import 'java.util.concurrent.TimeUnit'
|
6
|
+
|
7
|
+
require 'sentra/rest_client'
|
8
|
+
require "sentra/sents"
|
9
|
+
|
10
|
+
|
11
|
+
num_threads = 2
|
12
|
+
host = '5.9.118.83'
|
13
|
+
namespace = 'consolidation'
|
14
|
+
|
15
|
+
tasks = []
|
16
|
+
|
17
|
+
contents = ["Never try.", "It goes down the drain", "The service was good, but coffee was bad", "Sony Inc is a good company"]
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
class CheckLoad
|
22
|
+
def initialize id, contents
|
23
|
+
@id=id
|
24
|
+
@contents = contents
|
25
|
+
end
|
26
|
+
def call
|
27
|
+
puts 'Started Thread Number' + @id.to_s
|
28
|
+
q = {}
|
29
|
+
q['content'] = @contents[@id]
|
30
|
+
puts "Ready to send content = " + q['content']
|
31
|
+
|
32
|
+
url = "http://localhost:4567/sentra/analyzer/atomic?key=QD3F7Yr2u098RfaB"
|
33
|
+
response = RestClient2.post(url, q.to_json)
|
34
|
+
|
35
|
+
json = JSON.parse(response.body)
|
36
|
+
puts "Received response by Thread Number " + @id.to_s
|
37
|
+
p json
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
executor = ThreadPoolExecutor.new(8, # core_pool_treads
|
43
|
+
8, # max_pool_threads
|
44
|
+
60, # keep_alive_time
|
45
|
+
TimeUnit::SECONDS,
|
46
|
+
LinkedBlockingQueue.new)
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
num_threads.times do |i|
|
52
|
+
crawler = CheckLoad.new(i,contents) do |selff|
|
53
|
+
|
54
|
+
end
|
55
|
+
task = FutureTask.new(crawler)
|
56
|
+
executor.execute(task)
|
57
|
+
tasks << task
|
58
|
+
end
|
59
|
+
|
60
|
+
tasks.each do |t|
|
61
|
+
t.get
|
62
|
+
end
|
63
|
+
|
64
|
+
executor.shutdown()
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sentra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kshakirov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -143,8 +143,10 @@ files:
|
|
143
143
|
- lib/sentra.rb
|
144
144
|
- lib/sentra/opr.rb
|
145
145
|
- lib/sentra/rest_client.rb
|
146
|
+
- lib/sentra/sents.rb
|
146
147
|
- lib/sentra/version.rb
|
147
148
|
- sentra.gemspec
|
149
|
+
- tools/multithread_check.rb
|
148
150
|
- tools/remote_check.rb
|
149
151
|
homepage: https://rubygems.org
|
150
152
|
licenses:
|