Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -111,8 +111,10 @@ class NounExtractor:
|
|
111 |
"""
|
112 |
Determine the most appropriate dependency label for a phrase based on internal dependencies.
|
113 |
"""
|
114 |
-
if 'nsubj' in deps_in_phrase
|
115 |
-
return '
|
|
|
|
|
116 |
else:
|
117 |
# Choose a representative dependency if no clear subject is present
|
118 |
return deps_in_phrase.pop() if deps_in_phrase else 'unknown'
|
@@ -130,7 +132,7 @@ class NounExtractor:
|
|
130 |
if found_verbs:
|
131 |
# Adjust dependency labels for noun phrases based on the presence of an causative verb.
|
132 |
for phrase, dep in list(result_dict.items()): # Work on a copy of items to safely modify the dict
|
133 |
-
if dep == '
|
134 |
result_dict[phrase] = 'dobj'
|
135 |
elif dep == 'dobj':
|
136 |
result_dict[phrase] = 'ROOT'
|
@@ -140,13 +142,13 @@ class NounExtractor:
|
|
140 |
def format_results(results):
|
141 |
formatted = []
|
142 |
# Find all roots or central subjects to structure the phrases around them
|
143 |
-
root_keys = [key for key, value in results.items() if value == '
|
144 |
|
145 |
for key, value in results.items():
|
146 |
if key in root_keys:
|
147 |
continue # Skip the roots themselves when adding to the formatted list
|
148 |
for root_key in root_keys:
|
149 |
-
if value == '
|
150 |
formatted.append(f"{key} -> {root_key}")
|
151 |
else:
|
152 |
formatted.append(f"{root_key} <- {key}")
|
|
|
111 |
"""
|
112 |
Determine the most appropriate dependency label for a phrase based on internal dependencies.
|
113 |
"""
|
114 |
+
if 'nsubj' in deps_in_phrase:
|
115 |
+
return 'ROOTnsubj'
|
116 |
+
elif 'nsubjpass' in deps_in_phrase:
|
117 |
+
return 'ROOTnsubjpass'
|
118 |
else:
|
119 |
# Choose a representative dependency if no clear subject is present
|
120 |
return deps_in_phrase.pop() if deps_in_phrase else 'unknown'
|
|
|
132 |
if found_verbs:
|
133 |
# Adjust dependency labels for noun phrases based on the presence of an causative verb.
|
134 |
for phrase, dep in list(result_dict.items()): # Work on a copy of items to safely modify the dict
|
135 |
+
if dep == 'ROOTnsubj':
|
136 |
result_dict[phrase] = 'dobj'
|
137 |
elif dep == 'dobj':
|
138 |
result_dict[phrase] = 'ROOT'
|
|
|
142 |
def format_results(results):
|
143 |
formatted = []
|
144 |
# Find all roots or central subjects to structure the phrases around them
|
145 |
+
root_keys = [key for key, value in results.items() if value == 'ROOTnsubj' or value == 'ROOTnsubjpass']
|
146 |
|
147 |
for key, value in results.items():
|
148 |
if key in root_keys:
|
149 |
continue # Skip the roots themselves when adding to the formatted list
|
150 |
for root_key in root_keys:
|
151 |
+
if value == 'ROOTnsubjpass': # If the dependency indicates a passive subject
|
152 |
formatted.append(f"{key} -> {root_key}")
|
153 |
else:
|
154 |
formatted.append(f"{root_key} <- {key}")
|