MCPcopy Create free account
hub / github.com/debjitpaul/refiner / get_verb_phrases_from_token

Function get_verb_phrases_from_token

data_preprocessing/utils.py:277–355  ·  view source on GitHub ↗
(token, phrase_config=None)

Source from the content-addressed store, hash-verified

275 return [token.text]
276
277def get_verb_phrases_from_token(token, phrase_config=None):
278 if token.pos_ == "VERB" or token.pos_ == "AUX":
279 if hasattr(token, "children"):
280 dobj = None
281 prts = []
282 preps = []
283 attrs = []
284 acomps = []
285
286 for child in token.children:
287 if _enabled(phrase_config, "include_dobj") and child.dep_ == "dobj":
288 dobj = child
289 elif _enabled(phrase_config, "include_prt") and child.dep_ == "prt":
290 prts.append(child)
291 elif _enabled(phrase_config, "include_prep") and child.dep_ == "prep":
292 preps.append(child)
293 elif _enabled(phrase_config, "include_attr") and child.dep_ == "attr":
294 attrs.append(child)
295 elif _enabled(phrase_config, "include_acomp") and child.dep_ == "acomp":
296 acomps.append(child)
297
298 phrases = []
299 verb = f"{token.lemma_}"
300
301 if prts:
302 verb = f"{verb} {' '.join([prt.text for prt in prts])}"
303
304 dobj_phrases = []
305
306 if dobj:
307 dobj_phrases = get_noun_phrases_from_token(dobj, phrase_config=phrase_config)
308
309 prep_phrases = []
310
311 for prep in preps:
312 prep_phrases.extend(get_prep_phrases_from_token(prep, phrase_config=phrase_config))
313
314 attr_phrases = []
315
316 for attr in attrs:
317 attr_phrases.extend(get_noun_phrases_from_token(attr, phrase_config=phrase_config))
318
319 acomp_phrases = []
320
321 for acomp in acomps:
322 acomp_phrases.extend(get_acomp_phrases_from_token(acomp, phrase_config=phrase_config))
323
324 if _enabled(phrase_config, "longest_only"):
325 final_phrase = ""
326
327 for ph in dobj_phrases+attr_phrases+acomp_phrases+prep_phrases:
328 final_phrase += f" {ph}"
329
330 if final_phrase:
331 return [f"{verb}{final_phrase}"]
332
333 return []
334

Callers 1

get_phrasesFunction · 0.85

Calls 4

_enabledFunction · 0.85

Tested by

no test coverage detected