Skip to content

Commit bd37446

Browse files
author
mschild
committed
fix for negation dissovling heuristic
1 parent ad02cc6 commit bd37446

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

src/Backend/heuristics/negation_dissolve_heuristic.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
}
4343

4444

45-
def move_assignment(sentences_to_move, from_object, to_object, aspect, aspects):
45+
def move_assignment(sentences_to_move, from_object, to_object, aspect, aspects, threshold_score):
4646

4747
points_to_move = 0
4848
points_for_multiple = 0
@@ -51,12 +51,16 @@ def move_assignment(sentences_to_move, from_object, to_object, aspect, aspects):
5151
'sentences from', from_object.name, 'to', to_object.name, '.')
5252
print('----')
5353
for sentence in sentences_to_move:
54+
55+
points = (sentence[0]) / 10 if sentence[1].confidence < threshold_score else sentence[0]
56+
5457
if len(find_aspects(sentence[1].text, aspects)) > 1:
55-
points_for_multiple = points_for_multiple + sentence[0]
58+
points_for_multiple = points_for_multiple + points
5659
else:
57-
points_to_move = points_to_move + sentence[0]
60+
points_to_move = points_to_move + points
5861

59-
print('-' + re.sub(' +', ' ', re.sub('[^a-zA-Z0-9 ]', ' ', sentence[1].text)))
62+
print('-' + re.sub(' +', ' ',
63+
re.sub('[^a-zA-Z0-9 ]', ' ', sentence[1].text)))
6064

6165
from_object.sentences = [
6266
sentence for sentence in from_object.sentences if sentence not in sentences_to_move]
@@ -79,35 +83,42 @@ def move_assignment(sentences_to_move, from_object, to_object, aspect, aspects):
7983
print('----')
8084

8185

82-
def negation_dissolve_heuristic(object_a, object_b, aspect, aspects):
86+
def negation_dissolve_heuristic(object_a, object_b, aspect, aspects, threshold_score):
8387
markers = positive_contrary_comparatives
84-
filtered_sentences = get_matching_sentences(object_a.name, object_b.name, aspect, object_a.sentences, markers, True)
88+
filtered_sentences = get_matching_sentences(
89+
object_a.name, object_b.name, aspect, object_a.sentences, markers, True)
8590

8691
if len(filtered_sentences) > 0:
8792
for sentence in filtered_sentences:
88-
filtered_contrary = [v for k, v in markers.items() if k in sentence[1].text]
89-
filtered_contrary = [item for sublist in filtered_contrary for item in sublist]
93+
filtered_contrary = [
94+
v for k, v in markers.items() if k in sentence[1].text]
95+
filtered_contrary = [
96+
item for sublist in filtered_contrary for item in sublist]
9097

9198
if len(filtered_contrary) > 0:
9299
same_meaning_sentences = get_matching_sentences(
93100
object_b.name, object_a.name, aspect, object_b.sentences, filtered_contrary, False)
94101
if len(same_meaning_sentences) > 0:
95102
move_assignment(same_meaning_sentences,
96-
object_b, object_a, aspect, aspects)
103+
object_b, object_a, aspect, aspects, threshold_score)
97104

98105

99106
def get_matching_sentences(object_a, object_b, aspect, sentences, markers, is_positive):
100-
locked_out_markers = []
107+
locked_out_markers = []
101108
if is_positive:
102-
locked_out_markers = [item for sublist in list(positive_contrary_comparatives.values()) for item in sublist]
109+
locked_out_markers = [item for sublist in list(
110+
positive_contrary_comparatives.values()) for item in sublist]
103111
else:
104-
locked_out_markers = [marker for marker in positive_contrary_comparatives]
105-
re_locked_out_markers = '|'.join([re.escape(x) for x in locked_out_markers])
112+
locked_out_markers = [
113+
marker for marker in positive_contrary_comparatives]
114+
re_locked_out_markers = '|'.join(
115+
[re.escape(x) for x in locked_out_markers])
106116
re_markers = '|'.join([re.escape(x) for x in markers])
107117

108118
regex = re.compile(r'(?=.*(?:\b' + re.escape(object_a) + r'\b.*\b' + re.escape(aspect) +
109119
r'\b.*\b' + re.escape(object_b) + r'\b))(?=.*(?:\b' + re_markers + r'\b))(?!.*(?:\b' + re_locked_out_markers + r'\b))', re.IGNORECASE)
110120

111-
filtered_sentences = [x for x in sentences if regex.search(x[1].text) != None]
121+
filtered_sentences = [
122+
x for x in sentences if regex.search(x[1].text) != None]
112123

113124
return filtered_sentences

src/Backend/ml_approach/classify.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ def evaluate(sentences, prepared_sentences, classification_results, obj_a, obj_b
108108

109109
if USE_HEURISTICS:
110110
for aspect in aspects:
111-
negation_dissolve_heuristic(obj_a, obj_b, aspect.name, aspects)
112-
negation_dissolve_heuristic(obj_b, obj_a, aspect.name, aspects)
111+
negation_dissolve_heuristic(obj_a, obj_b, aspect.name, aspects, threshold_score)
112+
negation_dissolve_heuristic(obj_b, obj_a, aspect.name, aspects, threshold_score)
113113

114114
obj_a.sentences = prepare_sentence_list(obj_a.sentences)
115115
obj_b.sentences = prepare_sentence_list(obj_b.sentences)

0 commit comments

Comments
 (0)