MCPcopy Index your code
hub / github.com/clips/pattern / find_prepositions

Function find_prepositions

pattern/text/__init__.py:954–978  ·  view source on GitHub ↗

The input is a list of [token, tag, chunk]-items. The output is a list of [token, tag, chunk, preposition]-items. PP-chunks followed by NP-chunks make up a PNP-chunk.

(chunked)

Source from the content-addressed store, hash-verified

952 return chunked
953
954def find_prepositions(chunked):
955 """ The input is a list of [token, tag, chunk]-items.
956 The output is a list of [token, tag, chunk, preposition]-items.
957 PP-chunks followed by NP-chunks make up a PNP-chunk.
958 """
959 # Tokens that are not part of a preposition just get the O-tag.
960 for ch in chunked:
961 ch.append("O")
962 for i, chunk in enumerate(chunked):
963 if chunk[2].endswith("PP") and chunk[-1] == "O":
964 # Find PP followed by other PP, NP with nouns and pronouns, VP with a gerund.
965 if i < len(chunked)-1 and \
966 (chunked[i+1][2].endswith(("NP", "PP")) or \
967 chunked[i+1][1] in ("VBG", "VBN")):
968 chunk[-1] = "B-PNP"
969 pp = True
970 for ch in chunked[i+1:]:
971 if not (ch[2].endswith(("NP", "PP")) or ch[1] in ("VBG", "VBN")):
972 break
973 if ch[2].endswith("PP") and pp:
974 ch[-1] = "I-PNP"
975 if not ch[2].endswith("PP"):
976 ch[-1] = "I-PNP"
977 pp = False
978 return chunked
979
980#--- SEMANTIC ROLE LABELER -------------------------------------------------------------------------
981# Naive approach.

Callers 2

find_chunksMethod · 0.85
find_prepositionsMethod · 0.85

Calls 2

lenFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…