예제 #1
0
def possRole(semR, env, opts):
    traceSyntR("possRole", semR)
    if semR.get_concept() == "amr-unknown":
        env.push(PP(P("of"), Pro("whom")))
        opts.add("a", "?")
    else:
        syntR = makeSyntR(semR)
        if isinstance(syntR, D):
            env.put(":D", syntR)
        elif isinstance(syntR, Pro):
            concept = semR.concept
            if concept != None:
                env.put(":D", makePoss(concept))
            elif isinstance(semR.instance, SemanticRep.SemanticRep):
                ref = semR.instance.get_concept()
                poss = D("my")
                if isNoun(ref):
                    g = nouns[ref]["g"]
                    env.put(":D", poss.g(g if g != None else "n"))
                elif isPronoun(ref):
                    poss.props = pronounOptions[ref]
                    env.put(
                        ":D",
                        poss.g(pronounOptions[ref]["g"] if "g" in
                               pronounOptions[ref] else "m"))
                else:
                    env.put(":D", poss)
            else:
                env.put(":D", makePoss(syntR.lemma))
        else:
            env.push(PP(P("of"), syntR))
예제 #2
0
def scaleRole(semR, env, opts):
    traceSyntR("scaleRole", semR)
    semR_c = semR.get_concept()
    if (semR_c == "celsius"):
        env.push(PP(makeSyntR(semR), N("degree"), Q("Celsius")))
    else:
        env.push(PP(P("on"), D("the"), makeSyntR(semR), N("scale")))
예제 #3
0
def comparedToRole(semR, env, opts):
    traceSyntR("comparedToRole", semR)
    global comp
    if comp == "co":
        env.push(PP(P("than"), makeSyntR(semR)))
        return
    if comp == "su":
        env.push(PP(P("in"), makeSyntR(semR)))
        return
    errorSyntR(" :compared-to without :degree:%s in %s" % (semR, semR.parent))
예제 #4
0
def makeP(lemma):
    prep=prepositions[lemma]
    if isinstance(prep,PP):
        return LexSem(lemma,"P",[":op1"],lambda op1:copy.deepcopy(prep).add(accPron(op1)))
    if isinstance(prep,P):
        return LexSem(lemma,"P",[":op1"],lambda op1:PP(copy.deepcopy(prep),accPron(op1)))
    if isinstance(prep,str):
        return LexSem(lemma,"P",[":op1"],lambda op1:P(prep) if op1==None else PP(P(prep),accPron(op1)))
    print("### strange preposition:"+str(prep))
    return prep
예제 #5
0
def temp_trend(lang, trend, goalTemp, when):
    if lang == "en":
        return S(
            N("temperature"),
            VP(V(trend).t("pr"), PP(P("to"), jsrTemp(goalTemp, lang)), when))
    else:
        return S(
            NP(N("température").n("p"), PP(P("à"), NP(D("le"), N(trend)))),
            PP(P("pour"),
               V("atteindre").t("b"), jsrTemp(goalTemp, lang), when))
예제 #6
0
def purposeRole(semR, env, opts):
    traceSyntR("purposeRole", semR)
    roles = semR.get_roles()
    if ":ARG0" in roles:
        # remove useless subject reference to a variable
        del roles[":ARG0"]
    syntR = makeSyntR(semR)
    if isinstance(syntR, S) and isinstance(syntR.elements[0], VP):
        env.push(PP(P("for"), syntR.elements[0].t("pr")))
    else:
        env.push(PP(P("for"), syntR))
예제 #7
0
def timeRole(semR, env, opts):
    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)

    traceSyntR("timeRole", semR)
    syntR = makeSyntR(semR)
    concept = semR.get_concept()
    if concept == 'date-entity':  # very frequent case
        env.push(PP(P("on"), syntR))
        return
    return processTime(concept, syntR)
예제 #8
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)
예제 #9
0
 def apply(self, env=None, opts=None):
     if env == None: env = Env()
     if opts == None: opts = Options()
     ## process args from dictInfo building the list of arguments or None
     argV = [env.get(arg) if arg in env else None for arg in self.args]
     syntR = self.lambda_(*argV)
     if all([arg == None for arg in argV]) and len(env) == 0:
         return opts.apply(syntR)
     if isinstance(syntR, Terminal):
         if isinstance(syntR, A):
             if ":ARG1" in env:
                 syntR = S(env.get(":ARG1"), VP(V("be"), syntR))
             else:
                 syntR = AP(syntR)
         elif isinstance(syntR, (Pro, Q, NO)):
             syntR = SP(syntR)
         elif isinstance(syntR, Adv):
             syntR = AdvP(syntR)
         elif isinstance(syntR, P):
             syntR = PP(syntR)
         else:
             print("** apply: strange syntR:%s:%s" % (type(syntR), syntR))
             syntR = SP(syntR)
     ## add unprocessed args
     if len(env) > 0:
         syntR.add(env.get(":start"), 0)
         syntR.add(env.get(".*"))
     return opts.apply(syntR)
예제 #10
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)))
예제 #11
0
def havePurpose91(concept,roles,env,opts):
    if ":ARG2" in roles:
        if roles[":ARG2"].get_concept()=="amr-unknown":
            env.put(":start",Q("For what ?"))
        return addRoles(concept, roles, [],
                        LexSem("have-purpose","S",[":ARG1",":ARG2"],
                               lambda arg1,arg2:S(arg1,VP(V("be"),PP(P("for"),arg2)))), env, opts)
    return None
예제 #12
0
def modRole(semR, env, opts):
    def simpleModNoun(concept, neg):  ## check for "simple" cases
        if concept in [
                "all", "many", "both", "no", "too", "any", "other", "some",
                "one", "kind-yy", "then", "such"
        ]:
            env.put(":D", Q("kind of" if concept == "kind-yy" else concept))
            if neg: env.unshift(Q("not"))
            if concept in ["all", "many", "both"]:
                opts.add("n", "p")
        elif concept in determiners:
            env.put(":D", D(concept))
        elif is_number(concept):
            env.push(NO(concept))
        elif isNoun(concept):  ## prefix the :mod for nouns
            newNoun = N(nouns[concept].lemma)  # keep only noun from NP
            if ":A" in env:
                env.insertAfter(":A", ":A", newNoun)
            else:
                env.put(":A", newNoun)
            if neg: env.insertBefore(":A", ":A", Q("non"))
        elif isAdjective(concept):  ## postfix the :mod for adjectives
            newAdj = A(adjectives[concept].lemma)
            if ":A" in env:
                env.insertAfter(":A", ":A", newAdj)
            else:
                env.put(":A", newAdj)
            if neg: env.insertBefore(":A", ":A", Q("non"))
        elif isAdverb(concept):
            env.put(":D", Adv(concept))
        elif isVerb(concept):
            env.push(V(re.sub(r"-\d+$", '', concept)).t("pr"))
        elif semR.roles.areEmpty():  ## equivalent to processSimpleModOther
            env.push(Q(generateConceptWord(concept)))
        else:
            return False
        return True

    traceSyntR("modRole", semR)
    concept = semR.get_concept()
    if concept == None:
        env.push(makeSyntR(semR))
        return
    roles = semR.roles
    neg = False
    if hasNegPolarity(
            roles):  # negation will be applied to the generated relative
        neg = True
    if roles.areEmpty():
        simpleModNoun(concept, neg)
        return
    syntR = makeSyntR(semR)
    if isinstance(syntR, (N, NP)):
        env.push(PP(P("of"), syntR))
    else:
        rel = relative(concept, syntR)
        if neg: rel.typ({"neg": True})
        env.push(rel)
예제 #13
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
예제 #14
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)])
예제 #15
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)
예제 #16
0
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"))
    if h in range(11,14):
        return PP(P("around"),N("noon")) if lang=="en" else \
               PP(P("vers"),N("midi"))
    if h in range(14,18):
        return PP(P("in"),NP(D("the"),N("afternoon"))) if lang=="en"  else \
               PP(P("durant"),NP(D("le"),N("après-midi")))
    if h in range(18,24):
        return PP(P("in"),NP(D("the"),N("evening"))) if lang=="en"  else \
               PP(P("dans"),NP(D("le"),N("soirée"))) 
예제 #17
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)))
예제 #18
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)
예제 #19
0
def pathRole(semR, env, opts):
    traceSyntR("pathRole", semR)
    concept = semR.get_concept()
    if concept == "past" and ":op1" in semR.roles:
        env.push(AdvP(Adv("past"), makeSyntR(semR.roles[":op1"])))
    else:
        syntR = makeSyntR(semR)
        if isinstance(syntR, Pro):
            syntR.lemma = "me"
        else:
            if isinstance(syntR, (Adv, P, PP)):
                env.push(syntR)
            else:
                env.push(PP(P("via"), syntR))
예제 #20
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)
예제 #21
0
def mannerRole(semR, env, opts):
    traceSyntR("mannerRole", semR)
    cManner = semR.get_concept()
    if cManner == "amr-unknown":
        opts.add("typ", {"int": "how"})
    else:
        syntR = makeSyntR(semR)
        if isinstance(syntR, Q):
            env.push(syntR)
        elif isinstance(syntR, A):
            adv = Adv(adverbFromAdjective(syntR.lemma))
            adv.props = syntR.props
            env.push(adv)
        elif isinstance(syntR, (S, V, VP)):
            env.push(PP(P("by"), syntR.typ({"prog": True})))
        else:
            addPrep("with", semR, env)
예제 #22
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
예제 #23
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)
예제 #24
0
    if lang == "en":
        return S(
            N("temperature"),
            VP(V(trend).t("pr"), PP(P("to"), jsrTemp(goalTemp, lang)), when))
    else:
        return S(
            NP(N("température").n("p"), PP(P("à"), NP(D("le"), N(trend)))),
            PP(P("pour"),
               V("atteindre").t("b"), jsrTemp(goalTemp, lang), when))


jsrAbnormal = {
    "night": {
        "a": {
            "en":
            lambda t, _: temp_trend("en", "rise", t, PP(P("by"), N("morning"))
                                    ),
            "fr":
            lambda t, _: temp_trend("fr", "hausse", t, PP(
                P("en"), N("matinée")))
        },
        "b": {
            "en":
            lambda t, u: S(
                Adv("low"), u.a(","), P("with"),
                temp_trend("en", "rise", t, PP(P("by"), N("morning")))),
            "fr":
            lambda t, u: S(
                N("minimum"), u.a(","),
                temp_trend("fr", "hausse", t, PP(P("en"), N("matinée"))))
        },
예제 #25
0
                  lambda op1,op2,op3,op4,op5,op6:CP(C(conj),op1,op2,op3,op4,op5,op6))  
def op12(lemma,np,prep):
    return LexSem(lemma,"P",[":op1",":op2"],
                  lambda op1,op2:SP(np,op1,pp(prep,op2)))
conjunctions={}   
conjunctions["or"]=op16("or")
conjunctions["and"]=op16("and")
conjunctions["either"]=op16("either")
conjunctions["product-of"]=op16("times")
conjunctions["sum-of"]=op16("and")
conjunctions["ratio-of"]=op12("ratio-of",NP(N("ratio"),P("of")),"to")
conjunctions["difference-of"]=op16("minus")
conjunctions["quotient-of"]=op16("divided by")
conjunctions["power-of"]=op16("to the power of")
conjunctions["root-of"]= LexSem("root-of","P",[":op1",":op2"],
                                lambda op1,op2:NP(NO(op2[0].lemma).dOpt({"ord":True}),N("root"),PP(P("of"),op1)))
conjunctions["logarithm-of"]= LexSem("log-of","P",[":op1",":op2"],
                                     lambda op1,op2:NP(N("logarithm"),PP(P("of"),op1,N("base").a(":"),op2)))

def isConjunction(lemma):return lemma in conjunctions
def makeCP(lemma):
    return  conjunctions[lemma]

### Adverbs
adverbs["et-cetera"]=AdvP(Adv("etc"))
adverbs["at-least"]=AdvP(P("at"),Adv("least"))
adverbs["next-to"]=AdvP(Adv("next"),P("to"))
adverbs["kind-of"]=AdvP(Q("kind of"))
adverbs["away"]=AdvP(Adv("away"),P("from"))
delCat(adverbs,"between")
delCat(adverbs,"near")
예제 #26
0
파일: Wind.py 프로젝트: rali-udem/jsRealB
def wind(wInfo, period, lang):
    wind_terms = wInfo.get_wind(period)
    if wind_terms == None: return None
    lastSpeed = None
    lastDir = None
    jsrExprs = []
    for wind_term in wind_terms:
        wSpeed = wind_term.infos[2]
        wDir = wind_term.infos[0]
        jsrExpr = S()  # current expression
        if wSpeed >= 15 and wDir in jsrWindDirection:
            if lastSpeed != None and abs(
                    wSpeed - lastSpeed) >= 20:  # significant speed change
                lastSpeed = wSpeed
                if lang == "en":
                    jsrExpr.add(
                        VP(V("increase").t("pr"), PP(P("to"), NO(wSpeed))))
                else:
                    jsrExpr.add(
                        VP(V("augmenter").t("pr"), PP(P("à"), NO(wSpeed))))
            elif lastDir != None and dir_diff(
                    wDir, lastDir):  # significant direction change
                if lang == "en":
                    jsrExpr.add(
                        VP(V("become").t("pr"), jsrWindDirection[wDir][lang]))
                else:
                    jsrExpr.add(
                        VP(
                            V("devenir").t("pr"),
                            PP(P("de"), jsrWindDirection[wDir][lang])))
                lastDir = wDir
            else:  # realize wind and direction
                lastSpeed = wSpeed
                lastDir = wDir
                if lang == "en":
                    jsrExpr.add(
                        NP(N("wind"), jsrWindDirection[wDir][lang], NO(wSpeed),
                           Q("km/h")))
                else:
                    jsrExpr.add(
                        NP(
                            N("vent").n("p"),
                            PP(P("de"), jsrWindDirection[wDir][lang]),
                            PP(P("de"), NO(wSpeed), Q("km/h"))))
            if len(wind_term.infos) > 3:  # add gusting information
                gust = wind_term.infos[3]
                if gust.infos[0] == 'gust':
                    if lang == "en":
                        jsrExpr.add(
                            VP(
                                V("gust").t("pr"),
                                PP(P("to"), NO(gust.infos[1]))))
                    else:
                        jsrExpr.add(
                            PP(
                                P("avec"),
                                NP(
                                    N("rafale").n("p"), P("à"),
                                    NO(gust.infos[1]))))
            else:  # add time information
                jsrExpr.add(jsrHour(wind_term.start, lang))
            jsrExprs.append(jsrExpr)  # add current expression to the list
    return " ".join(realize(jsrExpr, lang, False) for jsrExpr in jsrExprs)
예제 #27
0
파일: Wind.py 프로젝트: rali-udem/jsRealB
                gust = wind_term.infos[3]
                if gust.infos[0] == 'gust':
                    if lang == "en":
                        jsrExpr.add(
                            VP(
                                V("gust").t("pr"),
                                PP(P("to"), NO(gust.infos[1]))))
                    else:
                        jsrExpr.add(
                            PP(
                                P("avec"),
                                NP(
                                    N("rafale").n("p"), P("à"),
                                    NO(gust.infos[1]))))
            else:  # add time information
                jsrExpr.add(jsrHour(wind_term.start, lang))
            jsrExprs.append(jsrExpr)  # add current expression to the list
    return " ".join(realize(jsrExpr, lang, False) for jsrExpr in jsrExprs)


if __name__ == '__main__':

    def showEnFr(jsrExprEN, jsrExprFR):
        print(
            f" %-30s %s" %
            (realize(jsrExprEN, "en", False), realize(jsrExprFR, "fr", False)))

    for wd in jsrWindDirection:
        showEnFr(NP(N("wind"), jsrWindDirection[wd]["en"]),
                 NP(N("vent").n("p"), PP(P("de"), jsrWindDirection[wd]["fr"])))
예제 #28
0
        return "LexSem(%s,%s)" % (self.lemma, self.pos)

    def apply(self, env=None, opts=None):
        if env == None: env = Env()
        if opts == None: opts = Options()
        ## process args from dictInfo building the list of arguments or None
        argV = [env.get(arg) if arg in env else None for arg in self.args]
        syntR = self.lambda_(*argV)
        if len(env) > 0:
            ## add unprocessed args
            syntR.add(env.get(":start"), 0)
            syntR.add(env.get(".*"))
        return opts.apply(syntR)


pp = lambda prep, arg: PP(P(prep), arg) if arg != None else None
optD = lambda det: det if det != None else D("the")

verbs['give-01'] = LexSem(
    "V", "give", [":ARG0", ":ARG1", ":ARG2"],
    lambda arg0, arg1, arg2: S(arg0, VP(V("give"), arg1, pp("to", arg2))))

nouns['envelope'] = LexSem("envelope", "N", [":D", ":A"],
                           lambda d, a: NP(optD(d), a, N("envelope")))
nouns['boy'] = LexSem("boy", "N", [":D", ":A"],
                      lambda d, a: NP(optD(d), a, N("boy")))
nouns['girl'] = LexSem("girl", "N", [":D", ":A"],
                       lambda d, a: NP(optD(d), a, N("girl")))

adjectives["little"] = LexSem("little", "A", [], lambda: A("little"))
adjectives["nice"] = LexSem("nice", "A", [], lambda: A("nice"))
예제 #29
0
def quantRole(semR, env, opts):
    def processSimpleQuant(concept):
        simpleQuants = {  # concept: string to add to the start, boolean to indicate if plural
            "most": ["most of", True],
            "more": ["more", True],
            "numerous": ["numerous", True],
            "many": ["many", True],
            "multiple": ["multiple", True],
            "few": ["few", True],
            "some": ["some", False],
            "such": ["a sack of", False],
            "last": ["last", False],
            "one": ["one", False],
            "entire": ["entire", False],
            "lot": ["a lot", False],
            "sack": ["a sack of", False]
        }
        if concept in simpleQuants:
            if concept == "lot":
                env.push(Q(simpleQuants[concept][0]))
            else:
                env.unshift(Q(simpleQuants[concept][0]))
            if simpleQuants[concept][1]: opts.add("n", "p")
            return True
        return False

    #  fuzzy operators from https://www.isi.edu/~ulf/amr/lib/popup/quantities.html#non-exact-quantities
    #  role :op1
    #  about, above, almost, approximately, around, at-least, at-most, below, close-to, couple, few, less-than,
    #  lot, many, more-than, multiple, nearly, no-more-than, over, roughly, several, some, under, up-to
    #  number is dealt separately
    def fuzzyQuant1(concept):
        fuzzyQuants = [
            'about', 'above', 'almost', 'approximately', 'around', 'at-least',
            'at-most', 'below', 'close-to', 'couple', 'few', 'less-than',
            'lot', 'many', 'more-than', 'nearly', 'no-more-than', 'over',
            'roughly', 'several', 'some', 'under', 'up-to'
        ]
        if concept == "multiple":
            env.unshift(Q("multiple"))
            env.push(Q("of"))
            if ":op1" in semR.roles:
                env.push(makeSyntR(semR.roles[":op1"]))
            return True
        if concept in fuzzyQuants and ":op1" in semR.roles:
            env.put(
                ":D",
                AP(Q(generateConceptWord(concept)),
                   makeSyntR(semR.roles[":op1"])))
            opts.add("n", "p")
            return True
        return False

    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

    traceSyntR("quantRole", semR)
    concept = semR.get_concept()
    roles = semR.roles
    if len(roles) == 0 and processSimpleQuant(concept): return
    if fuzzyQuant1(concept): return
    if fuzzyQuant2(concept): return
    if isinstance(concept, str) and re.match(r'.+-quantity$', concept):
        env.unshift(
            PP(specialConcept.quantity(concept, roles, Env(), Options()),
               P("of")))
        return

    if concept == "amr-unknown":
        env.unshift(AdvP(Adv("how"), Adv("much")))
        opts.add("a", "?")
    else:
        syntR = makeSyntR(semR, False)
        if isinstance(syntR, NO):
            env.put(":D", syntR)
        else:
            env.unshift(PP(syntR, P("of")))
예제 #30
0
def addPrep(prep, semR, env):
    syntR = makeSyntR(semR)
    if isinstance(syntR, Pro) and syntR.lemma == "I":
        syntR.lemma = "me"
    env.push(PP(P(prep), syntR))