MCPcopy Create free account
hub / github.com/clips/pattern / PNPChunk

Class PNPChunk

pattern/text/tree.py:462–501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

460#--- PNP CHUNK -------------------------------------------------------------------------------------
461
462class 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

Callers 1

_do_pnpMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…