示例#1
0
def number(concept,roles,env,opts):
    traceSyntR("number", concept)
    if ":*:quant" in roles:
        roles1=roles[":*:quant"].get_roles()
        if ":quant" in roles1:
            del roles1[":quant"]
            dictInfo=nounInfo(concept)
            env.push(PP(P("of"),makeSyntR(roles[":*:quant"],False).n("p")))
            return addRoles(concept,roles,[":*:quant"],dictInfo,env,opts)
    return addRoles(concept, roles, [":*:quant"], nounInfo(concept), env, opts)
示例#2
0
def governmentOrganization(concept,roles,env,opts):
    traceSyntR("governmentOrganization", concept)
    if ":*:ARG0" in roles:
        if roles[":*:ARG0"].get_concept()=="govern-01":
            starArg0Roles=roles[":*:ARG0"].roles
            if len(roles)==1:
                return addRoles(concept, starArg0Roles, [":ARG0"], nounInfo("government"), env, opts)
            elif  ":ARG1" in starArg0Roles:
                dictInfo=nounInfo("government")
                env.push(PP(P("of"),makeSyntR(starArg0Roles[":ARG1"])))
                return addRoles(concept, starArg0Roles,[":ARG0",":ARG1"], dictInfo, env, opts)
    dictInfo=nounInfo("organization")
    env.put(":A",A("governmental"))
    return addRoles(concept, roles, [":*:ARG0"], dictInfo, env, opts)
示例#3
0
def checkNominalization(concept,roles,env,opts):
    traceSyntR("checkNominalization", concept)
    if roles.areEmpty():
        if concept in verbalizations and "" in verbalizations[concept]:
            nominalization=verbalizations[concept][""]
            return addRoles(nominalization,roles,[],nounInfo(nominalization),env,opts)
        elif isVerb(concept):
            verbLemma=re.sub(r"-\d+$","",concept)
            if verbLemma in morphVerbalizations and "noun" in morphVerbalizations[verbLemma]:
                nominalization=morphVerbalizations[verbLemma]["noun"]
                return addRoles(nominalization,roles,[],nounInfo(nominalization),env,opts)
        else:
            return None
    if concept in verbalizations:
        verbArgs=[key for key in verbalizations[concept].keys() if key!=""]
        if len(verbArgs)==0:return None
        for verbArg in verbArgs:
            if verbArg in roles:
                subSemR=roles[verbArg]
                if subSemR.concept in verbalizations[concept][verbArg]:
                    nominalization=verbalizations[concept][verbArg][subSemR.concept]
                    del subSemR.roles[verbArg[2:]] # remove added :ARGi corresponding to the :*:ARGi
                    # splice rest of roles of subSemR into parent roles
                    for rl,sem in subSemR.roles.items():
                        roles.addRole(rl,sem)
                    del roles[verbArg]
                    return addRoles(nominalization,roles,[],nounInfo(nominalization),env,opts)
    # process morphVerbalizations
    if isVerb(concept):
        verbLemma=re.sub(r"(-\d+)?$",r"",concept)
        if verbLemma in morphVerbalizations:
            morphVerb=morphVerbalizations[verbLemma]
            if ":polarity" in roles: return None #fail if :polarity role is present
            if ":ARG1" in roles:
                verbArgs=[key for key in roles.keys() if key!=":ARG1"]
                if any([isArgOp(arg) for arg in verbArgs]): return None #fail if any :ARGi or :opi is present
                # OK if :ARG1 is a pronoun that refers to the :ARG0 of the verb of the upper level
                if roles[":ARG1"].instanceIsRef():
                    refARG1=roles[":ARG1"].instance
                    instanceRole=refARG1.get_my_role()
                    if ":ARG0" == instanceRole and "noun" in morphVerb:
                        morphVerb=morphVerb["noun"]
                        return addRoles(morphVerb,roles,[":ARG1"],nounInfo(morphVerb),env,opts)
                # TODO: should check for "actor"...
    return None
示例#4
0
def person(concept,roles,env,opts):
    traceSyntR("person",concept)
    ## with a single :named role ignore person
    if ":named" in roles and len(roles)==1:
        return makeSyntR(roles[":named"])
    ## deal with frequent patterns associated with a person
    #### (p/person :ARG0-of (v / verb)) == ((p/person :*:ARG0 (v / verb :ARG0 p))) 
    ####         ==> find verbalization
    starARG0=roles[":*:ARG0"]
    if starARG0!=None:
        starARG0_ARG0=starARG0.roles[":ARG0"] if ":ARG0" in starARG0.roles else None
        if starARG0_ARG0!=None:
            if len(starARG0_ARG0.roles)==1:
                verb=starARG0_ARG0.get_concept()
                nom=getNominalization(verb)
                if nom!=None:
                    return addRoles(concept, roles, [":*:ARG0"], nounInfo(nom), env, opts)
        if re.match(r"have-(org|rel)-role-91",starARG0.get_concept()) and len(starARG0.roles)==2:
            ##### shortcut : https://www.isi.edu/~ulf/amr/lib/amr-dict.html#shortcuts
            ### (p2 / person :ARG0-of (h / have-org-role-91 :ARG2 (m / mayor))) ==
            ###      [person,\p2,[':*:ARG0',['have-org-role-91',h,[':ARG0',p2], [':ARG2',[mayor,m]]] ==>
            ###  mayor !!!
            starARG0_ARG2=starARG0.roles[":ARG2"]
            if starARG0_ARG2!=None:
                nom=makeSyntR(starARG0_ARG2)
                if isinstance(nom,(NP,N)):
                    return addRoles(concept, roles, [":*:ARG0"], LexSem("person","NP",[],lambda:nom), env, opts)
        if re.match(r"have-(org|rel)-role-91",starARG0.get_concept()) and len(starARG0.roles)==3:
            ##### shortcut : https://www.isi.edu/~ulf/amr/lib/amr-dict.html#shortcuts
            ### (p / person
            ###          :ARG0-of (h / have-rel-role-91 :ARG1 (i / i):ARG2 (g / mother))) ==
            ### (p person [:*:ARG0 (h2 have-rel-role-91 [:ARG1 ^h ↑h2,
            ###                                          :ARG2 (m mother [] ↑h2),
            ###                                          :ARG0 ^p ↑h2] ↑p) ^_])            
            ###   (his/her) mother !!! 
            starARG0_ARG1=starARG0.roles[":ARG1"]
            starARG0_ARG2=starARG0.roles[":ARG2"]
            person=None
            if starARG0_ARG1!=None and starARG0_ARG2!=None and isNoun(starARG0_ARG2.get_concept()):
                conceptSyntR=makeSyntR(starARG0_ARG2)
                if starARG0_ARG1.instanceIsRef():
                    env.put(":D",makePoss(SemR2SyntR.instance2SyntR(starARG0_ARG1)))
                    person=addRoles(concept, starARG0_ARG2.roles,[":ARG1",":ARG2"], 
                                    LexSem("person","NP",[],lambda:conceptSyntR), env, opts)
                elif starARG0_ARG1.roles.areEmpty():
                    starARG0_ARG1concept=starARG0_ARG1.get_concept()
                    if isNoun(starARG0_ARG1concept):
                        env.put(":D",makeSyntR(starARG0_ARG1))
                        person=addRoles(concept,starARG0_ARG2.roles,[":ARG1",":ARG2",":ARG0"],
                                        LexSem("person","NP",[],lambda:conceptSyntR),env,opts)
                    elif isPronoun(starARG0_ARG1concept):
                        conceptSyntR.elements[0]=makePoss(starARG0_ARG1concept)
                        person=addRoles(concept,starARG0_ARG2.roles,[":ARG1",":ARG2",":ARG0"],
                                        LexSem("person","NP",[],lambda:conceptSyntR),env,opts)
                if person!=None:
                    return addRoles(concept, roles, [":*:ARG0"],LexSem("person","NP",[],lambda:person), env, opts)
    return namedEntity(concept,roles,env,opts)
示例#5
0
def namedEntity(concept,roles,env,opts):
    name = roles[":name"]
    if name != None:
#         name_named = name.roles[":named"] or name.roles[":op1"]
#         if name_named != None:
#             #### (p / NamedEntity :name NAME  other roles)) replaced by evaluation of NAME followed by other roles
#             nameSyntR=
#             return addRoles(concept, name.roles, [":named",":op1"], quoteInfo(name_named.get_instance()), env, opts)
        if name.concept == "name":
            nameSyntR=makeSyntR(name)
            return addRoles(concept, roles, [":name"], LexSem("name","NP",[],lambda:nameSyntR), env, opts)
        return addRoles(concept, roles, [":name"], nounInfo(concept), env, opts)
    return None