def relation(type, claim, specifics, general=None): relation = Relation(specifics, claim, type) argument = Argument(relations={relation}) if general is not None: argument = argument + Argument( relations={Relation([general], relation, Relation.SUPPORT)}) return argument
def blob_conditional_claim(state, data): subject = Instance() verb = None object = None claim = GeneralBlob(subject, verb, object, data[0]) argument = Argument(instances={subject: {subject}}, claims={claim: {claim}}) return Interpretation(argument=argument, local=claim)
def assume(claim, general): assumption = SpecificClaim(claim.subject, 'is', general.subject.singular, assumption=True) argument = Argument(claims={assumption: {assumption}}) argument += relation(Relation.SUPPORT, claim, general=general, specifics={assumption}) return Interpretation(argument=argument, local=claim)
def general_claim_singular(state, data): scope = Scope() subj = Instance(pronoun=Span('something'), scope=scope) condition = SpecificClaim(subj, Verb('is'), data[0].local.singular, scope=scope) claim = GeneralClaim(subj, data[1].local, data[2].local, scope=scope) relation = Relation({condition}, claim, Relation.CONDITION) return data[0] + data[2] + Interpretation( argument=Argument( claims={claim: {claim}, condition: {condition}}, relations={relation}, instances={subj: {subj}} ), local=claim)
def expanded_general_claim(state, data): assert len(data[0].argument.claims) == 2 assert len(data[0].argument.relations) == 1 claim = data[0].local conditions = set(claim.update(scope=data[0].local.scope) for claim in data[2].local) remaining_claims = set(data[0].argument.claims.keys()) ^ {claim} relation = Relation(remaining_claims | conditions , claim, Relation.CONDITION) return data[0] + data[2] + Interpretation( argument=Argument( claims={condition: {condition} for condition in conditions}, relations={relation}, instances={condition.subject: {condition.subject} for condition in conditions} ), local=claim)
def undetermined_claim(state, data): scope = Scope() conditions = set(claim.update(scope=scope) for claim in data[2].local) claim = GeneralClaim.from_claim(data[0].local, scope=scope, conj=data[1].local) relation = Relation(conditions, claim, Relation.CONDITION) return data[0] + data[2] + Interpretation( argument=Argument( claims={ claim: {claim}, **{condition: {condition} for condition in conditions} }, relations={relation}, instances={ claim.subject: {claim.subject}, **{condition.subject: {condition.subject} for condition in conditions} } ), local=claim)
def text(self, argument: Argument): return argument.get_instance(self).__str__()[:-1] + '/{})'.format(self.id)
def from_noun_rule(cls, state, data): instance = cls(noun=data[1].local) # 1 because of the 'the' at pos 0. return data[1] + Interpretation(local=instance, argument=Argument(instances={instance: {instance}}))
def from_names_rule(cls, state, data): instances = {Instance(name=name) for name in data[0].local} instance=cls(instances=instances) return data[0] + Interpretation(local=instance, argument=Argument(instances={instance: {instance}}))
def from_pronoun_rule(cls, state, data): instance = cls(pronoun=data[0].local) return data[0] + Interpretation(local=instance, argument=Argument(instances={instance: {instance}}))
def text(self, argument: Argument): return argument.get_instance(self).__str__()
def from_noun_rule(cls, state, data): instance = cls(noun=data[1].local) # because 'the' return data[1] + Interpretation(argument=Argument(instances={instance: {instance}}), local=instance)
def from_rule(cls, state, data): claim = cls(data[0].local, data[1].local, data[2].local) return data[0] + data[1] + data[2] + Interpretation( argument=Argument(claims={claim: {claim}}), local=claim)
def is_same(self, other: 'Instance', argument: Argument) -> bool: return argument.get_instance(self) == argument.get_instance(other)
def from_name_rule(cls, state, data): instance = cls(name=data[0].local) return data[0] + Interpretation(argument=Argument(instances={instance: {instance}}), local=instance)
def __init__(self, argument: Argument = Argument(), local: Any = None): self.argument = argument self.local = local
def instantiate(self, claim, context): relation = Relation(sources={}, target=claim, type=self.type) argument = Argument(relations={relation}) if self.specifics is not None: instances = OrderedDict() claims = OrderedDict() for specific in self.specifics: # If we're connecting to a scoped statement, make sure we have the right scope if claim.scope and specific.scope != claim.scope: scoped_specific = specific.update(scope=claim.scope) relation.sources.add(scoped_specific) instances[scoped_specific.subject] = { scoped_specific.subject, specific.subject } claims[scoped_specific] = {scoped_specific, specific} else: relation.sources.add(specific) argument = argument + Argument(instances=instances, claims=claims) if self.make_assumptions and self.conditional is not None: argument = argument + Argument(relations={ Relation([self.conditional], relation, Relation.SUPPORT) }) conditions = find_conditions(self.conditional, context) if len(conditions) > 0: assumptions = [] for condition in conditions: params = { 'subject': claim.subject, 'verb': condition.verb.for_subject(claim.subject), } if condition.verb.literal in ('is', 'are'): params['object'] = getattr( condition.object, claim.subject.grammatical_number) assumptions.append(condition.assume(**params)) argument = argument + Argument(claims=dict( (assumption, {assumption}) for assumption in assumptions)) relation.sources.update(assumptions) if self.make_assumptions and self.conditional is None and self.specifics is not None: """ Make a general assumption in the trend of 'When Tweety can fly because she is a bird, anything that is a bird can fly.' """ scope = Scope() subject = Instance(pronoun=Span('something'), scope=scope) if self.type == Relation.SUPPORT: object = claim.object elif self.type == Relation.ATTACK: object = Negation( claim.object ) #is this ok? Or are we jumping to conclusions? else: assert False, "Can't deal with this kind of relation" conditional = GeneralClaim(subject, claim.verb, object, scope=scope, assumption=True) assumptions = [] for specific in self.specifics: if claim.subject.could_be(specific.subject): assumptions.append( specific.update(id=None, subject=conditional.subject, scope=scope)) if len(assumptions) > 0: argument = argument + Argument( instances={subject: {subject}}, claims={ conditional: {conditional}, **{ assumption: {assumption} for assumption in assumptions } }, relations={ Relation([conditional], relation, Relation.SUPPORT), Relation(assumptions, conditional, Relation.CONDITION) }) if len(relation.sources) == 0: raise Exception( "No specific claim or assumption to link the conditional claim to" ) return Interpretation(argument=argument, local=claim)