| 460 | #--- PNP CHUNK ------------------------------------------------------------------------------------- |
| 461 | |
| 462 | class PNPChunk(Chunk): |
| 463 | |
| 464 | def __init__(self, *args, **kwargs): |
| 465 | """ A chunk of chunks that make up a prepositional noun phrase (i.e., PP + NP). |
| 466 | When the output of the parser includes PP-attachment, |
| 467 | PNPChunck.anchor will yield the chunk that is clarified by the preposition. |
| 468 | For example: "the cat went [for the mouse] [with its claws]": |
| 469 | - [went] what? => for the mouse, |
| 470 | - [went] how? => with its claws. |
| 471 | """ |
| 472 | self.anchor = None # The anchor chunk (e.g., "for the mouse" => "went"). |
| 473 | self.chunks = [] # List of chunks in the prepositional noun phrase. |
| 474 | Chunk.__init__(self, *args, **kwargs) |
| 475 | |
| 476 | def append(self, word): |
| 477 | self.words.append(word) |
| 478 | word.pnp = self |
| 479 | if word.chunk is not None: |
| 480 | word.chunk.pnp = self |
| 481 | if word.chunk not in self.chunks: |
| 482 | self.chunks.append(word.chunk) |
| 483 | |
| 484 | @property |
| 485 | def preposition(self): |
| 486 | """ Yields the first chunk in the prepositional noun phrase, usually a PP-chunk. |
| 487 | PP-chunks contain words such as "for", "with", "in", ... |
| 488 | """ |
| 489 | return self.chunks[0] |
| 490 | |
| 491 | pp = preposition |
| 492 | |
| 493 | @property |
| 494 | def phrases(self): |
| 495 | return self.chunks |
| 496 | |
| 497 | def guess_anchor(self): |
| 498 | """ Returns an anchor chunk for this prepositional noun phrase (without a PP-attacher). |
| 499 | Often, the nearest verb phrase is a good candidate. |
| 500 | """ |
| 501 | return self.nearest("VP") |
| 502 | |
| 503 | #--- CONJUNCTION ----------------------------------------------------------------------------------- |
| 504 |
no outgoing calls
no test coverage detected
searching dependent graphs…