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)
| 952 | return chunked |
| 953 | |
| 954 | def 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. |
no test coverage detected
searching dependent graphs…