Ejemplo n.º 1
0
def streetAddress91(concept,roles,env,opts):
    traceSyntR("streetAddress91", concept)
    res=SP()
    for i in range(1,7):
        argi=":ARG"+str(i)
        if argi in roles:
            argi_role=roles[argi]
            if argi_role.get_concept()==None:
                res.add(Q(unquote(argi_role.get_instance())))
            else:
                res.add(makeSyntR(argi_role))
    return res
Ejemplo n.º 2
0
def quantity(concept,roles,env,opts):
    traceSyntR("quantity",concept)
    if ":quant" in roles:
        qty=makeSyntR(roles[":quant"])
        if ":unit" in roles:
            unit=makeSyntR(roles[":unit"])
            if isinstance(unit,Pro): # get the referenced unit...
                unit=makeSyntR(roles[":unit"].instance)
            if isinstance(unit,NP) and qty!=None and isinstance(qty,NO):
                unit.elements[0]=qty
                qty=unit
            elif isinstance(unit,Phrase):
                qty=unit.add(qty)
            else:
                qty=SP(unit,qty)
        elif len(roles)>1 and isinstance(qty,Terminal):
            qty=NP(qty)
        if ":scale" in roles:
            qty.add(PP(P("on"),makeSyntR(roles[":scale"]),N("scale")))
        if ":*:ARG1" in roles:
            qty.add([D("the"),N("quantity"),Pro("that")])
        env.push(qty)
    return addRoles(concept,roles,[":quant",":unit",":scale"],LexSem("qty","SP",[],lambda:SP()),env,opts)
Ejemplo n.º 3
0
def dateEntity(concept,roles,env,opts):
    def zPad(s): #ensure a string of length 2 padded with a 0 
        if len(s)==2: return s
        if len(s)==1: return "0"+s
        if len(s)>2 : return s[0:2]
        return s
    
    def checkDateComp(date,rName,dOptField,length,default):
        if rName in roles:
            val=roles[rName].instance
            if is_number(val) and len(val)<=length:
                date+=val.rjust(length,"0")
                dOpt[dOptField]=True
            else:
                print("dateEntity: strange %s:%s"%(rName,val))
                date+=default
        else:
            date+=default
        return date
    
    traceSyntR("dateEntity",concept)
    if ":time" in roles and roles[":time"].get_concept()=="amr-unknown":
        return Q("what time is it ?")
    date="" # ISO format "YYYY-MM-DDTHH:mm:ss"
    dOpt={"year":False , "month":False , "date":False , "day":False , "hour":False , 
          "minute":False , "second":False , "nat":True, "det":False, "rtime":False}
    date=checkDateComp(date,":year","year",4,"2021")+"-"
    date=checkDateComp(date,":month", "month", 2, "01")+"-"
    date=checkDateComp(date,":day", "date", 2, "01")+"T"
    if ":time" in roles:
        timeS=roles[":time"].instance
        if isinstance(timeS,str) and ":" in timeS:
            time=unquote(timeS)
            tParts=time.split(":")
            if len(tParts)==2:
                tParts.append("00")
            if len(tParts)==3:
                date+=zPad(tParts[0])+":"+zPad(tParts[1])+":"+zPad(tParts[2])
                dOpt["hour"]=True
                dOpt["minute"]=True
                dOpt["second"]=True
    if not dOpt["hour"]:
        date+="00:00:00"
        dOpt["hour"]=False
        dOpt["minute"]=False
        dOpt["second"]=False
    sp=SP(DT(date+"-05:00").dOpt(dOpt))## HACK: force Montreal time zone  
    if ":timezone" in roles:
        sp.add(makeSyntR(roles[":timezone"]))
    if ":weekday" in roles:
        sp.add(Q(unquote(roles[":weekday"].get_concept()).capitalize()),0)
    if ":season" in roles:
        sp.add(Q(unquote(roles[":season"].get_concept())),0)
    if ":mod" in roles:
        sp.add(Q(unquote(roles[":mod"].get_concept())),0)
    if ":dayperiod" in roles:
        sp.add(Q(unquote(roles[":dayperiod"].get_concept())))
    if ":quarter" in roles:
        sp.add(NP(makeSyntR(roles[":quarter"]).dOpt({"ord":True}),N("quarter")))
    if ":year2" in roles:
        sp.add(makeSyntR(roles[":year2"]).dOpt({"raw":True}).b("-"))
    if ":era" in roles:
        sp.add(Q(unquote(roles[":era"].get_instance())))
    if ":calendar" in roles:
        sp.add(N("calendar").a(":"))
        sp.add(makeSyntR(roles[":calendar"]))
    if ":decade" in roles:
        sp.add(makeSyntR(roles[":decade"]))
        sp.add(Q("s"))
    return sp
Ejemplo n.º 4
0
def haveQuant91(concept,roles,env,opts):
    traceSyntR("haveQuant91",concept)
    if ":ARG1" in roles:
        quant=makeSyntR(roles[":ARG1"])
    else:
        errorSyntR("haveQuant91 without entity:%s"%concept)
        quant=SP(Q("*entity*"))
    if isinstance(quant,Terminal):
        quant=SP(quant)
    if ":ARG2" in roles:
        quant.add(makeSyntR(roles[":ARG2"]),0)
    else:
        quant.add(NP(D("the"),N("number"),P("of")),0)
    if ":ARG3" in roles:
        quant.add(VP(V("be"),makeSyntR(roles[":ARG3"])))        
    if ":ARG4" in roles:
        quant.add(PP(P("than"),
                        makeSyntR(roles[":ARG4"])))
    if ":ARG5" in roles:
        quant.add(PP(P("of"),makeSyntR(roles[":ARG5"])))
    if ":ARG6" in roles:
        quant.add(PP(P("for"),makeSyntR(roles[":ARG6"])))
    return addRoles(concept, roles, [":ARG1",":ARG2",":ARG3",":ARG4",":ARG5",":ARG6"], 
                    LexSem("qty","NP",[],lambda:quant), env, opts)