-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.js
296 lines (269 loc) · 23.8 KB
/
backend.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
var data={
"adult":[
"I couldn’t cry during the flood, but I did beg. Please God, just don’t let my kids lose their home. Because I know what it’s like to not be able to go home",
"This is a story I wrote a couple of years ago, when some young friends were struggling with themselves. Now, it’s different ones having the same issues. Life will feed you some shit sandwiches kids, and you’ll probably do a good job of making your own.",
"Mom called last night to say that when she and my brother went to Good Sam’s yesterday, they found Grandpa John totally naked in the bathroom, his butt basically stuck in the toilet seat, unable to get up",
"Aisha, 15, fled her home with her father and 10-year-old brother, but Boko Haram caught them. The fighters killed her father and, soon after, she watched them strap a bomb to her brother, squeeze him between two militants on a motorbike and speed away.",
"It feels like we are in a moment of momentum, working our way towards something better, however clumsy, messy, and painful the process can be.",
"Like many women, I’ve been disturbed and enraged by the allegations that Hollywood producer Harvey Weinstein has been sexually harassing and assaulting women for decades.",
"It is painfully transparent that people with tiny house budgets often have McMansion dreams",
"when I was five years old, my parents decided they could no longer watch the nightly news. Or rather, they could no longer watch it if I was in earshot.",
"You could say the silence started in Calumet in 1913. Word spread that the doors opened inward, that no one was to blame. What followed was a great quiet, a hundred years of agreed-upon untruth.",
"Most of Marchello’s 12-person crew regularly clocked 120 hours a week—with some logging an occasional 140- or 160-hour week. That meant they worked, ate, and slept while on the well site, though sleep was never a priority",
"Sarah Polley first picked up Alias Grace — Margaret Atwood’s 1996 novel about an Irish servant girl accused of double-homicide in 19th-century Canada — when she was 17 years old",
"In the early Eighties, Andy King, the coach of the Seawolves, a swim club in Danville, California, instructed Debra Denithorne, aged twelve, to do doubles — to practice in the morning and the afternoon. King told Denithorne’s parents that he saw in her the potential to receive a college scholarship, and even to compete in the Olympics.",
"Firefighters estimate that at times, the flames raced 230 feet per second and, inconceivably, threw embers a full mile ahead of the fire front. It moved so fast that chickens, cats and other animals were charred where they stood, left standing like blackened statues.",
"when flood waterwash up memories of a refuse childhood.I couldn’t cry during the flood, but I did beg. Please God, just don’t let my kids die and lose their home. Because I know what it’s like to not be able to go home.”One of my family member is already murdered.",
"when you wish upon a binary star.This is a story I wrote a couple of years ago, when some young friends were struggling with themselves. Now, it’s different ones having the same issues. Life will feed you some shit sandwiches kids, and you’ll probably do a good job of making your own.Because life sucks.",
"The itch and the touch Mom called last night to say that when she and my brother went to Good Sam’s yesterday, they found Grandpa John totally naked in the bathroom, his butt basically stuck in the toilet seat, unable to get up. She found it very ridiculous. She was abducted.",
"What makes a disability undesirable?Who gets to decide if a disability is bad? This is one of the fundamental questions raised by a recent STAT feature on the genetic testing of embryos, which also looks at how that decision is reached.",
"The life and murder of stella walsh, Intersex Olympic Champion.On the night she was murdered, Stella Walsh was in a very bad mood. The Cleveland resident spent much of December 4, 1980, thinking about her two passions: sports and Poland, the country she ran for when she won two Olympic medals. The life there was hell.",
"The Re(selling) of Maria Sharapova To be in the backseat of a car, the cyanotype night on some minor highway, and pass at a distance of one or two hundred yards a rectangle of total green under pooled white lights is to see North American heaven.she absolved her life and acquitted according to her decisions.",
"Men paralyzed by #MeToo: Here’s why you need to speak up-and how Like many women, I’ve been disturbed and enraged by the allegations that Hollywood producer Harvey Weinstein has been sexually harassing and assaulting women for decades.",
"We’re going through hell, and Men need to join us there.It feels like we are in a moment of momentum, working our way towards something better, however clumsy, messy, and painful the process can be. It chokes her being collapsed through the pressure of retro mentality society.",
"Idaho Conservatives are trying to move the American GOP further Right where many conservatives have moved to enjoy a life among like minds in this white, right wing sanctuary. ",
"What we are not talking about when we talk about Tiny house hunters.The episode that really pushed me over the edge was one where a single father was looking to move into a tiny home with his tweenage daughter.",
"Reality shrivels .This is your life now:88 days trapped in bed to save a pregnancy.when I was five years old, my parents decided they could no longer watch the nightly news. Or rather, they could no longer watch it if I was in earshot.",
"How does it feel?An alternative American history,told with folk music.You could say the silence started in Calumet in 1913. Word spread that the doors opened inward, that no one was to blame. What followed was a great quiet, a hundred years of agreed-upon untruth.",
"Burned where they stood:The first nine hours of the California wildfires.Firefighters estimate that at times, the flames raced 230 feet per second and, inconceivably, threw embers a full mile ahead of the fire front. It moved so fast that chickens, cats and other animals were charred where they stood, left standing like blackened statues.",
"What the U.S. Olympic Committee can — and can’t — do about sexual abuse?In the early Eighties, Andy King, the coach of the Seawolves, a swim club in Danville, California, instructed Debra Denithorne, aged twelve, to do doubles — to practice in the morning and the afternoon. King told Denithorne’s parents that he saw in her the potential to receive a college scholarship, and even to compete in the Olympics.",
"What Would Sarah Polley Do? The unorthodox film heroine’s 20-year journey to Alias Grace.Sarah Polley first picked up Alias Grace — Margaret Atwood’s 1996 novel about an Irish servant girl accused of double-homicide in 19th-century Canada — when she was 17 years old"
],
"child":[
"From Jill Talbot’s compelling poem, 8 AM Wednesday: “How are you? I am familiar with the question, but the answer always befuddles me",
"For real, how many of you challenge yourself with this question?Why am I, the way that I am?",
"Sometimes the easiest means of self expression is just to write a story, in the hope that someone reads it in preference to listening.",
"Imagine if you fell into a lake during a freak cold spell, and were frozen in a cryogenic-like state, however the extreme cold across the globe (perhaps the sun burned out?) caused the entire human race to perish, or at least change drastically.",
"The motto at Anne-Marie Bonneau’s ethical-cooking blog: “No packaging. Nothing processed. No waste",
"Describing life is a waste is not totally waste if you look at it clearly.",
"Who gets to decide if a disability is bad? This is one of the fundamental questions raised by a recent STAT feature on the genetic testing of embryos, which also looks at how that decision is reached.",
"The Cleveland resident spent much of December 4, 1980, thinking about her two passions: sports and Poland, the country she ran for when she won two Olympic medals.",
"To be in the backseat of a car, the cyanotype night on some minor highway, and pass at a distance of one or two hundred yards a rectangle of total green under pooled white lights is to see North American heaven.",
" where many conservatives have moved to enjoy a life among like minds in this white, right wing sanctuary",
"The episode that really pushed me over the edge was one where a single father was looking to move into a tiny home with his tweenage daughter.",
"Western North Dakota—at the epicenter of the Bakken oil rush—has become a new Wild West of sorts, where fortunes are made, sought and lost with alarming speed. Thousands have been drawn to the Bakken over the last seven years, including Maya Rao, a talented reporter who has cut her teeth at dailies and currently covers regional issues at the Minneapolis Star Tribune.",
"2.8am Wednesday by jill tabot From Jill Talbot’s compelling poem, 8 AM Wednesday: “How are you? I am familiar with the question, but the answer always befuddles me.It was very beautiful and flawless poetry.",
"claim your life.Now.For real, how many of you challenge yourself with this question?Why am I, the way that I am? How can our life which is becoming more dangerous can be saved from getting screwed up?",
"Brown paper packages, tied up with instrument strings.Sometimes the easiest means of self expression is just to write a beautiful story, in the hope that someone good will read it in preference to listening",
"The difference engine and the afternaut.Imagine if you fell into a lake during a freak cold spell, and were frozen in a cryogenic-like state, however the extreme cold across the globe (perhaps the sun burned out?) caused the entire human race to perish, or at least change drastically.",
"The zero waste chef The motto at Anne-Marie Bonneau’s ethical-cooking blog: “No packaging. Nothing processed. ALL good, nice things. Some awesome are supposed to happen.",
"Bike packing Iceland: life in the wastes.Describing life is a waste is not totally waste if you look at it clearly.",
"The teen girls who defied Boko Haram Aisha, 15, fled her home with her father and 10-year-old brother, but Boko Haram caught them. The fighters killed her father and, soon after, she watched them strap a bomb to her brother, squeeze him between two militants on a motorbike and speed away. Getting abondened ,abusive is the worst.",
"We’re going through hell, and Men need to join us there.It feels like we are in a moment of momentum, working our way towards something better, however clumsy, messy, and painful the process can be. It chokes her being collapsed through the pressure of retro mentality society.",
"Tiny House Hunters’ and the shrinking American dream It is painfully transparent that people with tiny house budgets often have McMansion dreams"
]
}
// function start()
// {
// sentiment = new Sentimood();
// var str=document.getElementById("text").value;
// console.log(sentiment.positivity(str).score,sentiment.positivity(str).words);
// console.log(sentiment.negativity(str).score,sentiment.negativity(str).words);
// console.log(JSON.stringify(sentiment.analyze(str)));
// analyse1=sentiment.analyze(str);
// var bayes= new Classifier();
// bayes.train("It's been a long time since I've posted anything. I have a three year old son now who is amazing! The reason I'm posting is that I've always looked at this blog as part of my therapy, a form of healing. I have been doing overall ok the last few years. I suffer from anxiety still but I can manage it well enough. But lately something has changed, I haven't been able to get a handle on her panic and anxiety. All of a sudden I'm having away nightmares again and I constantly have that feeling of panic and tension which I haven't felt this strongly in years. The only thing I figure is that I went back to study and was doing amazing there, I loved it but due to cutbacks the childcare was closed down suddenly and I can no longer continue my studies. It was very sudden and really unfair on everyone affected. Anyway I feel like the rug was pulled from under me and it seems to have kickstarted this reaction from me. At this stage I think the thing that started it seems to have passed but I'm still hanging on to the feelings and the panic is getting worse. It's very frustrating, I can't seem to switch it off!!", "Adult");
// bayes.train("Tomorrow is 3 years since it happened.I have come so far and have my life back, I have a wonderful fiance and the most beautiful baby boy however unfortunately I find that tonight I'm fighting a panic attack. I haven't needed to write in a long time but tonight I can't sleep and writing always helps me get everything out of my head. It reminds me that I'll always be living with this. At least now though I can live with it and I can honestly say I am a stronger person now. I also have an appreciation for what's important and most of all I have this beautiful little boy who I love more than I could ever explain so go away panic attack your not welcome in my head. I an surviving and thriving!", "Adult");
// bayes.train("I have the craziest most bizarre story, so in my last post I wrote about it coming up to 2 years since I was raped. On the day of the 2nd anniversary we found out I'm pregnant!I was dreading the day and thinking, I just want it to be over, I was expecting a bad nights sleep the whole lot and I was feeling pretty down about it until.....Myself and himself were talking and I realized I was late, I put it down to the stress of the time of year as I could feel my period coming, I had a test in my room so I said to him will I take one for the laugh, he had never seen one work before so he said yes, both of us completely relaxed as we were 100% sure I wasn't. So off I went and peed on a stick and within seconds it came up positive, I was so shocked I just showed it to him, he thought I was joking! I made him go and buy another 2 tests and I took them and they were positive.I still couldn't believe it the next morning so I took another 2 and they were positive!! I went to the doctor and she confirmed it. I don't want to get ahead of myself but it just feels so foreign and overwhelming to have nice things happen for a change.I'm so used to things being horrible that I'm scared something will go wrong", "Adult");
// bayes.train("Paris was the most beautiful place on Earth I have ever visited so far. I didn’t expect it to be that stunning especially as it was only an hour flight from Bristol airport but god did it take my breath. It was one of those trips that really set my mind on how my life is doing, it’s still pretty shit but you know what, I’m going to be out of this small town in a few years and I won’t have to stay in contact with the people who have ruined my perspective on love and lifeSaying that probably makes you think I’ve broken up with Reece. I haven’t, we are perfectly happy at the moment together. And I’m really lucky to have him which was shown when missing him while I was away in Paris.The world has a lot of bull shit in it, a ton load and at the moment, I only have a few people in my life who I would consider to be close with and I need to realise that’s all I need.","Children")
// bayes.train("It's the digital age, baby. Kids are learning how to use technology at younger and younger ages, and, in turn, are kick starting their blogging careers well before they are able to vote. Check out the blogs of these rad kids under the age of 18. (We wish we were this cool during puberty.)","Children")
// bayes.train("This blog was created by Eva Baker at the age of 16 after she tuned into a conversation of her mom and Dave Ramsey. Eva writes about how to spend smart and save better. She hopes to inspire Childrens to make smart financial choices. You can find a place for yourself on her site whether you're in school or college, and thinking of saving or drowning in debt. She even has articles for college prep — whether to take the ACT, how to find volunteer work to beef up your application, etc.","Children");
// bayes.train("Holly Fratter and her mom Sam created a fantastic blog where they give reviews about children books. Instantly I liked this blog where mother and daughter are both writing their different perspectives about books. Reading is their big and mutual love and they decided to share it with all of us. It is always great to see how little ones enjoy reading and developing critical opinion on what they have read!","Children");
// bayes.train("Hagan, 7-year-old boy from Iowa, isn’t afraid to share anything from his life with you. He loves writing about his travels and adventures! Hagan Miller loves animals, sports and telling stories about his young life. His big and exciting trip to Alaska with his parents was inspiration for many of his blogs where Hagan delightfully wrote about how great it was for him to have had that experience!","Children");
// bayes.train("etsy Lou is one of the youngest children bloggers in United Kingdom. Her parents are bloggers for many years now and Betsy grew up watching them write their blogs until she eventually came with an idea to have her own. That is how it all started. In her writing, Betsy wants to share everything that makes her happy in life and write about the things she is enjoying in school. She is also writing poems about everyday things that surround her.","Children");
// bayes.probabilities();
// let results = bayes.guess("Yesterday, I was very very happy, so happy.");
// console.log(JSON.stringify(results));
// // console.log(bayes.guess(str));
// }
// document.onload=function(){
// new Chart(document.getElementById("pie-chart"),
// {
// type: 'pie',
// data:
// {
// labels: ["POSITIVE", "NEGATIVE", "NEUTRAL", "AMAN", "AGARWAL"],
// datasets: [
// {
// labels: "YEH NAI CHAL RAHA",
// backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
// data: [20,40,20,40,20]
// }
// ]
// },
// options:
// {
// title:
// {
// display: true,
// text: 'Analysis on News'
// }
// }
// });
// };
// {
// "score":8,
// "comparative":-1,
// "positive":
// {
// "score":12,
// "comparative":3,
// "words":["good","better","best","awesome"]
// },
// "negative":
// {
// "score":4,
// "comparative":4,
// "words":["fuck"]
// }
// }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
var bayes= new Classifier();
data.adult.forEach(
function(element)
{
bayes.train(element,"adult");
}
);
data.child.forEach(
function(element)
{
bayes.train(element,"child");
}
);
bayes.probabilities();
function start()
{
var str=document.getElementById("text").value;
var sentiment = new Sentimood();
// console.log(sentiment.positivity(str).score,sentiment.positivity(str).words);
// console.log(sentiment.negativity(str).score,sentiment.negativity(str).words);
// console.log(JSON.stringify(sentiment.analyze(str)));
new Chart(document.getElementById("myChart"), {
type: 'bar',
data: {
labels: ["Positive", "Negative", "Overall"],
datasets: [
{
backgroundColor: ["#3e95cd", "#8e5ea2","#ffffff"],
data: [
sentiment.positivity(str).score,
sentiment.negativity(str).score,
sentiment.analyze(str).comparative
]
}
]
},
options: {
hover:
{
mode:null
},
scales:
{
yAxes: [{
display: true,
ticks: {
beginAtZero: true,
steps: 0.5,
stepValue: 0.5,
max: 10,
min:-10
}
}]
},
animation:{
duration:0
},
legend: { display: false },
title: {
display: true,
text: 'Comparison of absolute Score of Positive and negative words'
}
}
});
new Chart(document.getElementById("myChart1"), {
type: 'bar',
data: {
labels: ["POSITIVE", "NEGATIVE",'OVERALL SCORE'],
datasets: [{
backgroundColor: ["#3e95cd", "#8e5ea2","#ffffff"],
data: [
sentiment.positivity(str).comparative,
sentiment.negativity(str).comparative,
sentiment.analyze(str).comparative
]
},
]
},
options: {
grid:
{
color:"#ffffff",
display:true
},
hover:
{
mode:null
},
legend:
{
display:false
},
scales:
{
yAxes: [{
display: true,
ticks: {
beginAtZero: true,
steps: 0.5,
stepValue: 0.5,
max:5,
min:-5
}
}]
},
animation:{
duration:0
},
title:
{
display: true,
text: 'Comparison of comparative Score of Positive and negative words'
}
}
});
document.getElementsByClassName("list")[0].innerHTML="The list of positive word is: "+sentiment.positivity(str).words;
document.getElementsByClassName("list")[0].innerHTML+="<br>The list of negative words is: "+ sentiment.negativity(str).words;
console.log(bayes.guess(str))
var ctx = document.getElementById("pie-chart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'pie',
data: {
labels: ["Adult", "Child"],
options:
{
animation:{
duration:0
}
},
datasets: [{
backgroundColor: [
"#3498db",
"#e74c3c",
],
data: [bayes.guess(str).adult.probability,bayes.guess(str).child.probability]
}]
}
});
}