Source code for decomp.semantics.predpatt.rules.predicate_rules
"""Predicate extraction rules for PredPatt.This module contains rules for identifying predicate root tokens,building predicate phrases, and handling predicate-specific phenomena."""from__future__importannotationsfromtypingimportTYPE_CHECKINGfrom.baseimport(EnglishSpecific,PredConjRule,PredicateRootRule,PredPhraseRule,SimplifyRule,)ifTYPE_CHECKING:from..core.predicateimportPredicatefrom..core.tokenimportTokenfrom..parsing.udparseimportDepTriple# predicate root identification rules
[docs]classA1(PredicateRootRule):"""Extract a predicate token from the dependent of clausal relation {ccomp, csub, csubjpass}."""rule_type='predicate_root'
[docs]classA2(PredicateRootRule):"""Extract a predicate token from the dependent of clausal complement 'xcomp'."""rule_type='predicate_root'
[docs]classB(PredicateRootRule):"""Extract a predicate token from the dependent of clausal modifier."""rule_type='predicate_root'
[docs]classC(PredicateRootRule):"""Extract a predicate token from the governor of predicate-indicating relations. Relations: {nsubj, nsubjpass, dobj, iobj, ccomp, xcomp, advcl}. """rule_type='predicate_root'
[docs]def__init__(self,e:DepTriple)->None:"""Initialize with the dependency edge that triggered this rule. Parameters ---------- e : DepTriple The dependency edge with a predicate-indicating relation. """super().__init__()self.e=e
[docs]def__repr__(self)->str:"""Return string representation showing the edge details. Returns ------- str Formatted string showing governor, relation, and dependent. """returnf"add_root({self.e.gov})_for_{self.e.rel}_from_({self.e.dep})"
[docs]classD(PredicateRootRule):"""Extract a predicate token from the dependent of apposition."""rule_type='predicate_root'
[docs]classE(PredicateRootRule):"""Extract a predicate token from the dependent of an adjectival modifier."""rule_type='predicate_root'
[docs]classV(PredicateRootRule):"""Extract a predicate token from the dependent of 'nmod:poss' (English specific)."""rule_type='predicate_root'
[docs]classF(PredicateRootRule):"""Extract a conjunct token of a predicate token."""rule_type='predicate_root'
# predicate conjunction resolution rules
[docs]classPredConjBorrowAuxNeg(PredConjRule):"""Borrow aux and neg tokens from conjoined predicate's name."""
[docs]def__init__(self,friend:Predicate,borrowed_token:Token)->None:"""Initialize with the friend predicate and borrowed token. Parameters ---------- friend : Predicate The predicate we're borrowing from. borrowed_token : Token The aux or neg token being borrowed. """super().__init__()self.friend=friendself.borrowed_token=borrowed_token
[docs]classPredConjBorrowTokensXcomp(PredConjRule):"""Borrow tokens from xcomp in a conjunction or predicates."""
[docs]def__init__(self,friend:Predicate,borrowed_token:Token)->None:"""Initialize with the friend predicate and borrowed token. Parameters ---------- friend : Predicate The predicate we're borrowing from. borrowed_token : Token The token being borrowed from xcomp. """super().__init__()self.friend=friendself.borrowed_token=borrowed_token
# predicate phrase building rules
[docs]classN1(PredPhraseRule):"""Extract a token from the subtree of the predicate root token. Adds the token to the predicate phrase. """pass
[docs]classN2(PredPhraseRule):"""Drop a token, which is an argument root token, from the predicate subtree."""pass
[docs]classN3(PredPhraseRule):"""Drop a token, which is another predicate root token, from the predicate subtree."""pass
[docs]classN4(PredPhraseRule):"""Drop a token which is a dependent of specific relations from the predicate subtree. Relations: {ccomp, csubj, advcl, acl, acl:relcl, nmod:tmod, parataxis, appos, dep}. """pass
[docs]classN5(PredPhraseRule):"""Drop a conjunct token from the predicate subtree. Drops conjuncts of the predicate root token or conjuncts of a xcomp's dependent token. """pass
[docs]classN6(PredPhraseRule):"""Add a case phrase to the predicate phrase."""pass
# simplification rules for predicates
[docs]classP1(SimplifyRule):"""Remove a non-core argument, a nominal modifier, from the predpatt."""pass
[docs]classP2(SimplifyRule):"""Remove an argument of other type from the predpatt."""pass
[docs]classQ(SimplifyRule):"""Remove an adverbial modifier in the predicate phrase."""pass
[docs]classR(SimplifyRule):"""Remove auxiliary in the predicate phrase."""pass
# utility rules
[docs]classU(SimplifyRule):"""Strip the punct in the phrase."""pass
# english-specific rules
[docs]classEnRelclDummyArgFilter(EnglishSpecific):"""Filter out dummy arguments in English relative clauses."""
[docs]def__init__(self)->None:"""Initialize the English relative clause filter."""super().__init__()