commentcheck 0.0.28
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 +7 -0
- data/lib/commentcheck.rb +47 -0
- metadata +42 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 544081e0a5f9104cf5551dec59a79fb1958daaa7c84597a96502c9556d3e8a9b
|
4
|
+
data.tar.gz: 66a5d434214628c8266a631c2c0857cf3c6ec4b67c6bcbaed8b990ab3d86be89
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc40f08a2ca2684d15adb010c39eafa617e161d1837b334cfac04fa819c223f394a95b0b25584a7ef4572c1cfdf90cbc2e4597faf981f499e1e558e6348f271e
|
7
|
+
data.tar.gz: ab3784c0911734808213604dbadc50ecb3bfe7ee5125a0c662a0396e4116715bcb7df553e181069a8ad69b6eaa80f03cd5782badfc98e0e69cc505c6892237d4
|
data/lib/commentcheck.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'singleton'
|
3
|
+
class CommentCheck
|
4
|
+
include Singleton
|
5
|
+
def call(text, wordselection)
|
6
|
+
sentiment = analyze(text, wordselection, total=0)
|
7
|
+
sentiment[:type] = sentiment_type(sentiment[:total])
|
8
|
+
sentiment
|
9
|
+
end
|
10
|
+
|
11
|
+
def analyze(review, wordselection, total)
|
12
|
+
#Empty array for results
|
13
|
+
result = Array.new
|
14
|
+
|
15
|
+
#Split review into sepearte words
|
16
|
+
words = review.split
|
17
|
+
#Then for every word check if that word exists in the JSON file of words
|
18
|
+
words.each do |word|
|
19
|
+
|
20
|
+
score = wordselection[word].to_f
|
21
|
+
total += score
|
22
|
+
result << { key: word, score: total}
|
23
|
+
end
|
24
|
+
|
25
|
+
{total: total}
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def sentiment_type(total)
|
30
|
+
case
|
31
|
+
when total < 0
|
32
|
+
'Negative'
|
33
|
+
when total == 0
|
34
|
+
'Neutral'
|
35
|
+
when total > 0
|
36
|
+
'Positive'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def load_file(file)
|
42
|
+
file = JSON.parse(File.read(file))
|
43
|
+
return file
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
metadata
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: commentcheck
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.28
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Graham Lynch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A comment check gem
|
14
|
+
email: graham@email.ie
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/commentcheck.rb
|
20
|
+
homepage: http://rubygems.org/gems/commentcheck
|
21
|
+
licenses: []
|
22
|
+
metadata: {}
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubygems_version: 3.0.3
|
39
|
+
signing_key:
|
40
|
+
specification_version: 4
|
41
|
+
summary: Test to see if a comment is neutral,positive or negative!
|
42
|
+
test_files: []
|