简体   繁体   中英

NLTK fcfg sem value is awkward

My FCFG that I used for this sentence was

S[SEM=<?vp(?np)>] -> NP[NUM=?n, SEM=?np] VP[NUM=?n,SEM=?vp] 
VP[NUM=?n,SEM=<?v(?obj)>] -> TV[NUM=?n,SEM=?v] DET NP[SEM=?obj
NP[NUM=?n, SEM=?np] -> N[NUM=?n, SEM=?np] 
N[NUM=sg, SEM=<\P.P(I)>] -> 'I'
TV[NUM=sg,SEM=<\x y.(run(y,x))>] -> 'run'
DET -> "a"
N[NUM=sg, SEM=<\P.P(race)>] -> 'race'

I want to parse out the sentence "I run a race" and when I used that sentence

sent = 'I run a race'
parser = load_parser('grammar.fcfg')

for tree in parser.parse(sent.split()):
    print (tree)

It returns a really awkward looking phrase for the parsed sentence

S[SEM=<run(\P.P(I3),\P.P(race))>]

However I wanted the code to return

S[SEM=<run(I,race)>]

How do I get rid of the \\PP which shouldn't belong there?

This is the normal form for nouns:

N[NUM=sg, SEM=<\x.race(x)>] -> 'race'

So, for example, you might have:

Det[NUM=sg, SEM=<\P.\Q.exists x.(P(x) & Q(x))>] -> 'a'
NP[NUM=?num, SEM=<?det(?n)>] -> Det[NUM=?num, SEM=?det] N[NUM=?num, SEM=?n]

So that "a race" is:

\P.\Q.exists x.(P(x) & Q(x))(\x.race(x)) = \Q.exists x.(\y.race(y)(x) & Q(x)))
                                           \Q.exists x.(race(x) & Q(x)))

And if you have:

TV[NUM=sg, SEM=<\X.\y.X(\x.run(y,x))>] -> 'run'
VP[NUM=?num, SEM=<?tv(?obj)>] -> TV[NUM=?num, SEM=?tv] NP[NUM=?num, SEM=?obj]

So "run a race" is:

\X.\y.X(\z.run(y,z))(\Q.exists x.(race(x) & Q(x))))
                                = \y.(\Q.exists x.(race(x) & Q(x)))(\z.run(y,z)))
                                = \y.exists x.(race(x) & \z.run(y,z)(x)))
                                = \y.exists x.(race(x) & run(y,x)))

And then you'd have:

NP[NUM=sg, SEM=<\P.P(I)>] -> 'I'
S[NUM=?num, SEM=<?subj(?vp)>] -> NP[NUM=?num, SEM=?subj] VP[NUM=?num, SEM=?vp] 

So "I run a race" is:

\P.P(I)(\y.exists x.(race(x) & run(y,x)))) = \y.exists x.(race(x) & run(y,x)))(I)
                                           = exists x.(race(x) & run(I,x)))

Have a look at this .

The reason that my initial code is awkward and returns

S[SEM=<run(\P.P(I3),\P.P(race))>]

Is because of type raising. The I and race are of different types where I is raised several times. That is why there is a

\P.P(I3)

So to fix this the I needs to be an argument not a higher type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM