Ejemplo n.º 1
0
def causeRole(semR, env, opts):
    traceSyntR("causeRole", semR)
    concept = semR.get_concept()
    if concept == "amr-unknown":
        opts.add("typ", {"int": "why"})
    else:
        syntR = makeSyntR(semR)
        if isinstance(syntR, (N, Q)):
            env.push(SP(C("because"), P("of"), syntR))
        else:
            env.push(SP(C("because"), syntR))
Ejemplo n.º 2
0
def conditionRole(semR, env, opts):
    traceSyntR("conditionRole", semR)
    concept = semR.get_concept()
    if concept == "as-long-as":
        roles = semR.get_roles()
        if ":op1" in roles:
            env.push(PP(P("as"), A("long"), P("as"), makeSyntR(roles[":op1"])))
            return
    if concept == "otherwise":
        env.push(SP(C("otherwise"), makeSyntR(semR)))
    else:
        env.push(SP(C("if"), makeSyntR(semR)))
Ejemplo n.º 3
0
def processFrameOpRole(rolei, semRi, env, opts):
    if semRi.get_concept() == "amr-unknown" and rolei in questionTypes:
        opts.add("typ", {"int": questionTypes[rolei]})
        for roleii, semRii in semRi.roles.items():
            env.put(roleii, makeSyntR(semRii))
    elif semRi.concept == "amr-choice":
        opts.add("typ", {"int": "yon"})
        roles = semRi.roles
        if ":op1" in roles: env.push(makeSyntR(roles[":op1"]))
        if ":op2" in roles: env.push(SP(C("or"), makeSyntR(roles[":op2"])))
    else:
        syntRi = makeSyntR(semRi)
        if isinstance(syntRi, S):
            # infinitive when the sentence is a verb without subject
            if isinstance(syntRi.elements[0], VP):
                syntRi.elements[0].t("b")
                env.put(rolei, PP(P("to"), syntRi))
            elif semRi.parent != None and semRi.parent.concept not in [
                    "or", "and"
            ]:
                env.put(rolei, syntRi.add(Pro("that"), 0))
            else:
                env.put(rolei, syntRi)
        elif isinstance(syntRi, Pro) and syntRi.lemma == "I":
            if (rolei == ":ARG1" and ":ARG0" in env) or re.match(
                    ":ARG[2-9]", rolei):
                syntRi.lemma = "me"
                env.put(rolei, syntRi)
            else:
                env.put(rolei, syntRi)
        elif isinstance(syntRi, str):
            env.put(rolei, Q(syntRi))
        else:
            env.put(rolei, syntRi)
Ejemplo n.º 4
0
def concessionRole(semR, env, opts):
    traceSyntR("concessionRole", semR)
    syntR = makeSyntR(semR)
    if isinstance(syntR, (S, SP)):
        env.push(SP(C("although"), syntR))
    elif isinstance(syntR, (AdvP, Adv)):
        env.push(syntR)
    else:
        addPrep("despite", semR, env)
Ejemplo n.º 5
0
 def fuzzyQuant2(concept):
     roles = semR.get_roles()
     if ":op1" in roles and ":op2" in roles:
         env.put(
             ":D",
             PP(P("between"), makeSyntR(roles[":op1"]), C("and"),
                makeSyntR(roles[":op2"])))
         return True
     return False
Ejemplo n.º 6
0
def title_block(wInfo, lang):
    issueDate = wInfo.get_issue_date()
    noSecond = {"second": False}
    if lang == "en":
        s1 = S(
            NP(N("forecast").n("p")),
            VP(
                V("issue").t("pp"),
                PP(
                    P("by"), Q("jsRealB"),
                    DT(issueDate).dOpt(noSecond), P("for"),
                    CP(
                        C("and"), N("today"),
                        DT(issueDate + datetime.timedelta(days=1)).dOpt(
                            {"rtime": issueDate})))))
        s2 = S(
            NP(D("the"), D("next"),
               V("schedule").t("pp"),
               N("forecast").n("p")),
            VP(
                V("be").t("f"),
                V("issue").t("pp"),
                DT(wInfo.get_next_issue_date()).dOpt(noSecond)))
    else:
        s1 = S(
            NP(N("prévision").n("p")),
            VP(
                V("émettre").t("pp"),
                PP(
                    P("par"), Q("jsRealB"),
                    DT(issueDate).dOpt(noSecond), P("pour"),
                    CP(
                        C("et"), Adv("aujourd'hui"),
                        DT(issueDate + datetime.timedelta(days=1)).dOpt(
                            {"rtime": issueDate})))))
        s2 = S(
            NP(D("le"),
               A("prochain").pos("pre"),
               N("prévision").n("p")),
            VP(
                V("être").t("f"),
                V("émettre").t("pp"),
                DT(wInfo.get_next_issue_date()).dOpt(noSecond)))
    return "\n".join([realize(s1, lang, False), realize(s2, lang, False)])
Ejemplo n.º 7
0
def uv_index(wInfo,period,lang):
    if period in ["tonight","tomorrow_night"]:      # no UV index during the night
        return None
    uvi_terms=wInfo.get_uv_index(period)
    if uvi_terms==None:return None 
    uvVal=uvi_terms[0].infos[0]                     # consider only the first uvi_term
    if uvVal<1: return None                         # too low
    uvVal=round(uvVal)
    if uvVal==0:return None
    for high,expr in uv_ranges:
        if uvVal<=high:
            return realize(NP(Q("UV index" if lang=="en" else "indice UV"),
                              NO(uvVal),C("or" if lang=="en" else "ou"),expr[lang]),
                           lang)
    return None
Ejemplo n.º 8
0
 def processTime(concept, syntR):
     if concept == "amr-unknown":
         opts.add("typ", {"int": "whn"})
         env.push(syntR)
     elif syntR == A("former"):
         env.unshift(Adv("formerly"))
     elif syntR == Q("ex"):
         env.unshift(syntR)
     elif syntR == Q("about to"):
         env.push(Adv("about"))
         env.push(P("to"))
     elif isVerb(concept):
         env.push(SP(C("when"), syntR))
     elif isinstance(syntR, A):
         env.push(Adv(adverbFromAdjective(syntR.lemma)))
     else:
         env.push(syntR)
Ejemplo n.º 9
0
def locationRole(semR, env, opts):
    traceSyntR("locationRole", semR)
    concept = semR.get_concept()
    roles = semR.roles
    if concept == "amr-unknown":
        opts.add("typ", {"int": "whe"})
    elif concept == "between" and ":op1" in roles and ":op2" in roles:
        env.push(
            CP(C("and"), PP(P("between"), makeSyntR(roles[":op1"])),
               makeSyntR(roles[":op2"])))
        del roles[":op1"]
        del roles[":op2"]
    else:
        if isPreposition(concept) or isAdverb(concept):
            env.push(makeSyntR(semR))
        else:
            env.push(PP(P("in"), makeSyntR(semR)))
Ejemplo n.º 10
0
def processRoles(concept, roles, ignoredRoles, dictInfo, env, opts):
    traceSyntR("processRoles", str(dictInfo))

    for (rolei, semRi) in roles.items():
        if rolei not in ignoredRoles:
            if isArgOp(rolei) or (isinstance(dictInfo, LexSem)
                                  and rolei in dictInfo.args):
                processFrameOpRole(rolei, semRi, env, opts)
            elif rolei.startswith(':*'):
                processStarRole(rolei[2:], concept, semRi, env)
            elif rolei in roleSwitch:
                roleSwitch[rolei](semRi, env, opts)
            elif rolei.startswith(":conj-"):
                env.push(
                    SP(C(generateConceptWord(rolei[6:])), makeSyntR(semRi)))
            elif rolei.startswith(":prep-"):
                env.push(
                    PP(P(generateConceptWord(rolei[6:])), makeSyntR(semRi)))
            else:
                #             print("ignored role:"+rolei+":"+semRi.shortStr())
                env.push(makeSyntR(semRi))
    return dictInfo
Ejemplo n.º 11
0
def op16(conj):
    return LexSem(conj,"C",[":op1",":op2",":op3",":op4",":op5",":op6"],
                  lambda op1,op2,op3,op4,op5,op6:CP(C(conj),op1,op2,op3,op4,op5,op6))  
Ejemplo n.º 12
0
# coding=utf-8
from jsRealBclass import N,A,Pro,D,Adv,V,C,P,DT,NO,Q,  NP,AP,AdvP,VP,CP,PP,S,SP, jsRealB, Terminal, Phrase,Constituent
from amrDicoGen import pp,optD, nouns,adjectives,verbs,adverbs,prepositions, verbalizations ,morphVerbalizations

from lexicalSemantics import LexSem, nounInfo,adjInfo,pp,optD
import utils
import copy,re

## function to build a noun syntR
dn = lambda det,arg: NP(D(det),arg) if arg!=None else None
cn = lambda conj,arg:S(C(conj),arg) if arg!=None else None

def addOptions(syntR,opts):
    for (key,val) in opts.items():
        getattr(syntR, key)(val)
    return syntR

def delCat(dct,w):
    if w in dct:del dct[w]

### Pronouns
pronounOptions = {
    "I":{"pe":1},
    "i":{"pe":1},
    "me":{"pe":1},
    "you":{"pe":2},
    "he":{"pe":3,"g":"m"},
    "she":{"pe":3,"g":"f"},
    "it":{"pe":3,"g":"n"},
    "we":{"pe":1,"n":"p"},
    "they":{"pe":3,"n":"p"},
Ejemplo n.º 13
0
            (5,   {"en":A("moderate"),                "fr":A("modéré")}), 
            (7,   {"en":A("high"),                    "fr":A("élevé")}), 
            (10,  {"en":AP(Adv("very"), A("high")),   "fr":AP(Adv("très"),A("élevé"))}), 
            (1000,{"en":A("extreme"),                 "fr":A("extrême")})]

def uv_index(wInfo,period,lang):
    if period in ["tonight","tomorrow_night"]:      # no UV index during the night
        return None
    uvi_terms=wInfo.get_uv_index(period)
    if uvi_terms==None:return None 
    uvVal=uvi_terms[0].infos[0]                     # consider only the first uvi_term
    if uvVal<1: return None                         # too low
    uvVal=round(uvVal)
    if uvVal==0:return None
    for high,expr in uv_ranges:
        if uvVal<=high:
            return realize(NP(Q("UV index" if lang=="en" else "indice UV"),
                              NO(uvVal),C("or" if lang=="en" else "ou"),expr[lang]),
                           lang)
    return None


if __name__ == '__main__':
    def showEnFr(jsrExprEN,jsrExprFR):
        print(f" %s\n %s\n"%(realize(jsrExprEN,"en",False),realize(jsrExprFR,"fr",False)))
## exercise all kinds of uv_ranges
    for i in range(0,len(uv_ranges)):
        (val,jsrEnFr)=uv_ranges[i]
        showEnFr(NP(Q("UV"),N("index"),NO(val),C("or"),jsrEnFr["en"]),
                 NP(N("indice"),Q("UV"),NO(val),C("ou"),jsrEnFr["fr"]))
        
Ejemplo n.º 14
0
    isTomorrow=hour>23
    hour=hour%24
    for (s,e,jsrExp) in dayPeriods:
        if hour in range(s,e):
            exp=jsrExp[lang]()
            if isTomorrow:
                return exp.add(N("tomorrow" if lang=="en" else "demain"),0)
            elif s!=18:
                return exp.add(D("this" if lang=="en" else "ce"),0)

dayOnly={"day":True,"year": False, "month": False, "date": False,"hour":False,"minute":False, "second": False,"det":False}
periodNames = {
    "today":{"en":lambda _:N("today"),
             "fr":lambda _:Adv("aujourd'hui")},
    "tonight":{"en":lambda _:N("tonight"),
               "fr":lambda _:CP(C("et"),NP(D("ce"),N("soir")),NP(D("ce"),N("nuit")))},
    "tomorrow":{"en":lambda d:DT(d).dOpt(dayOnly),
                "fr":lambda d:DT(d).dOpt(dayOnly)},
    "tomorrow_night":{"en":lambda d:NP(DT(d).dOpt(dayOnly),N("night")),
                      "fr":lambda d:CP(C("et"),NP(DT(d).dOpt(dayOnly),N("soir")),NP(N("nuit")))}
}

### time generation

def jsrHour(h,lang):
    if h in range(0,6):
        return PP(P("during"),NP(D("the"),N("night"))) if lang=="en" else \
               PP(P("durant"),NP(D("le"),N("nuit")))
    if h in range(6,11):
        return PP(P("in"),NP(D("the"),N("morning"))) if lang=="en" else \
               NP(D("le"),N("matin"))
Ejemplo n.º 15
0
from jsRealBclass import N,A,Adv,V,D,P,C,DT,NO,Q, NP,AP,AdvP,VP,S,PP,CP
from Realization.common import realize, jsrDayPeriod

sky_condition_terminology = { ## types of sky conditions
    "c1":{"en":(AP(A("sunny")),AP(A("clear"))),
          "fr":(AP(A("ensoleillé")),AP(A("dégagé")))},
    "c2":{"en":(AP(Adv("mainly"),A("sunny")),NP(Q("a"),D("few"),N("cloud").n("p"))),
          "fr":(AP(Adv("généralement"),A("ensoleillé")),NP(D("quelque"),N("nuage").n("p")))},
    "c3":{"en":(NP(D("a"),N("mix"),PP(P("of"),CP(C("and"),N("sun"),N("cloud").n("p")))),
                AP(Adv("partly"),A("cloudy"))),
          "fr":(NP(N("alternance"),CP(C("et"),PP(P("de"),N("soleil")),PP(P("de"),N("nuage").n("p")))),
                AP(Adv("partiellement"),A("couvert")))},
    "c4":{"en":(AP(Adv("mainly"),A("cloudy")),),
          "fr":(AP(Adv("généralement"),A("nuageux")),)},
    "c5":{"en":(AP(A("cloudy")),),
          "fr":(AP(A("nuageux")),)},
    "c6":{"en":(AP(A("overcast")),),
          "fr":(AP(A("couvert")),)},
    "c7":{"en":(NP(V("increase").t("pr"),N("cloudiness")),),
          "fr":(NP(N("ennuagement")),)},
    "c8":{"en":(NP(N("clearing")),),
          "fr":(NP(N("dégagement")),)},
}

def sky_condition(mc,period,lang):
    previous_conditions=[]
    jsrExprs=[]

    def addNoRepeat(c,dn,period=None): # avoid generating same sentence twice
        if c not in previous_conditions:
            if len(sky_condition_terminology[c][lang])==1:dn=0