Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -94,7 +94,7 @@ class NounExtractor:
|
|
94 |
# Choose a representative dependency if no clear subject is present
|
95 |
return deps_in_phrase.pop() if deps_in_phrase else 'unknown'
|
96 |
|
97 |
-
def extract(self, sentence,
|
98 |
"""
|
99 |
Extracts and returns noun phrases with their detailed dependency tags from the sentence.
|
100 |
"""
|
@@ -102,10 +102,10 @@ class NounExtractor:
|
|
102 |
noun_phrases = self.get_noun_phrases(doc)
|
103 |
result_dict = {phrase: dep for phrase, dep in noun_phrases}
|
104 |
|
105 |
-
# Check for the presence of
|
106 |
-
found_verbs = [v for v in
|
107 |
if found_verbs:
|
108 |
-
# Adjust dependency labels for noun phrases based on the presence of an
|
109 |
for phrase, dep in list(result_dict.items()): # Work on a copy of items to safely modify the dict
|
110 |
if dep == 'ROOT':
|
111 |
result_dict[phrase] = 'dobj'
|
@@ -173,12 +173,12 @@ extractor = NounExtractor(nlp=nlp)
|
|
173 |
|
174 |
# Example of how to use this function
|
175 |
words_list = ["so", "because", "increase", "contribute", "due to"]
|
176 |
-
|
177 |
|
178 |
# Define the callback function for the GUI
|
179 |
def CogMapAnalysis(text):
|
180 |
if contains_words_or_phrases(words_list, text):
|
181 |
-
result = extractor.extract(text,
|
182 |
formatted_result = format_results(result)
|
183 |
plot = visualize_cognitive_map(formatted_result)
|
184 |
return formatted_result, plot
|
|
|
94 |
# Choose a representative dependency if no clear subject is present
|
95 |
return deps_in_phrase.pop() if deps_in_phrase else 'unknown'
|
96 |
|
97 |
+
def extract(self, sentence, causative_verb):
|
98 |
"""
|
99 |
Extracts and returns noun phrases with their detailed dependency tags from the sentence.
|
100 |
"""
|
|
|
102 |
noun_phrases = self.get_noun_phrases(doc)
|
103 |
result_dict = {phrase: dep for phrase, dep in noun_phrases}
|
104 |
|
105 |
+
# Check for the presence of causative verbs like 'cause', in the sentence
|
106 |
+
found_verbs = [v for v in causative_verb if v.lower() in sentence.lower()]
|
107 |
if found_verbs:
|
108 |
+
# Adjust dependency labels for noun phrases based on the presence of an causative verb.
|
109 |
for phrase, dep in list(result_dict.items()): # Work on a copy of items to safely modify the dict
|
110 |
if dep == 'ROOT':
|
111 |
result_dict[phrase] = 'dobj'
|
|
|
173 |
|
174 |
# Example of how to use this function
|
175 |
words_list = ["so", "because", "increase", "contribute", "due to"]
|
176 |
+
causative_verb = ['affect', 'influence', 'increase', 'against']
|
177 |
|
178 |
# Define the callback function for the GUI
|
179 |
def CogMapAnalysis(text):
|
180 |
if contains_words_or_phrases(words_list, text):
|
181 |
+
result = extractor.extract(text, causative_verb)
|
182 |
formatted_result = format_results(result)
|
183 |
plot = visualize_cognitive_map(formatted_result)
|
184 |
return formatted_result, plot
|