-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_functions.py
2575 lines (2184 loc) · 151 KB
/
common_functions.py
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import numpy as np
import time
import multiprocessing
import itertools
import csv
import os
import os.path
import spacy
from collections import Counter
from datetime import datetime
import pandas as pd
import operator
import getpass
from nltk.corpus import sentiwordnet as swn
from pathlib import Path
import re
from sentence_splitter import SentenceSplitter, split_text_into_sentences
import sys
# THIS IS TO IMPORT FILES FROM A DIFFERENT FOLDER
base_dir = os.getcwd()
pathResourcesFolder = os.path.join(base_dir, "Resources")
#pathResourcesFolder = "/DATA/Resources/"
sys.path.insert(0, pathResourcesFolder)
import senticnet5
import senti_bignomics
#
#
#import pysentiment as ps # https://github.com/hanzhichao2000/pysentiment
base_dir = os.getcwd()
pathResourcesFolder = os.path.join(base_dir, "Resources")
pathResourcesFolder = os.path.join(pathResourcesFolder, "pyss")
sys.path.insert(0, pathResourcesFolder)
import pyss as ps # https://github.com/hanzhichao2000/pysentiment
# intialize harvard and macdonald
hiv4 = ps.HIV4()
lmac = ps.LM()
#
#
#import moral resources
base_dir = os.getcwd()
input_liberty = os.path.join(os.path.join(os.path.join(base_dir, "Resources"), "liberty"), "cs_lexicon_final.csv")
df_liberty = pd.read_csv(input_liberty, sep=",", header=0, encoding='utf-8')
a_scale, b_scale = -1, 1
x_scale, y_scale = df_liberty.score.min(), df_liberty.score.max()
df_liberty["scoreRescaled"] = (df_liberty.score - x_scale) / (y_scale - x_scale) * (b_scale - a_scale) + a_scale
#print(df_liberty["scoreRescaled"].max())
#print(df_liberty["scoreRescaled"].min())
#
input_authority = os.path.join(os.path.join(os.path.join(base_dir, "Resources"), "moralstrength_annotations"), "authority.tsv")
df_authority = pd.read_csv(input_authority, sep="\t", header=0, encoding='utf-8')
a_scale, b_scale = -1, 1
x_scale, y_scale = df_authority.EXPRESSED_MORAL.min(), df_authority.EXPRESSED_MORAL.max()
df_authority["scoreRescaled"] = (df_authority.EXPRESSED_MORAL - x_scale) / (y_scale - x_scale) * (b_scale - a_scale) + a_scale
#print(df_authority["scoreRescaled"].max())
#print(df_authority["scoreRescaled"].min())
#
input_care = os.path.join(os.path.join(os.path.join(base_dir, "Resources"), "moralstrength_annotations"), "care.tsv")
df_care = pd.read_csv(input_care, sep="\t", header=0, encoding='utf-8')
a_scale, b_scale = -1, 1
x_scale, y_scale = df_care.EXPRESSED_MORAL.min(), df_care.EXPRESSED_MORAL.max()
df_care["scoreRescaled"] = (df_care.EXPRESSED_MORAL - x_scale) / (y_scale - x_scale) * (b_scale - a_scale) + a_scale
#print(df_care["scoreRescaled"].max())
#print(df_care["scoreRescaled"].min())
#
input_fairness = os.path.join(os.path.join(os.path.join(base_dir, "Resources"), "moralstrength_annotations"), "fairness.tsv")
df_fairness = pd.read_csv(input_fairness, sep="\t", header=0, encoding='utf-8')
a_scale, b_scale = -1, 1
x_scale, y_scale = df_fairness.EXPRESSED_MORAL.min(), df_fairness.EXPRESSED_MORAL.max()
df_fairness["scoreRescaled"] = (df_fairness.EXPRESSED_MORAL - x_scale) / (y_scale - x_scale) * (b_scale - a_scale) + a_scale
#print(df_fairness["scoreRescaled"].max())
#print(df_fairness["scoreRescaled"].min())
#
input_loyalty = os.path.join(os.path.join(os.path.join(base_dir, "Resources"), "moralstrength_annotations"), "loyalty.tsv")
df_loyalty = pd.read_csv(input_loyalty, sep="\t", header=0, encoding='utf-8')
a_scale, b_scale = -1, 1
x_scale, y_scale = df_loyalty.EXPRESSED_MORAL.min(), df_loyalty.EXPRESSED_MORAL.max()
df_loyalty["scoreRescaled"] = (df_loyalty.EXPRESSED_MORAL - x_scale) / (y_scale - x_scale) * (b_scale - a_scale) + a_scale
#print(df_loyalty["scoreRescaled"].max())
#print(df_loyalty["scoreRescaled"].min())
#
input_purity = os.path.join(os.path.join(os.path.join(base_dir, "Resources"), "moralstrength_annotations"), "purity.tsv")
df_purity = pd.read_csv(input_purity, sep="\t", header=0, encoding='utf-8')
a_scale, b_scale = -1, 1
x_scale, y_scale = df_purity.EXPRESSED_MORAL.min(), df_purity.EXPRESSED_MORAL.max()
df_purity["scoreRescaled"] = (df_purity.EXPRESSED_MORAL - x_scale) / (y_scale - x_scale) * (b_scale - a_scale) + a_scale
#print(df_purity["scoreRescaled"].max())
#print(df_purity["scoreRescaled"].min())
#
#
def putSpace(input):
#e.g. input = "Text1. Text2.Text3."
rx = r"\.(?=\S)"
result = re.sub(rx, ". ", input)
result = re.sub(rx, ": ", input)
#print(result)
togiveout = result.replace(" "," ")
togiveout = togiveout.replace(" ", " ")
return togiveout
def split_into_sentences(text, lang):
sentences = split_text_into_sentences(text, lang.lower())
return sentences
def safe_string_cast_to_numerictype(val, to_type, default = None):
try:
return to_type(val)
except (ValueError, TypeError):
return default
def FeelIt(tlemma, tpos=None, tokentlemma=None, PrintScr=False, UseSenticNet=False,UseSentiWordNet=False,UseFigas=False,UseLiberty=False, UseAuthority=False, UseCare=False, UseFairness=False, UseLoyalty=False, UsePurity=False):
computed_polarity = 0.0
if ((UseLiberty == True) or (UseAuthority == True) or (UseCare == True) or (UseFairness == True) or (UseLoyalty == True) or (UsePurity == True)) :
# if DEBUG:
# print("moral polarity computation with FeelIt")
liberty_polarity = 0.0
if (UseLiberty == True):
if df_liberty is not None:
if not df_liberty.empty:
if tokentlemma and (df_liberty.loc[df_liberty['word'] == tokentlemma, 'scoreRescaled'].empty == False):
liberty_polarity = df_liberty.loc[df_liberty['word'] == tokentlemma, 'scoreRescaled'].iloc[0]
elif df_liberty.loc[df_liberty['word'] == tlemma, 'scoreRescaled'].empty == False:
liberty_polarity = df_liberty.loc[df_liberty['word'] == tlemma, 'scoreRescaled'].iloc[0]
else:
liberty_polarity = 0.0
authority_polarity = 0.0
if (UseAuthority == True):
if df_authority is not None:
if not df_authority.empty:
if tokentlemma and (df_authority.loc[df_authority['LEMMA'] == tokentlemma, 'scoreRescaled'].empty == False):
authority_polarity = df_authority.loc[df_authority['LEMMA'] == tokentlemma, 'scoreRescaled'].iloc[0]
elif df_authority.loc[df_authority['LEMMA'] == tlemma, 'scoreRescaled'].empty == False:
authority_polarity = df_authority.loc[df_authority['LEMMA'] == tlemma, 'scoreRescaled'].iloc[0]
else:
authority_polarity = 0.0
care_polarity = 0.0
if (UseCare == True):
if df_care is not None:
if not df_care.empty:
if tokentlemma and (df_care.loc[df_care['LEMMA'] == tokentlemma, 'scoreRescaled'].empty == False):
care_polarity = df_care.loc[df_care['LEMMA'] == tokentlemma, 'scoreRescaled'].iloc[0]
elif df_care.loc[df_care['LEMMA'] == tlemma, 'scoreRescaled'].empty == False:
care_polarity = df_care.loc[df_care['LEMMA'] == tlemma, 'scoreRescaled'].iloc[0]
else:
care_polarity = 0.0
fairness_polarity = 0.0
if (UseFairness == True):
if df_fairness is not None:
if not df_fairness.empty:
if tokentlemma and (
df_fairness.loc[df_fairness['LEMMA'] == tokentlemma, 'scoreRescaled'].empty == False):
fairness_polarity = df_fairness.loc[df_fairness['LEMMA'] == tokentlemma, 'scoreRescaled'].iloc[0]
elif df_fairness.loc[df_fairness['LEMMA'] == tlemma, 'scoreRescaled'].empty == False:
fairness_polarity = df_fairness.loc[df_fairness['LEMMA'] == tlemma, 'scoreRescaled'].iloc[0]
else:
fairness_polarity = 0.0
loyalty_polarity = 0.0
if (UseLoyalty == True):
if df_loyalty is not None:
if not df_loyalty.empty:
if tokentlemma and (df_loyalty.loc[df_loyalty['LEMMA'] == tokentlemma, 'scoreRescaled'].empty == False):
loyalty_polarity = df_loyalty.loc[df_loyalty['LEMMA'] == tokentlemma, 'scoreRescaled'].iloc[0]
elif df_loyalty.loc[df_loyalty['LEMMA'] == tlemma, 'scoreRescaled'].empty == False:
loyalty_polarity = df_loyalty.loc[df_loyalty['LEMMA'] == tlemma, 'scoreRescaled'].iloc[0]
else:
loyalty_polarity = 0.0
purity_polarity = 0.0
if (UsePurity == True):
if df_purity is not None:
if not df_purity.empty:
if tokentlemma and (df_purity.loc[df_purity['LEMMA'] == tokentlemma, 'scoreRescaled'].empty == False):
purity_polarity = df_purity.loc[df_purity['LEMMA'] == tokentlemma, 'scoreRescaled'].iloc[0]
elif df_purity.loc[df_purity['LEMMA'] == tlemma, 'scoreRescaled'].empty == False:
purity_polarity = df_purity.loc[df_purity['LEMMA'] == tlemma, 'scoreRescaled'].iloc[0]
else:
purity_polarity = 0.0
###########
x = [liberty_polarity, authority_polarity, care_polarity, fairness_polarity, loyalty_polarity, purity_polarity]
denom_for_average = sum(j != 0 for j in x)
num_for_average = sum(x)
computed_polarity = 0
if denom_for_average != 0:
computed_polarity = num_for_average / denom_for_average
### print("end moral polarity computation")
elif ((UseSenticNet == True) or (UseSentiWordNet == True) or (UseFigas == True) ):
# if DEBUG:
# print("sentiment polarity computation with FeelIt")
valstr = ""
senti_bignomics_sentiment = 0.0
if UseFigas==True:
tosearcsenticnet = tlemma.lower().replace(" ", "_")
sentibignomicsitem = senti_bignomics.senti_bignomics.get(tosearcsenticnet)
if sentibignomicsitem and sentibignomicsitem[0]:
valstr = sentibignomicsitem[0]
senti_bignomics_sentiment = safe_string_cast_to_numerictype(valstr, float, 0)
#computed_polarity = senti_bignomics_sentiment
#return computed_polarity
# n - NOUN
# v - VERB
# a - ADJECTIVE
# s - ADJECTIVE SATELLITE
# r - ADVERB
if tpos == "NOUN":
posval = "n"
elif tpos == "VERB":
posval = "v"
elif tpos == "ADJ":
posval = "a"
elif tpos == "ADV":
posval = "r"
else:
posval = "n"
#(sentibignomicsitem == False or sentibignomicsitem[0]==False)
#(senti_bignomics_sentiment == 0)
avgscSWN = 0
if (UseSentiWordNet==True) or ((UseSentiWordNet==False) and ((UseFigas==True) and ((not valstr) or valstr == ""))):
try:
llsenses_pos = list(swn.senti_synsets(tlemma.lower(), posval))
except:
llsenses_pos = []
if llsenses_pos and len(llsenses_pos) > 0:
for thistimescore in llsenses_pos:
avgscSWN = thistimescore.pos_score() - thistimescore.neg_score()
if avgscSWN != 0:
break
if avgscSWN == 0 and posval == "a":
posval = "s"
try:
llsenses_pos = list(swn.senti_synsets(tlemma.lower(), posval))
except:
llsenses_pos = []
if llsenses_pos and len(llsenses_pos) > 0:
for thistimescore in llsenses_pos:
avgscSWN = thistimescore.pos_score() - thistimescore.neg_score()
if avgscSWN != 0:
break
sentic_sentiment = 0
if UseSenticNet == True:
tosearcsenticnet = tlemma.lower().replace(" ", "_")
senticitem = senticnet5.senticnet.get(tosearcsenticnet)
if senticitem and senticitem[7]:
valstr = senticitem[7]
sentic_sentiment = safe_string_cast_to_numerictype(valstr, float, 0)
#if sentic_sentiment != 0:
# computed_polarity = (sentic_sentiment + avgscSWN) / 2
#else:
# computed_polarity = avgscSWN
###########
x = [sentic_sentiment, avgscSWN, senti_bignomics_sentiment]
denom_for_average = sum(j != 0 for j in x)
num_for_average = sum(x)
# denom_for_average = 0
# num_for_average = 0.0
# if sentic_sentiment != 0:
# denom_for_average=denom_for_average+1
# num_for_average = sentic_sentiment
# if avgscSWN != 0:
# denom_for_average = denom_for_average + 1
# num_for_average = avgscSWN
# if senti_bignomics_sentiment !=0:
# denom_for_average = denom_for_average + 1
# num_for_average = senti_bignomics_sentiment
computed_polarity = 0
if denom_for_average != 0:
computed_polarity = num_for_average / denom_for_average
### print("end sentiment polarity computation")
else:
print("\n!!!ERROR!!! THIS IS NOT POSSIBLE, AT LEAST ONE OPTION SHOULD BE ENABLED, THERE IS SOME MISTAKE...CHECK IT...EXITING NOW")
sys.exit()
return computed_polarity
def FeelIt_OverallSentiment(toi, PrintScr=False, UseSenticNet=False, UseSentiWordNet=False, UseFigas=True, ComputeWithMacDonaldOnly=False, ComputeWithHarvardOnly=False, UseLiberty=False, UseAuthority=False, UseCare=False, UseFairness=False, UseLoyalty=False, UsePurity=False):
sentim_all = 0.0
if (ComputeWithMacDonaldOnly==True) or (ComputeWithHarvardOnly == True):
sentim_LMD = 0.0
if ComputeWithMacDonaldOnly == True:
# MACDONALD OVERALL SENTIMENT CALCULATION:
if PrintScr == True:
print("MACDONALD OVERALL SENTIMENT CALCULATION on FeelIt_Overall")
countsss = 0
wc_mac=0
for xin in toi.sent:
if (xin.pos_ == "ADJ") | (xin.pos_ == "ADV") | (xin.pos_ == "NOUN") | (xin.pos_ == "PROPN") | (
xin.pos_ == "VERB"):
countsss = countsss + 1
tlemma=xin.lemma_.lower()
# compute with mcdonald
# listtlemma = lmac.tokenize(tlemma) # text can be tokenized by other ways
listtlemma = [tlemma]
lmacscore = lmac.get_score(listtlemma)['Polarity']
if lmacscore and lmacscore!=0:
if lmacscore>0:
wc_mac=wc_mac+1
else:
wc_mac=wc_mac-1
if wc_mac!=0 and countsss>0:
sentim_LMD = wc_mac/countsss
# END MACDONALD OVERALL SENTIMENT CALCULATION:
sentim_HARVARD = 0.0
if ComputeWithHarvardOnly == True:
# HARVARD OVERALL SENTIMENT CALCULATION:
if PrintScr == True:
print("HARVARD OVERALL SENTIMENT CALCULATION on FeelIt_Overall")
countsss = 0
wc_hv = 0
for xin in toi.sent:
if (xin.pos_ == "ADJ") | (xin.pos_ == "ADV") | (xin.pos_ == "NOUN") | (xin.pos_ == "PROPN") | (
xin.pos_ == "VERB"):
countsss = countsss + 1
tlemma = xin.lemma_.lower()
# compute with mcdonald
# listtlemma = lmac.tokenize(tlemma) # text can be tokenized by other ways
listtlemma = [tlemma]
hvscore = hiv4.get_score(listtlemma)['Polarity']
if hvscore and hvscore != 0:
if hvscore > 0:
wc_hv = wc_hv + 1
else:
wc_hv = wc_hv- 1
if wc_hv != 0 and countsss>0:
sentim_HARVARD = wc_hv / countsss
# END HARVARD OVERALL SENTIMENT CALCULATION
x = [sentim_LMD, sentim_HARVARD]
denom_for_average = sum(j != 0 for j in x)
num_for_average = sum(x)
sentim_all = 0
if denom_for_average != 0:
sentim_all = num_for_average / denom_for_average
else:
# FIGAS OVERALL SENTIMENT CALCULATION:
if PrintScr == True:
print("FIGAS OVERALL POLARITY CALCULATION on FeelIt_Overall")
countsss = 0
for xin in toi.sent:
if (xin.pos_ == "ADJ") | (xin.pos_ == "ADV") | (xin.pos_ == "NOUN") | (xin.pos_ == "PROPN") | (
xin.pos_ == "VERB"):
sentim_app = FeelIt(xin.lemma_.lower(), xin.pos_, xin, UseSenticNet=UseSenticNet, UseSentiWordNet=UseSentiWordNet, UseFigas=UseFigas, UseLiberty=UseLiberty, UseAuthority=UseAuthority, UseCare=UseCare, UseFairness=UseFairness, UseLoyalty=UseLoyalty, UsePurity=UsePurity)
if sentim_app != 0.0:
countsss = countsss + 1
sentim_all = sentim_all + sentim_app
if countsss > 0:
sentim_all = sentim_all / countsss
# END FIGAS OVERALL SENTIMENT CALCULATION
return sentim_all
def PREP_token_IE_parsing(xin, singleNOUNs, singleCompoundedHITS, singleCompoundedHITS_toEXCLUDE, filterNOUNs,
filterCOMPOUNDs,
LOCATION_SYNONYMS_FOR_HEURISTIC, VERBS_TO_KEEP, COMPUTE_OVERALL_POLARITY_SCORE, minw, maxw,
FoundVerb, t, nountoskip=None, previousprep=None, UseSenticNet=False, UseSentiWordNet=False,
UseFigas=True, UseLiberty=False, UseAuthority=False, UseCare=False, UseFairness=False, UseLoyalty=False, UsePurity=False):
listOfPreps = []
listOfPreps_sentim = []
lxin_n = [x for x in xin.lefts]
rxin_n = [x for x in xin.rights]
if lxin_n:
for xinxin in lxin_n:
if xinxin.dep_ == "pobj" and xinxin.pos_ == "NOUN" and IsInterestingToken(
xinxin) and xinxin.lemma_.lower() != t.lemma_.lower():
if (nountoskip):
if xinxin.lemma_.lower() == nountoskip.lemma_.lower():
continue
print(
"...DEBUG NOUN ITERATE from PREP {}, {}: pos:{}, tag:{} - coming from Noun: {} ".format(
xinxin.dep_,
xinxin.lemma_,
xinxin.pos_,
xinxin.tag_,
t.lemma_,
))
minw = min(minw, xinxin.i)
maxw = max(maxw, xinxin.i)
other_list_NOUN, sentilist, minw, maxw = NOUN_token_IE_parsing(xinxin, singleNOUNs,
singleCompoundedHITS,
singleCompoundedHITS_toEXCLUDE,
filterNOUNs,
filterCOMPOUNDs,
LOCATION_SYNONYMS_FOR_HEURISTIC,
VERBS_TO_KEEP,
COMPUTE_OVERALL_POLARITY_SCORE,
minw=minw, maxw=maxw,
verbtoskip=FoundVerb, nountoskip=t, UseSenticNet=UseSenticNet,
UseSentiWordNet=UseSentiWordNet, UseFigas=UseFigas, UseLiberty=UseLiberty, UseAuthority=UseAuthority, UseCare=UseCare, UseFairness=UseFairness, UseLoyalty=UseLoyalty, UsePurity=UsePurity)
sentim_noun = FeelIt(xinxin.lemma_.lower(), xinxin.pos_, xinxin, UseSenticNet=UseSenticNet,
UseSentiWordNet=UseSentiWordNet, UseFigas=UseFigas, UseLiberty=UseLiberty, UseAuthority=UseAuthority, UseCare=UseCare, UseFairness=UseFairness, UseLoyalty=UseLoyalty, UsePurity=UsePurity)
if other_list_NOUN and len(other_list_NOUN) > 0:
listNoun_app = []
FoundNounInlist = "___" + xinxin.lemma_.lower()
for modin in other_list_NOUN:
FoundNounInlist = FoundNounInlist + "___" + modin
listNoun_app.append(FoundNounInlist)
other_list_NOUN = listNoun_app
listOfPreps.extend(other_list_NOUN)
else:
FoundNounInlist = "___" + xinxin.lemma_.lower() + "___"
listOfPreps.append(FoundNounInlist)
if sentilist and len(sentilist) > 0:
print(" sentilist: ")
print(sentilist)
for sentin in sentilist:
if sentin != 0:
if sentim_noun == 0:
sentim_noun = sentin
else:
if (sentim_noun > 0 and sentin < 0) or (
sentim_noun < 0 and sentin > 0): # they have different signes, I just sum them up
sentim_noun = np.sign(sentin) * np.sign(sentim_noun) * (
abs(sentim_noun) + (1 - abs(sentim_noun)) * abs(
sentin)) # change the sign and increase it
else: # they have same sign
sentim_noun = np.sign(sentim_noun) * (
abs(sentim_noun) + (1 - abs(sentim_noun)) * abs(
sentin)) # increase it
listOfPreps_sentim.append(sentim_noun)
print(
"...DEBUG END NOUN ITERATE from PREP {}, {}: pos:{}, tag:{} - coming from Noun: {} - sentiment={}".format(
xinxin.dep_,
xinxin.lemma_,
xinxin.pos_,
xinxin.tag_,
t.lemma_, sentim_noun
))
elif xinxin.dep_ == "pcomp" and xinxin.pos_ == "VERB" and xinxin.lemma_.lower() != t.lemma_.lower(): # and (xinxin.tag_ == "VB" or xinxin.tag_ == "VBG" or xinxin.tag_ == "VBP" or xinxin.tag_ == "VBZ" )
print(
"...DEBUG VERB ITERATE from PREP {}, {}: pos:{}, tag:{} - coming from Noun: {} ".format(
xinxin.dep_,
xinxin.lemma_,
xinxin.pos_,
xinxin.tag_,
t.lemma_,
))
minw = min(minw, xinxin.i)
maxw = max(maxw, xinxin.i)
iterated_list_VERB, list_verbs_sentim_app, minw, maxw = VERB_token_IE_parsing(xinxin, singleNOUNs,
singleCompoundedHITS,
singleCompoundedHITS_toEXCLUDE,
filterNOUNs,
filterCOMPOUNDs,
LOCATION_SYNONYMS_FOR_HEURISTIC,
VERBS_TO_KEEP,
COMPUTE_OVERALL_POLARITY_SCORE,
t, minw, maxw,
nountoskip=nountoskip,
previousverb=FoundVerb,
UseSenticNet=UseSenticNet,
UseSentiWordNet=UseSentiWordNet,
UseFigas=UseFigas,
UseLiberty=UseLiberty, UseAuthority=UseAuthority, UseCare=UseCare, UseFairness=UseFairness, UseLoyalty=UseLoyalty, UsePurity=UsePurity
)
if iterated_list_VERB and len(iterated_list_VERB) > 0:
listOfPreps.extend(iterated_list_VERB)
if list_verbs_sentim_app and len(list_verbs_sentim_app) > 0:
listOfPreps_sentim.extend(list_verbs_sentim_app)
elif xinxin.dep_ == "prep" and xinxin.pos_ == "ADP":
if (previousprep):
if xinxin.lemma_.lower() == previousprep.lemma_.lower():
continue
minw = min(minw, xinxin.i)
maxw = max(maxw, xinxin.i)
iterated_list_prep, iterated_list_prep_sentim, minw, maxw = PREP_token_IE_parsing(xinxin, singleNOUNs,
singleCompoundedHITS,
singleCompoundedHITS_toEXCLUDE,
filterNOUNs,
filterCOMPOUNDs,
LOCATION_SYNONYMS_FOR_HEURISTIC,
VERBS_TO_KEEP,
COMPUTE_OVERALL_POLARITY_SCORE,
minw=minw, maxw=maxw,
FoundVerb=FoundVerb,
t=t,
nountoskip=nountoskip,
previousprep=xin,
UseSenticNet=UseSenticNet,
UseSentiWordNet=UseSentiWordNet,
UseFigas=UseFigas,
UseLiberty=UseLiberty, UseAuthority=UseAuthority, UseCare=UseCare, UseFairness=UseFairness, UseLoyalty=UseLoyalty, UsePurity=UsePurity
)
if iterated_list_prep and len(iterated_list_prep) > 0:
listOfPreps.extend(iterated_list_prep)
if iterated_list_prep_sentim and len(iterated_list_prep_sentim) > 0:
listOfPreps_sentim.extend(iterated_list_prep_sentim)
else:
print(
"...DEBUG ITERATE from PREP - NOT CONSIDERED CASE - {} {}: pos:{}, tag:{} - coming from Noun: {} ".format(
xinxin.dep_,
xinxin.lemma_,
xinxin.pos_,
xinxin.tag_,
t.lemma_,
))
if rxin_n:
for xinxin in rxin_n:
if xinxin.dep_ == "pobj" and xinxin.pos_ == "NOUN" and IsInterestingToken(
xinxin) and xinxin.lemma_.lower() != t.lemma_.lower():
if (nountoskip):
if xinxin.lemma_.lower() == nountoskip.lemma_.lower():
continue
print(
"...DEBUG NOUN ITERATE from PREP {}, {}: pos:{}, tag:{} - coming from Noun: {} ".format(
xinxin.dep_,
xinxin.lemma_,
xinxin.pos_,
xinxin.tag_,
t.lemma_,
))
minw = min(minw, xinxin.i)
maxw = max(maxw, xinxin.i)
other_list_NOUN, sentilist, minw, maxw = NOUN_token_IE_parsing(xinxin, singleNOUNs,
singleCompoundedHITS,
singleCompoundedHITS_toEXCLUDE,
filterNOUNs,
filterCOMPOUNDs,
LOCATION_SYNONYMS_FOR_HEURISTIC,
VERBS_TO_KEEP,
COMPUTE_OVERALL_POLARITY_SCORE,
minw=minw, maxw=maxw,
verbtoskip=FoundVerb, nountoskip=t, UseSenticNet=UseSenticNet,
UseSentiWordNet=UseSentiWordNet, UseFigas=UseFigas, UseLiberty=UseLiberty, UseAuthority=UseAuthority, UseCare=UseCare, UseFairness=UseFairness, UseLoyalty=UseLoyalty, UsePurity=UsePurity)
sentim_noun = FeelIt(xinxin.lemma_.lower(), xinxin.pos_, xinxin, UseSenticNet=UseSenticNet,
UseSentiWordNet=UseSentiWordNet, UseFigas=UseFigas, UseLiberty=UseLiberty, UseAuthority=UseAuthority, UseCare=UseCare, UseFairness=UseFairness, UseLoyalty=UseLoyalty, UsePurity=UsePurity)
if other_list_NOUN and len(other_list_NOUN) > 0:
listNoun_app = []
FoundNounInlist = "___" + xinxin.lemma_.lower()
for modin in other_list_NOUN:
FoundNounInlist = FoundNounInlist + "___" + modin
listNoun_app.append(FoundNounInlist)
other_list_NOUN = listNoun_app
listOfPreps.extend(other_list_NOUN)
else:
FoundNounInlist = "___" + xinxin.lemma_.lower() + "___"
listOfPreps.append(FoundNounInlist)
if sentilist and len(sentilist) > 0:
print(" sentilist: ")
print(sentilist)
for sentin in sentilist:
if sentin != 0:
if sentim_noun == 0:
sentim_noun = sentin
else:
if (sentim_noun > 0 and sentin < 0) or (
sentim_noun < 0 and sentin > 0): # they have different signes, I just sum them up
sentim_noun = np.sign(sentin) * np.sign(sentim_noun) * (
abs(sentim_noun) + (1 - abs(sentim_noun)) * abs(
sentin)) # change the sign and increase it
else: # they have same sign
sentim_noun = np.sign(sentim_noun) * (
abs(sentim_noun) + (1 - abs(sentim_noun)) * abs(
sentin)) # increase it
listOfPreps_sentim.append(sentim_noun)
print(
"...DEBUG END NOUN ITERATE from PREP {}, {}: pos:{}, tag:{} - coming from Noun: {} - with sentiment={}".format(
xinxin.dep_,
xinxin.lemma_,
xinxin.pos_,
xinxin.tag_,
t.lemma_, sentim_noun
))
elif xinxin.dep_ == "pcomp" and xinxin.pos_ == "VERB" and xinxin.lemma_.lower() != t.lemma_.lower():
minw = min(minw, xinxin.i)
maxw = max(maxw, xinxin.i)
iterated_list_VERB, list_verbs_sentim_app, minw, maxw = VERB_token_IE_parsing(xinxin, singleNOUNs,
singleCompoundedHITS,
singleCompoundedHITS_toEXCLUDE,
filterNOUNs,
filterCOMPOUNDs,
LOCATION_SYNONYMS_FOR_HEURISTIC,
VERBS_TO_KEEP,
COMPUTE_OVERALL_POLARITY_SCORE,
t, minw, maxw,
nountoskip=nountoskip,
previousverb=FoundVerb,
UseSenticNet=UseSenticNet,
UseSentiWordNet=UseSentiWordNet,
UseFigas=UseFigas,
UseLiberty=UseLiberty, UseAuthority=UseAuthority, UseCare=UseCare, UseFairness=UseFairness, UseLoyalty=UseLoyalty, UsePurity=UsePurity
)
if iterated_list_VERB and len(iterated_list_VERB) > 0:
listOfPreps.extend(iterated_list_VERB)
if list_verbs_sentim_app and len(list_verbs_sentim_app) > 0:
listOfPreps_sentim.extend(list_verbs_sentim_app)
elif xinxin.dep_ == "prep" and xinxin.pos_ == "ADP":
if (previousprep):
if xinxin.lemma_.lower() == previousprep.lemma_.lower():
continue
print(
"...DEBUG VERB ITERATE from PREP {}, {}: pos:{}, tag:{} - coming from Noun: {} ".format(
xinxin.dep_,
xinxin.lemma_,
xinxin.pos_,
xinxin.tag_,
t.lemma_,
))
minw = min(minw, xinxin.i)
maxw = max(maxw, xinxin.i)
iterated_list_prep, iterated_list_prep_sentim, minw, maxw = PREP_token_IE_parsing(xinxin, singleNOUNs,
singleCompoundedHITS,
singleCompoundedHITS_toEXCLUDE,
filterNOUNs,
filterCOMPOUNDs,
LOCATION_SYNONYMS_FOR_HEURISTIC,
VERBS_TO_KEEP,
COMPUTE_OVERALL_POLARITY_SCORE,
minw=minw, maxw=maxw,
FoundVerb=FoundVerb,
t=t,
nountoskip=nountoskip,
previousprep=xin,
UseSenticNet=UseSenticNet,
UseSentiWordNet=UseSentiWordNet,
UseFigas=UseFigas,
UseLiberty=UseLiberty,
UseAuthority=UseAuthority,
UseCare=UseCare,
UseFairness=UseFairness,
UseLoyalty=UseLoyalty,
UsePurity=UsePurity
)
if iterated_list_prep and len(iterated_list_prep) > 0:
listOfPreps.extend(iterated_list_prep)
if iterated_list_prep_sentim and len(iterated_list_prep_sentim) > 0:
listOfPreps_sentim.extend(iterated_list_prep_sentim)
else:
print(
"...DEBUG ITERATE from PREP - NOT CONSIDERED CASE - {} {}: pos:{}, tag:{} - coming from Noun: {} ".format(
xinxin.dep_,
xinxin.lemma_,
xinxin.pos_,
xinxin.tag_,
t.lemma_,
))
return listOfPreps, listOfPreps_sentim, minw, maxw
def VERB_token_IE_parsing(FoundVerb, singleNOUNs, singleCompoundedHITS, singleCompoundedHITS_toEXCLUDE, filterNOUNs,
filterCOMPOUNDs,
LOCATION_SYNONYMS_FOR_HEURISTIC, VERBS_TO_KEEP, COMPUTE_OVERALL_POLARITY_SCORE, t, minw,
maxw, nountoskip=None, previousverb=None, UseSenticNet=True, UseSentiWordNet=True,
UseFigas=True, UseLiberty=False, UseAuthority=False, UseCare=False, UseFairness=False, UseLoyalty=False, UsePurity=False):
listVerbs = []
listVerbs_sentim = []
CompoundsOfSingleHit = findCompoundedHITsOfTerm(singleCompoundedHITS, FoundVerb)
FoundNeg = None
FoundVerbAdverb = ""
FoundVerbAdverb_sentim = 0
listFoundModofVB = []
listFoundModofVB_sentim = []
l_n = [x for x in FoundVerb.lefts]
if l_n:
for xin in l_n:
lxin_n = [x for x in xin.lefts]
rxin_n = [x for x in xin.rights]
if xin.dep_ == "neg":
FoundNeg = "__not"
minw = min(minw, xin.i)
maxw = max(maxw, xin.i)
# elif xin.dep_== "advmod" and (xin.pos_=="ADV" and(xin.tag_=="RBS" or xin.tag_=="RBR")) and (FoundVerb.lemma_.lower()=="be" or FoundVerb.lemma_.lower()=="have"): #only for have or be
# listFoundModofVB.append(xin.lemma_.lower())
# print("...DEBUG VB-advmod_be_have {}: pos:{}, tag:{} ".format(xin.lemma_, xin.pos_, xin.tag_))
# fileIE_LOG.write('...DEBUG VB-advmod_be_have {}: pos:{} tag:{}'.format(xin.lemma_, xin.pos_, xin.tag_))
# fileIE_LOG.write("\n")
elif xin.dep_ == "advmod" and (xin.pos_ == "ADV" and (
xin.tag_ == "RBS" or xin.tag_ == "RBR")): # or xin.tag_ == "RB" #and (FoundVerb.lemma_.lower() == "be" or FoundVerb.lemma_.lower() == "have"): # only for have or be
if (xin.lemma_.lower() in filterCOMPOUNDs) or (xin.lemma_.lower() in CompoundsOfSingleHit):
continue
minw = min(minw, xin.i)
maxw = max(maxw, xin.i)
sentim_app = FeelIt(xin.lemma_.lower(), xin.pos_, xin, UseSenticNet=UseSenticNet,
UseSentiWordNet=UseSentiWordNet, UseFigas=UseFigas, UseLiberty=UseLiberty, UseAuthority=UseAuthority, UseCare=UseCare, UseFairness=UseFairness, UseLoyalty=UseLoyalty, UsePurity=UsePurity)
FoundVerbAdverb = FoundVerbAdverb + "__" + xin.lemma_.lower()
if FoundVerbAdverb_sentim == 0:
FoundVerbAdverb_sentim = sentim_app
else:
if (FoundVerbAdverb_sentim > 0 and sentim_app < 0) or (
FoundVerbAdverb_sentim < 0 and sentim_app > 0): # they have different signes, I just sum them up
FoundVerbAdverb_sentim = FoundVerbAdverb_sentim + sentim_app
else: # they have same sign
FoundVerbAdverb_sentim = np.sign(FoundVerbAdverb_sentim) * (
abs(FoundVerbAdverb_sentim) + (1 - abs(FoundVerbAdverb_sentim)) * abs(sentim_app))
print("...DEBUG found-advmod_of_VB {}: pos:{}, tag:{} ({})".format(xin.lemma_, xin.pos_, xin.tag_,
sentim_app))
elif (xin.dep_ == "acomp" or xin.dep_ == "oprd") and (xin.pos_ == "ADJ" and (xin.tag_ == "JJR" or xin.tag_ == "JJS" or xin.tag_ == "JJ")) and xin.lemma_.lower() != t.lemma_.lower(): # and (xin.left_edge.lemma_.lower() != t.lemma_.lower()) and (xin.right_edge.lemma_.lower() != t.lemma_.lower()):
if (xin.lemma_.lower() in filterCOMPOUNDs) or (xin.lemma_.lower() in CompoundsOfSingleHit):
continue
foundadv = ""
foundadv_sentim = 0
if lxin_n:
for xinxin in lxin_n:
if ((xinxin.dep_ == "advmod" and (xinxin.pos_ == "ADV" and (
xinxin.tag_ == "RBS" or xinxin.tag_ == "RBR"))) or (
xinxin.dep_ == "conj" and (xinxin.pos_ == "ADJ" and (
xinxin.tag_ == "JJR" or xinxin.tag_ == "JJS" or xinxin.tag_ == "JJ")))) and xinxin.lemma_.lower() != t.lemma_.lower(): # or xinxin.tag_=="RB"
foundadv = foundadv + "__" + xinxin.lemma_.lower()
minw = min(minw, xinxin.i)
maxw = max(maxw, xinxin.i)
sentim_app = FeelIt(xinxin.lemma_.lower(), xinxin.pos_, xinxin, UseSenticNet=UseSenticNet,
UseSentiWordNet=UseSentiWordNet, UseFigas=UseFigas, UseLiberty=UseLiberty, UseAuthority=UseAuthority, UseCare=UseCare, UseFairness=UseFairness, UseLoyalty=UseLoyalty, UsePurity=UsePurity)
if foundadv_sentim == 0:
foundadv_sentim = sentim_app
else:
if (foundadv_sentim > 0 and sentim_app < 0) or (
foundadv_sentim < 0 and sentim_app > 0): # they have different signes, I just sum them up
foundadv_sentim = foundadv_sentim + sentim_app
else: # they have same sign
foundadv_sentim = np.sign(foundadv_sentim) * (
abs(foundadv_sentim) + (1 - abs(foundadv_sentim)) * abs(sentim_app))
print("...DEBUG found-advmod-adj_of_ADJ {}: pos:{}, tag:{} ({})".format(xinxin.lemma_,
xinxin.pos_,
xinxin.tag_,
sentim_app))
if rxin_n:
for xinxin in rxin_n:
if ((xinxin.dep_ == "advmod" and (xinxin.pos_ == "ADV" and (
xinxin.tag_ == "RBS" or xinxin.tag_ == "RBR"))) or (
xinxin.dep_ == "conj" and (xinxin.pos_ == "ADJ" and (
xinxin.tag_ == "JJR" or xinxin.tag_ == "JJS" or xinxin.tag_ == "JJ")))) and xinxin.lemma_.lower() != t.lemma_.lower(): # or xinxin.tag_=="RB"
foundadv = foundadv + "__" + xinxin.lemma_.lower()
minw = min(minw, xinxin.i)
maxw = max(maxw, xinxin.i)
sentim_app = FeelIt(xinxin.lemma_.lower(), xinxin.pos_, xinxin, UseSenticNet=UseSenticNet,
UseSentiWordNet=UseSentiWordNet, UseFigas=UseFigas, UseLiberty=UseLiberty, UseAuthority=UseAuthority, UseCare=UseCare, UseFairness=UseFairness, UseLoyalty=UseLoyalty, UsePurity=UsePurity)
if foundadv_sentim == 0:
foundadv_sentim = sentim_app
else:
if (foundadv_sentim > 0 and sentim_app < 0) or (
foundadv_sentim < 0 and sentim_app > 0): # they have different signes, I just sum them up
foundadv_sentim = foundadv_sentim + sentim_app
else: # they have same sign
foundadv_sentim = np.sign(foundadv_sentim) * (
abs(foundadv_sentim) + (1 - abs(foundadv_sentim)) * abs(sentim_app))
print("...DEBUG found-advmod-adj_of_ADJ {}: pos:{}, tag:{} ({})".format(xinxin.lemma_,
xinxin.pos_,
xinxin.tag_,
sentim_app))
sentim_compound = FeelIt(xin.lemma_.lower(), xin.pos_, xin, UseSenticNet=UseSenticNet,
UseSentiWordNet=UseSentiWordNet, UseFigas=UseFigas, UseLiberty=UseLiberty, UseAuthority=UseAuthority, UseCare=UseCare, UseFairness=UseFairness, UseLoyalty=UseLoyalty, UsePurity=UsePurity)
if sentim_compound == 0:
sentim_compound = foundadv_sentim
else:
if (foundadv_sentim > 0 and sentim_app < 0) or (
foundadv_sentim < 0 and sentim_app > 0): # they have different signes, I just sum them up
sentim_compound = np.sign(foundadv_sentim) * np.sign(sentim_compound) * (
abs(sentim_compound) + (1 - abs(sentim_compound)) * abs(
foundadv_sentim)) # change the sign and increase it
else: # they have same sign
sentim_compound = np.sign(sentim_compound) * (
abs(sentim_compound) + (1 - abs(sentim_compound)) * abs(foundadv_sentim)) # increase it
listFoundModofVB.append((xin.lemma_.lower() + foundadv))
listFoundModofVB_sentim.append(sentim_compound)
minw = min(minw, xin.i)
maxw = max(maxw, xin.i)
print("...DEBUG VB-acomp {}: pos:{}, tag:{} ({})".format(xin.lemma_ + foundadv, xin.pos_, xin.tag_,
sentim_compound))
elif (xin.dep_ == "dobj" or xin.dep_ == "attr") and xin.pos_ == "NOUN" and IsInterestingToken(
xin) and xin.lemma_.lower() != t.lemma_.lower():
if (nountoskip):
# print("\n\n\nSTART nountoskip PROBLEM")
# fileIE_LOG.write("\n\n\n\nSTART nountoskip PROBLEM")
# fileIE_LOG.write("\n")
# print(t.sent)
# fileIE_LOG.write("\n" + t.sent.text)
# fileIE_LOG.write("\n\n")
# print("t")
# print(t.lemma_)
# fileIE_LOG.write("t")
# fileIE_LOG.write(t.lemma_)
# fileIE_LOG.write("\n")
# print("nountoskip")
# print(nountoskip.lemma_)
# fileIE_LOG.write("nountoskip")
# fileIE_LOG.write(nountoskip.lemma_)
# fileIE_LOG.write("\n\n")
if xin.lemma_.lower() == nountoskip.lemma_.lower():
continue
print("...DEBUG NOUN ITERATE, VB-{} {}: pos:{}, tag:{} - coming from Noun: {} ".format(xin.dep_,
xin.lemma_,
xin.pos_,
xin.tag_,
t.lemma_,
))
minw = min(minw, xin.i)
maxw = max(maxw, xin.i)
iterated_list_NOUN, sentilist, minw, maxw = NOUN_token_IE_parsing(xin, singleNOUNs, singleCompoundedHITS,
singleCompoundedHITS_toEXCLUDE,
filterNOUNs,
filterCOMPOUNDs,
LOCATION_SYNONYMS_FOR_HEURISTIC,
VERBS_TO_KEEP,
COMPUTE_OVERALL_POLARITY_SCORE, minw=minw,
maxw=maxw,
verbtoskip=FoundVerb, nountoskip=t, UseSenticNet=UseSenticNet,
UseSentiWordNet=UseSentiWordNet, UseFigas=UseFigas, UseLiberty=UseLiberty, UseAuthority=UseAuthority, UseCare=UseCare, UseFairness=UseFairness, UseLoyalty=UseLoyalty, UsePurity=UsePurity)
sentim_noun = FeelIt(xin.lemma_.lower(), xin.pos_, xin, UseSenticNet=UseSenticNet,
UseSentiWordNet=UseSentiWordNet, UseFigas=UseFigas, UseLiberty=UseLiberty, UseAuthority=UseAuthority, UseCare=UseCare, UseFairness=UseFairness, UseLoyalty=UseLoyalty, UsePurity=UsePurity)
if sentilist and len(sentilist) > 0:
print(" sentilist: ")
print(sentilist)
for sentin in sentilist:
if sentin != 0:
if sentim_noun == 0:
sentim_noun = sentin
else:
if (sentim_noun > 0 and sentin < 0) or (
sentim_noun < 0 and sentin > 0): # they have different signes, I just sum them up
sentim_noun = np.sign(sentin) * np.sign(sentim_noun) * (
abs(sentim_noun) + (1 - abs(sentim_noun)) * abs(
sentin)) # change the sign and increase it
else: # they have same sign
sentim_noun = np.sign(sentim_noun) * (
abs(sentim_noun) + (1 - abs(sentim_noun)) * abs(
sentin)) # increase it
listFoundModofVB_sentim.append(sentim_noun)
print(
"...DEBUG END NOUN ITERATE, VB-{} {}: pos:{}, tag:{} - coming from Noun: {} - with sentiment={}".format(
xin.dep_,
xin.lemma_,
xin.pos_,
xin.tag_,
t.lemma_, sentim_noun
))
if iterated_list_NOUN and len(iterated_list_NOUN) > 0:
#
listNoun_app = []
for modin in iterated_list_NOUN:
FoundNounInlist = "___" + xin.lemma_.lower() + "___" + modin
listNoun_app.append(FoundNounInlist)
iterated_list_NOUN = listNoun_app
#
listFoundModofVB.extend(iterated_list_NOUN)
else:
FoundNounInlist = "___" + xin.lemma_.lower() + "___"
listFoundModofVB.append(FoundNounInlist)
#
elif xin.dep_ == "prep" and xin.pos_ == "ADP" and xin.lemma_.lower() != t.lemma_.lower():
minw = min(minw, xin.i)
maxw = max(maxw, xin.i)
iterated_list_prep, iterated_list_prep_sentim, minw, maxw = PREP_token_IE_parsing(xin, singleNOUNs,
singleCompoundedHITS,
singleCompoundedHITS_toEXCLUDE,
filterNOUNs,
filterCOMPOUNDs,
LOCATION_SYNONYMS_FOR_HEURISTIC,
VERBS_TO_KEEP,
COMPUTE_OVERALL_POLARITY_SCORE,
minw=minw, maxw=maxw,
FoundVerb=FoundVerb, t=t,
nountoskip=nountoskip,
UseSenticNet=UseSenticNet,
UseSentiWordNet=UseSentiWordNet,
UseFigas=UseFigas,
UseLiberty=UseLiberty, UseAuthority=UseAuthority, UseCare=UseCare, UseFairness=UseFairness, UseLoyalty=UseLoyalty, UsePurity=UsePurity
)
if iterated_list_prep and len(iterated_list_prep) > 0:
listFoundModofVB.extend(iterated_list_prep)
if iterated_list_prep_sentim and len(iterated_list_prep_sentim) > 0:
listFoundModofVB_sentim.extend(iterated_list_prep_sentim)
if FoundNeg is None:
for xinxin in lxin_n:
if (xinxin.dep_ == "neg"):
FoundNeg = "__not"
minw = min(minw, xinxin.i)
maxw = max(maxw, xinxin.i)
for xinxin in rxin_n:
if (xinxin.dep_ == "neg"):
FoundNeg = "__not"