sentra 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d8d483f21abb8eaf76addcfc0345bb2722549b9
4
- data.tar.gz: ffe7191bd480c7cb573618fa3a9f0b23d97a9461
3
+ metadata.gz: 241a9c6f287995d1654cbdc7e60cf34f0d071ee3
4
+ data.tar.gz: a896e4a0c5268d24eab362e0a8f1b1849cc900bf
5
5
  SHA512:
6
- metadata.gz: 04a2502441e48a8a18281f26acb149480a3c17a648131a9e1a66278b2cd7acc073d848c07b10ce7df2fb8b1c7078b7820af8c941bce3ec03419fd79125155288
7
- data.tar.gz: 7b0d4e9f82bd6b4e9067bbe2ede2ec9df7f7a978d846b818e37bd796cb8dcb96ecc1c657c1a434745412b31b7fa875404b21b6706584146ca63d3a5cd55c369d
6
+ metadata.gz: 5bd42236077beb9ed6e3da207fbd00a5a5890afd9fc8a745e7e8acd846817d20207ca51b755b0814366c81b7984e6afcc00d133b634c3319834f42edb1859b02
7
+ data.tar.gz: 752fe0cadf75195e46b08f13d9f8ecb2b49f1176114cf71394ce87200e149552bf717ee278ca77edc0319388d215a104e9ad2e25b09fa549fe9ef8c78f1e1c40
data/lib/sentra/sents.rb CHANGED
@@ -5,7 +5,8 @@ module Sentra
5
5
 
6
6
  p "initializing"
7
7
  end
8
- def prepare_article content, url, title,domain='GENERAL'
8
+
9
+ def prepare_article content, url, title, domain='GENERAL'
9
10
  calendar = Util::Calendar.getInstance();
10
11
  @tweet.setUrl(Net::URL.new(url));
11
12
  @tweet.setDate(calendar.getTime)
@@ -13,6 +14,7 @@ module Sentra
13
14
  @tweet.setChannel(domain)
14
15
  @tweet.setContent(content)
15
16
  end
17
+
16
18
  def send
17
19
 
18
20
  p 'sending'
@@ -27,9 +29,19 @@ module Sentra
27
29
 
28
30
  def process_result statistics
29
31
  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
32
+ # puts 'here statistics'
33
+ # p statistics
34
+ if statistics[3].getValue.to_f > 0
35
+ response['negative'] = statistics[0].getValue.to_f / statistics[3].getValue.to_f
36
+ response['positive'] = statistics[1].getValue.to_f / statistics[3].getValue.to_f
37
+ response['neutral'] = statistics[2].getValue.to_f / statistics[3].getValue.to_f
38
+
39
+ else
40
+ response['negative'] = 0
41
+ response['positive'] = 0
42
+ response['neutral'] = 0
43
+
44
+ end
33
45
  response['details'] = {}
34
46
  response
35
47
  end
@@ -1,3 +1,3 @@
1
1
  module Sentra
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
data/lib/sentra.rb CHANGED
@@ -32,20 +32,28 @@ module Sentra
32
32
 
33
33
  post '/sentra/analyzer/atomic' do
34
34
  query = request.body.read.to_s
35
- query = JSON.parse(query)
35
+ begin
36
+ query = JSON.parse(query)
37
+ rescue Exception => e
38
+ puts 'Error with JSON'
39
+ p query
40
+ p e.message
41
+ query = {}
42
+ query['content'] = nil
43
+ end
36
44
  if params['key'] and params['key'] =="QD3F7Yr2u098RfaB" and query['content']
37
45
  p 'new'
38
46
  processing_client = Sentra::ProcessingClient.new
39
47
  processing_client.prepare_article query['content'],
40
- "http://" +SecureRandom.urlsafe_base64 + ".com/" + SecureRandom.urlsafe_base64,
48
+ "http://" +SecureRandom.urlsafe_base64 + ".com/" + SecureRandom.urlsafe_base64,
41
49
  "Test1"
42
50
  response = processing_client.send
43
51
  begin
44
- processing_client.process_result(response).to_json
52
+ processing_client.process_result(response).to_json
45
53
  rescue Exception => e
46
54
  puts e.message
47
55
  p response
48
- response = {'error'=> e.message}
56
+ response = {'error' => e.message}
49
57
  response.to_json
50
58
  end
51
59
 
@@ -59,19 +67,36 @@ module Sentra
59
67
 
60
68
  post '/sentra/analyzer/batch' do
61
69
  query = request.body.read.to_s
62
- query = JSON.parse(query)
70
+ begin
71
+ query = JSON.parse(query)
72
+ rescue Exception => e
73
+ puts 'Error with JSON'
74
+ p query
75
+ p e.message
76
+ query = nil
77
+ end
63
78
  if params['key'] and params['key'] =="QD3F7Yr2u098RfaB" and query
64
79
  responses = []
65
80
  processing_client = Sentra::ProcessingClient.new
66
- query.each_with_index do |tweet, index|
67
- processing_client.prepare_article tweet['content'],
68
- "http://" + SecureRandom.urlsafe_base64 + ".com/" + SecureRandom.urlsafe_base64,
69
- "Test" + index.to_s
70
- response = processing_client.send
71
- responses.push(processing_client.process_result(response))
81
+ query.each_with_index do |tweet, index|
82
+ begin
83
+ processing_client.prepare_article tweet['content'],
84
+ "http://" + SecureRandom.urlsafe_base64 + ".com/" + SecureRandom.urlsafe_base64,
85
+ "Test" + index.to_s
86
+ response = processing_client.send
87
+ responses.push(processing_client.process_result(response))
88
+ rescue
89
+ puts 'Errors with getting result from socket or queue'
90
+ end
72
91
  end
73
- responses.to_json
74
- elsif params['key'] and params['key'] =="QD3F7Yr2u098RfaB" and not query['content']
92
+ begin
93
+ responses.to_json
94
+ rescue Exception => e
95
+ puts 'Errors with converting result to json'
96
+ p responses
97
+ p e.message
98
+ end
99
+ elsif params['key'] and params['key'] =="QD3F7Yr2u098RfaB" and not query and not query['content']
75
100
  return "There is no text to process"
76
101
  else
77
102
  return "Not authorized"
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.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - kshakirov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-06 00:00:00.000000000 Z
11
+ date: 2015-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler