-
Notifications
You must be signed in to change notification settings - Fork 1
/
skills.py
1983 lines (1773 loc) · 58.8 KB
/
skills.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 re
import regex as re2
from regex import sub as sub2
from collections import defaultdict
from datetime import datetime
from ngrams.ngrams import corrections, Pw
import nltk
# ===========================================================================================
# #
## # #### ##### # # ## # # ###### ## ##### # #### # #
# # # # # # # ## ## # # # # # # # # # # # ## #
# # # # # # # # ## # # # # # # # # # # # # # # #
# # # # # ##### # # ###### # # # ###### # # # # # # #
# ## # # # # # # # # # # # # # # # # # # ##
# # #### # # # # # # ###### # ###### # # # # #### # #
def preprocess_message( statement):
sentences = nltk.sent_tokenize( statement)
return [
cleanup_sentence(
remove_fluff(
corrections(
expand_contractions(
sentence.lower()
))))
for sentence
in sentences
]
def stemmer( word, pos):
if pos=="NOUN" and word[-1]=="s":
return word[:-1]
elif pos=="VERB" and word[-1]=="s":
return word[:-1]
elif pos=="VERB" and word[-2:]=="ed" and word[-3]!="e":
return word[:-2]+"ing"
else:
return word
def capitalize_sentence(sentence):
sentence = sentence[:1].upper() + sentence[1:]
sentence = re.sub(r"(^|\W)i($|\W)",r"\1I\2",sentence)
names = extract_named_entities(sentence.title())
for name in names:
sentence = re.sub(name.lower(),name,sentence)
for token in nltk.tokenize.word_tokenize(sentence)[1:]:
if re.match(r"[A-Z]\w*",token):
if Pw(token.lower())>1e-06 and token not in firstnames.words():
sentence = re.sub(token,token.lower(),sentence)
return sentence
def capitalize_fragment(sentence):
sentence = re.sub(r"(^|\W)i($|\W)",r"\1I\2",sentence)
names = extract_named_entities(sentence.title())
for name in names:
sentence = re.sub(name.lower(),name,sentence)
for token in nltk.tokenize.word_tokenize(sentence):
if re.match(r"[A-Z]\w*",token):
if Pw(token.lower())>1e-06 and token not in firstnames.words():
sentence = re.sub(token,token.lower(),sentence)
return sentence
##### # ######
# # #### #### ##### # # # ## #####
# # # # # # # # # # # # # #
# #### # # # # # # # ###### # # # #
# # # # # # # # # # # ###### # #
# # # # # # # # # # # # # # #
##### #### #### ##### # ###### # # #####
intensifiers = "|".join([
r"(?:pretty(?: much)?",
r"quite",
r"so",
r"very",
r"absolutely",
r"total?ly",
r"real?ly",
r"somewhat",
r"kind of",
r"perfectly",
r"incredibly",
r"positively",
r"definitely",
r"completely",
r"propably",
r"just",
r"rather",
r"almost",
r"entirely",
r"fully",
r"highly",
r"a bit)"
])
positives = "|".join([
r"(good",
r"better",
r"best",
r"finer?",
r"nicer?",
r"lovel(y|ier)",
r"great(er)?",
r"amazing",
r"super",
r"smashing",
r"fantastic",
r"stunning",
r"groovy",
r"wonderful?l",
r"superb",
r"marvel?lous",
r"neat",
r"terrific",
r"swell",
r"dandy",
r"tremendous",
r"excellent",
r"dope",
r"well",
r"elat(ed|ing)",
r"enthusiastic",
r"looking forward to",
r"engag(ed|ing)",
r"thrill(ed|ing)",
r"excit(ed|ing)",
r"happ(y|ier)",
r"joyful",
r"joyous",
r"delight(ed|ing)",
r"curious",
r"eager",
r"ok",
r"alright)"
])
negatives = "|".join([
r"(bad",
r"terrible",
r"awful",
r"mad",
r"horrible",
r"horrid",
r"sad",
r"blue",
r"down",
r"unhappy",
r"unwell",
r"miserable",
r"dissatisfied",
r"unsatisfied",
r"sick",
r"ill",
r"tired",
r"jealous",
r"envious",
r"afraid",
r"scared",
r"converned",
r"worried",
r"uneasy",
r"so-so",
r"medium",
r"negative",
r"troubled)"
])
def is_positive( sentence):
if(
(
re.search( positives, sentence)
and not has_negation( sentence)
)or(
re.search( negatives, sentence)
and has_negation( sentence)
)
):
return True
else:
return False
def is_negative( sentence):
if(
(
re.search( negatives, sentence)
and not has_negation( sentence)
)or(
re.search( positives, sentence)
and has_negation( sentence)
)
):
return True
else:
return False
#####
# # ##### #### ##### # #
# # # # # # # #
##### # # # # # #
# # # # ##### #
# # # # # # # #
##### # #### # # #
def has_story( sentence):
if(
re.search( r"(^|\W)(i|me|mine|myself|my|we|our|oursel(f|v)(es)?|us)(\W|$)", sentence)
and not re.search( r"\?$", sentence)
):
return True
else:
return False
story_negatives = r"|".join([
r"(too late",
r"(lost|missed|broke|hurt|killed|failed|misplaced|forgot) (.* )?(my|ours?|mine|hers?|his|theirs?)",
r"failed (\w+ )?at)"
])
def has_story_negative( sentence):
if(
re.search( r"(^|\W)(i|we|my|our|me) ", sentence)
and not re.search( r"\?$", sentence)
and re.search( story_negatives, sentence)
):
return True
else:
return False
#####
# # # # ## # # ##### # ##### # ##### # #
# # # # # # ## # # # # # # # #
# # # # # # # # # # # # # # #
# # # # # ###### # # # # # # # # #
# # # # # # # ## # # # # # #
#### # #### # # # # # # # # # #
quantifier_much = "|".join([
r"(a [^\.\;]*lot",
r"lots",
r"enough",
r"(?:^|\s)sufficient",
r"great [^\.\;]*deal of",
r"some",
r"extensively",
r"several",
r"a few",
r"a [^\.\;]*couple of",
r"a [^\.\;]*bit of",
r"several",
r"multiple",
r"various",
r"fold",
r"numerous",
r"plent[iy]",
r"copious",
r"abundant",
r"ample",
r"any",
r"many",
r"much)"
])
quantifier_insufficient = "|".join([
r"(insufficient",
r"lack of",
r"lacked",
r"defici",
r"(?<!a\s)few", # match only if not preceded by "a "
r"(?<!a\s)little",
r"scant",
r"miss)"
])
def has_quantifier_much(sentence):
if re.search(r"not[^\.\;]+" + quantifier_much,sentence):
return False
if re.search(quantifier_much,sentence):
return True
elif re.search(r"no[^\.\;]+(complain|lack|miss|defici|insufficient)",sentence):
return True
else:
return False
def has_quantifier_insufficient(sentence):
if re.search(r"no[^\.\;]+" + quantifier_insufficient,sentence):
return False
if re.search(quantifier_insufficient,sentence):
return True
elif re.search(r"not[^\.\;]+"+quantifier_much,sentence):
return True
else:
return False
def has_quantifier_excessive(sentence):
if re.search(r"(too much|overmuch)",sentence):
return True
else:
return False
# # # # #
# # ###### #### # ## # ####
# # # # # # # # # #
# ##### #### # # # # # #
# # # # # # # # #
# # # # # # ## # #
# ###### #### # # # ####
# Maybe intensifiers can be viewed as a subset of affirmations?
affirmations = "|".join([
r"(yes",
r"yeah",
r"aye",
r"absolutely",
r"total?ly",
r"certainly",
r"probably",
r"definitely",
r"maybe",
r"right",
r"correct",
r"true",
r"possible",
r"possibly",
r"sure",
r"almost",
r"entirely",
r"fully",
r"highly",
r"ok",
r"okay",
r"agree",
r"alright)"
])
negations_short = "|".join([
r"(no",
r"not",
r"nay",
r"nope)"
])
negations_pronoun = "|".join([
r"(never",
r"no?one",
r"nobody",
r"nowhere",
r"nothing)"
])
negations_adjective = "|".join([
r"(impossible",
r"wrong",
r"false",
r"bullshit",
r"incorrect)"
])
negations = r"(("+negations_short+r"(\W|$))|" + negations_pronoun + "|" + negations_adjective + ")"
def has_negation(sentence):
if re.search( negations_short + r"[^\.\,\;(is)]+" + negations_adjective,sentence):
return False
elif re.search( negations,sentence):
return True
else:
return False
def has_affirmation( sentence):
if(
re.search( affirmations+r"(\W|$)",sentence)
and not has_negation( sentence)
):
return True
elif(
re.search( r"why not(\?|\!)", sentence)
or re.search( intensifiers + r" so(\W|$)", sentence)
or (
re.search( r"(\W|^)i (.* )?(think|say|hope) so(\W|$)", sentence)
and not has_negation(sentence)
)
or(
re.search( r"(\W|^)(sounds|feels) (" + intensifiers + " )?" + positives, sentence)
)
):
return True
else:
return False
def has_elaboration(sentences):
text = "".join(sentences)
for pattern in [ positives, negatives, intensifiers, affirmations, negations]:
text=re.sub(pattern,"",text)
if len(text) > 20:
return True
else:
return False
#######
# # ##### ##### # #### # # ####
# # # # # # # # ## # #
# # # # # # # # # # # ####
# # ##### # # # # # # # #
# # # # # # # # ## # #
####### # # # #### # # ####
action_verbs = r"|".join([
r"(ask(ing)?",
r"go(ing)?",
r"demand(ing)?",
r"driv(e|ing)",
r"chang(e|ing)",
r"behav(e|ing)",
r"perform(ing)?",
r"work(ing)?",
r"meet(ing)?",
r"prepar(e|ing)",
r"smil(e|ing)",
r"help(ing)?",
r"support(ing)?",
r"aid(ing)?",
r"consult(ing)?",
r"coach(ing)?",
r"car(e|ing)",
r"bring(ing)?",
r"tak(e|ing)",
r"get(ting)?",
r"carry(ing)?",
r"solv(e|ing)",
r"creat(e|ing)",
r"initiat(e|ing)?",
r"engag(e|ing)",
r"set(ting)?",
r"motivat(e|ing)",
r"inspir(e|ing)",
r"eat(ing)?",
r"drink(ing)?",
r"consum(e|ing)",
r"sleep(ing)?",
r"see(ing)?",
r"invent(ing)?",
r"rehears(e|ing)",
r"dress(ing)?",
r"break(ing)?",
r"fill(ing)?",
r"fulfill(ing)?",
r"develop(ing)?",
r"rest(ing)?",
r"stop(ing)?",
r"increas(e|ing)",
r"decreas(e|ing)",
r"listen(ing)?",
r"meditat(e|ing)",
r"us(e|ing)",
r"spen.(ing)?",
r"wast(e|ing)",
r"organiz(e|ing)",
r"plan(ing)?",
r"invest(ing)?",
r"learn(ing)?",
r"join(ing)?",
r"practi.(e|ing)",
r"play(ing)?",
r"hik(e|ing)",
r"climb(ing)?",
r"walk(ing)?",
r"bik(e|ing)",
r"sail(ing)?",
r"jump(ing)?",
r"laugh(ing)?",
r"surf(ing)?",
r"swim(ing)?",
r"fly(ing)?",
r"writ(e|ing)",
r"reply(ing)?",
r"send(ing)?",
r"fight(ing)?",
r"buy(ing)?",
r"repair(ing)?",
r"continu(e|ing)",
r"lower(ing)?",
r"rais(e|ing)",
r"improv(e|ing)",
r"read(ing)?",
r"explor(ing)?",
r"travel(ing)?",
r"exchang(e|ing)",
r"invest(ing)?",
r"transfer(ing)?",
r"balanc(ing)?",
r"danc(e|ing)",
r"wear(ing)?",
r"mak(e|ing)",
r"keep(ing)?",
r"writ(e|ing)",
r"jump(ing)?",
r"stand(ing)?",
r"pos(e|ing)",
r"fake(e|ing)?",
r"pretend(ing)?",
r"tell(ing)?",
r"nap(ping)?",
r"research(ing)?",
r"find(ing)?",
r"discuss(ing)?",
r"argue(ing)?",
r"provoc(e|ing)",
r"suggest(ing)?",
r"start(ing)?",
r"apply(ing)?",
r"connect(ing)?",
r"(out|crowd)?sourc(e|ing)",
r"fun(ing)?",
r"found(ing)",
r"shar(e|ing)",
r"tap(ping)?",
r"invit(e|ing)",
r"investigat(e|ing)",
r"giv(e|ing)",
r"donat(e|ing)",
r"lov(e|ing)?)",
r"ignor(e|ing)",
r"deal(ing)?",
r"mind(ing)?",
r"do(ing)"
])
def has_option( sentence):
if(
re2.search( action_verbs, sentence)
and (
not has_negation( sentence)
or re.search( r"no matter (what)?", sentence))
and not has_quantifier_excessive( sentence)
and not has_quantifier_insufficient( sentence)
and not re.search( r"(too late)", sentence)
):
return True
else:
return False
numbers = r"|".join([
r"(first",
r"second",
r"third",
r"two",
r"three",
r"four(th)?",
r"six(th)?",
r"seven(th)?",
r"eighth?",
r"nine?(th)?",
r"ten(th)?",
r"(number|option|item) (one|a|b|c)(\W|$)",
r"last",
r"end",
r"beginning",
r"start)"
])
def has_choice_of_enumerated_item( sentence):
sentence_fragments = sentence.split("but")
if (
re.search( numbers, sentence_fragments[-1])
and not has_negation( sentence_fragments[-1])
):
return True
elif(
re.search( numbers, sentence)
and not has_negation( sentence)
):
return True
else:
return False
######
# # ##### #### ##### # ###### # #
# # # # # # # # # # ## ##
###### # # # # ##### # ##### # ## #
# ##### # # # # # # # #
# # # # # # # # # # #
# # # #### ##### ###### ###### # #
problem_grammar = nltk.CFG.fromstring(r"""
problem -> subject VP | subject modifier VP
VP -> verb_group
VP -> verb_group object_clause
VP -> verb_group quantifier_j object_clause
VP -> verb_group quantifier_r
VP -> verb_group modifier_r quantifier_r
PP -> P object
verb_group -> verb_simple
verb_group -> moderator verb_simple
verb_group -> verb_aux verb_gerund
verb_group -> verb_aux modifier verb_gerund
verb_group -> verb_aux moderator verb_gerund
verb_group -> verb_aux moderator modifier verb_gerund
verb_group -> verb_aux verb_simple
verb_group -> verb_aux modifier verb_simple
verb_group -> verb_aux moderator verb_simple
verb_group -> verb_aux moderator modifier verb_simple
verb_group -> verb_aux "to" verb_simple
verb_group -> "do" modifier verb_aux "to" verb_simple
verb_group -> verb_aux
verb_simple -> "drink"
verb_gerund -> "drinking"
verb_aux -> "have" verb_pastprog
verb_aux -> "have" modifier verb_pastprog
verb_aux -> "am" | "do" | "have"
verb_aux -> "use" | "fail" | "can" | "want" | "get"
verb_pastprog -> "been" | "done"
subject -> "i"
object_simple -> "milk"
object_np -> determiner object_simple
object_clause -> object_simple | object_np
object_clause -> comparison_base object_simple "than" comparison
object_clause -> comparison_base preposition object_np "than" comparison
object_clause -> quantifier_j object_simple
object_clause -> modifier_r quantifier_j object_simple
object_clause -> quantifier_j preposition object_np
object_clause -> modifier_r quantifier_j preposition object_np
determiner -> "a" | "an" | "the" | "this" | "these" | "those" | "that"
determiner -> "my" | "our" | "his" | "her" | "its" | "our" | "their"
preposition -> "of" | "from"
modifier -> negation | temporal | negation temporal
modifier_r -> "much" | "way" | "far" | "by" "far" | "a" "lot" | "a" "bit"
negation -> "no" | "not" | "never"
temporal -> "always" | "sometimes" | "often"
quantifier_j -> "a" "lot" "of" | "a" "lot"| "enough"
quantifier_j -> "too" "much" | "too" "many"
quantifier_j -> "too" "few" | "too" "little"
quantifier_r -> "too" adverb | "too" "little" | "too" "much" |
quantifier_r -> comparison_base adverb "than" comparison
quantifier_r -> comparison_base "than" comparison
adverb -> "seldom" | "often"
comparison -> "i" "should"
comparison_base -> "more" | "less" | modifier_r "more" | modifier_r "less"
moderator -> "kind" "of" | "somehow"
""")
problem_parser = nltk.RecursiveDescentParser( problem_grammar)
def matches_problem_grammar(sentence):
sentence = re.sub( r"(\.|\,|\!|\?|\;|\:)", "", sentence)
return False
# work in progress
def extract_defined_problem( sentence):
return sentence
# work in progress
problems = "|".join([
"(problems?",
"issues?",
"topics?",
"somethings?",
"itch(es)?",
"irritations?",
"troubles?",
"challenges?",
"topics?",
"fears?",
"pains?)"
])
problem_keywords = r"|".join([
r"(too much",
r"too many",
r"too often",
r"too little",
r"too few",
r"too seldom",
r"not get",
r"being",
r"lack of",
r"need",
r"satisf",
r"unhealthy",
r"stress",
r"pressure",
r"struggle",
r"barely"
r"hardly",
r"pain",
r"alone",
r"awkward",
r"deserve",
r"more (\w+ )than",
r"less (\w+ )than",
r"survive",
r"enough)"
])
problem_quantifiers = r"|".join([
r"(no",
r"lack of",
r"too much",
r"too many",
r"too few",
r"not enough",
r"more than enough",
r"lack of",
r"overmuch",
r"(want(ing)?|need(ing)?|hav(e|ing)) (more|less)",
r"(not|never) (hav(e|ing)|get(ting)?)( my( (\w+ )?share of)| the| enough( of))?",
r"too little)"
])
problem_ressources = r"|".join([
r"(money",
r"(\w+ )?time",
r"(\w+ )?opportinit(y|ies)",
r"respect",
r"recognition",
r"support",
r"help",
r"backup",
r"ressources?",
r"sources?",
r"sex",
r"love",
r"thrill",
r"process",
r"food",
r"fun",
r"contact",
r"connections?",
r"energy",
r"willpower",
r"endurance",
r"fitness",
r"strenght",
r"power)"
])
problem_patterns = [
r".*(my|the) (\w|\s|\-|\,)?" \
+ problems \
+ r" (is|are|would be|might be)"\
+ "(?! not)( that( i))? ([^\.\!\?$]+)",
r".* (is|are|would be|might be)(?! not) "\
+ "(my|the|an?|one of my) (\w|\s|\-|\,)?" \
+ problems \
+ r"( for me)?(\,|\.|\-|\!|\?|$)",
r"(it (would|might|could|will)"\
+ "(( \w+)?( allow| enable| empower) me to)?"\
+ "( (solve|reduce|improve|increase)) )?"\
+ "(my|the|an?|one of my)( \w+)? "\
+ problems\
+ "\,? (of|that|the|in|not)"
]
problem_antipatterns = [
r".*(my|the) (\w|\s|\-|\,)*" \
+ problems \
+ r" (is|are|would be|might be)( that( i))? (not|never) ([^\.\!\?$]+)",
r".* (is|are|would be|might be) (not|never) (my|the|an?|one of my) (\w|\s|\-|\,)*" \
+ problems \
+ r"( for me)?(\,|\.|\-|\!|\?|$)"
]
def has_problem_statement( sentence):
if(
any( re.search( antipattern, sentence) for antipattern in problem_antipatterns)
):
return False
elif(
(
any( re.search( pattern, sentence) for pattern in problem_patterns)
or re.search( problem_keywords, sentence)
or re.search( problem_quantifiers + r" " + problem_ressources, sentence)
)
and not re.search( r"you", sentence)
):
return True
else:
return False
##### #######
# # ##### ###### #### # ###### # #### # # # # ######
# # # # # # # # # # # # # ## ## #
##### # # ##### # # ##### # # # # # ## # #####
# ##### # # # # # # # # # # #
# # # # # # # # # # # # # # # #
##### # ###### #### # # # #### # # # # ######
timepoints = r"|".join([
r"(monday",
r"tuesday",
r"wednesday",
r"thursday",
r"friday",
r"saturday",
r"sunday",
r"week",
r"tonight",
r"today",
r"tomorrow",
r"afternoon",
r"morning",
r"evening",
r"night",
r"break",
r"session",
r"meeting",
r"training",
r"presentation",
r"test",
r"lunch",
r"breakfast",
r"supper",
r"dinner",
r"coffee",
r"party",
r"gathering",
r"event",
r"trip",
r"barbecue",
r"picnic)"
])
def has_specific_time( sentence):
if (
re.search( timepoints, sentence)
or re.search( r"(at|on) the ", sentence)
):
return True
else:
return False
# #
# # ###### #### # ##### ## ##### # #### # #
# # # # # # # # # # # # ## #
####### ##### #### # # # # # # # # # # #
# # # # # # ###### # # # # # # #
# # # # # # # # # # # # # # ##
# # ###### #### # # # # # # #### # #
def has_hesitation( sentence):
if(
re.search( r"^(\W)*(e+r*m*|h*u*m+|so+|well)?(\W)*"
r"(actually|"
r"((" + intensifiers + r" )?" + positives + r") question|"
r"let me think|"
r"(\w+ )?hard to say|"
r"i do ?n(o|\')t( \w+)? know)?"
r"(\W)*$", sentence)
):
return True
else:
return False
#######
# # # ## # # # # ####
# # # # # ## # # # #
# ###### # # # # # #### ####
# # # ###### # # # # # #
# # # # # # ## # # # #
# # # # # # # # # ####
def has_thanks( sentence):
if re.search( r"thank", sentence):
return True
else:
return False
#######
# ###### ###### # # # # #### ####
# # # # # ## # # # #
##### ##### ##### # # # # # # ####
# # # # # # # # # ### #
# # # # # # ## # # # #
# ###### ###### ###### # # # #### ####
feelings_negative = r"|".join([
r"(a?lone(?:ly|some)?",
r"hungry",
r"thirsty",
r"tired",
r"starv(?:ed|ing)",
r"ravished",
r"angry",
r"furious",
r"raging",
r"mad",
r"sad",
r"unhappy",
r"blue",
r"sorrowful",
r"mournful",
r"miserable",
r"depressed",
r"frustrated",
r"glum",
r"weak",
r"down",
r"disappointed",
r"desparate",
r"despairing",
r"exhausted",
r"worn.out",
r"drained",
r"displeased",
r"dissatisfied",
r"discontent",
r"unlucky",
r"unwell",
r"uneasy",
r"annoyed",
r"irritated",
r"infuriated",
r"bothered",
r"nervous",
r"shocked",
r"perplexed",
r"confused",
r"troubled",
r"outraged",
r"shaken",
r"scandalized",
r"disgusted",
r"deprived",
r"hurt",
r"injured",
r"insulted",
r"degraded",
r"humiliated",
r"shamed",
r"ashame",
r"pathetic",
r"rotten",
r"disgusting",
r"foul",
r"defeated",
r"powerless",
r"inferior",
r"inappropriate",
r"awkward",
r"clumsy",
r"ugly",
r"embarrass(?:ed|ing)",
r"inept",
r"helpless",
r"upset",
r"unwelcome)"
])
def has_feeling_negative( sentence):
return_value = False
if re.search( feelings_negative, sentence):
feeling_match = re.match( r"(.*?)(" + intensifiers + r".*)?" + feelings_negative + r"(.*?$)", sentence)
if(
not has_negation( feeling_match.group(1))
and
(re.search( r"(^|\W)(i|we)\W", feeling_match.group(1))
or re.search( r"^\W*$", feeling_match.group(1)))
):
return_value = True
return return_value
#######