Example #1
0
def realize(jsrExpr,lang,addS=True):
    if addS and not isinstance(jsrExpr,S):
        jsrExpr=S(jsrExpr)
    realization=jsRealB(jsrExpr.set_lang(lang).pp())
    if savedJsrIO!=None:
        savedJsrIO.append((jsrExpr.show(),realization))
    return realization
Example #2
0
def amr2text(amrString, trace=False):
    if trace: print("*** AMR\n%s" % amrString)
    amrs.append(amrString)
    semR = SemanticRep.fromString(amrString)
    print("*** Semantic Representation - with inverse roles\n%s" %
          semR.prettyStr())
    dereified = dereify(semR)
    if dereified != None:
        semR = dereified
        if trace:
            print("*** Semantic Representation - [dereified]\n%s" %
                  semR.prettyStr())
    semR.elimInv()  # transform inverse roles
    if trace:
        print("*** Semantic Representation\n%s" % semR.prettyStr())


#         print("*** Baseline Generation\n%s"%semR.baselineGen())
    syntR = SemR2SyntR.makeSyntR(semR)
    if syntR is str:
        return syntR
    else:
        if not isinstance(syntR, (S, Q)):
            syntR = S(
                syntR)  # ensure that the complete output is a full sentence
        if trace:
            print("*** Syntactic Representation")
            try:
                print(syntR.show())
            except Exception as e:  ## for debugging the representation...
                print(syntR.pp0())
                raise e
        return jsRealB(syntR.show(-1))
Example #3
0
def showSyntR(syntR):
    print(syntR)
    print(syntR.show())
    print(jsRealB(syntR.show(-1)))
Example #4
0
                    arg0, VP(V("be"), A(adj), pp("for", arg1))))
        elif ":ARG1" in env and ":ARG2" in env:
            if isinstance(env[":ARG1"], Pro) and env[":ARG1"].lemma == "me":
                env[":ARG1"].lemma = "I"
            if isinstance(env[":ARG2"], Pro) and env[":ARG2"].lemma == "I":
                env[":ARG2"].lemma = "me"
            dictInfo = LexSem(
                adj, "S", [":ARG1", ":ARG2"], lambda arg1, arg2: S(
                    arg1, VP(V("be"), A(adj), pp("for", arg2))))
        elif ":ARG1" in env:
            if isinstance(env[":ARG1"], Pro) and env[":ARG1"].lemma == "me":
                env[":ARG1"].lemma = "I"
            dictInfo = LexSem(adj, "S", [":ARG1"],
                              lambda arg1: S(arg1, VP(V("be"), A(adj))))
    syntR = dictInfo.apply(env, opts)
    return syntR


if __name__ == '__main__':
    no = 0
    for test in tests[0:]:
        semR = SemanticRep.fromString(test).elimInv()
        print("*%d*" % no)
        print(semR.prettyStr())
        syntR = makeSyntR(semR)
        print(syntR)
        print(syntR.show())
        print(jsRealB(syntR.show(-1)))
        print("--------")
        no += 1
 def showSyntR(syntR):
     print(syntR.show())  # show the indented structure
     print(jsRealB(syntR.show(-1))) # get realized string