Presentation is loading. Please wait.

Presentation is loading. Please wait.

How to perform tree surgery Anna Rafferty Marie-Catherine de Marneffe.

Similar presentations


Presentation on theme: "How to perform tree surgery Anna Rafferty Marie-Catherine de Marneffe."— Presentation transcript:

1 How to perform tree surgery Anna Rafferty Marie-Catherine de Marneffe

2 Tsurgeon by Roger Levy What? makes operations on a grammatical tree How? based on Tregex syntax Where? Javanlp: trees.tregex.tsurgeon

3 How? Tregex utility for identifying patterns in trees (like regular expressions for strings) node descriptions and relationships between nodes NP < /^NN/ NP NN filterscigaretteitsin croco- dilite usingstoppedfirmThe PRP IN PPVBG VPVBDDT VP S NN NP NN NP NNS

4 Tsurgeon syntax Define a pattern to be matched on the trees VBZ=vbz $ NP Define one or several operation(s) relabel vbz VBZ_TRANSITIVE

5 Delete (ROOT (SBARQ (SQ (NP (NNS Cats)) (VP (VBP do) (VP (WHNP what) (VB eat))) (PUNCT ?))) PUNCT=punct > SBARQ delete punct

6 Delete (ROOT (SBARQ (SQ (NP (NNS Cats)) (VP (VBP do) (VP (WHNP what) (VB eat))) (PUNCT ?))) PUNCT=punct > SBARQ delete punct Delete the node and everything below it delete …

7 Excise (ROOT (SBARQ (SQ (NP (NNS Cats)) (VP (VBP do) (VP (WHNP what) (VB eat)))))) SBARQ=sbarq > ROOT excise sbarq sbarq (ROOT (SQ (NP (NNS Cats)) (VP (VBP do) (VP (WHNP what) (VB eat)))))

8 Excise (ROOT (SBARQ (SQ (NP (NNS Cats)) (VP (VBP do) (VP (WHNP what) (VB eat)))))) SBARQ=sbarq > ROOT excise sbarq sbarq name1 is name2 or dominates name2. All children of name2 go into the parent of name1, where name1 was. excise

9 Prune prune … Different from delete : If after the pruning the parent has no children anymore, the parent is pruned too.

10 Insert (ROOT (SQ (NP (NNS Cats)) (VP (VBP do) (VP (WHNP what) (VB eat))))) SQ=sq > ROOT !<- /PUNCT/ insert (PUNCT.) >-1 sq (ROOT (SQ (NP (NNS Cats)) (VP (VBP do) (VP (WHNP what) (VB eat))) (PUNCT.))) Caveat: cyclic application of rules

11 Position for ‘insert’ and ‘move’ insert := $+ the left sister of the named node $-the right sister of the named node >i the i_th daughter of the named node >-i the i_th daughter, counting from the right, of the named node.

12 Move (ROOT (SQ (NP (NNS Cats)) (VP (VBP do) (VP (WHNP what) (VB eat))) (PUNCT.))) VP < (/^WH/=wh $++ /^VB/=vb) move vb $+ wh move moves the named node into the specified position

13 Move (ROOT (SQ (NP (NNS Cats)) (VP (VBP do) (VP (WHNP what) (VB eat))) (PUNCT.))) VP < (/^WH/=wh $++ /^VB/=vb) move vb $+ wh (ROOT (SQ (NP (NNS Cats)) (VP (VBP do) (VP (VB eat) (WHNP what))) (PUNCT.)))

14 Adjoin (ROOT (SQ (NP (NNS Cats)) (VP (VBP do) (VP (VB eat) (WHNP what))) (PUNCT.))) VP=vp > SQ !> (__ << usually) adjoin (VP (ADVP (ADV usually)) VP@) vp (ROOT (SQ (NP (NNS Cats)) (VP (ADVP (RB usually)) (VP (VBP do) (VP (VB eat) (WHNP what))) (PUNCT.)))

15 Adjoin syntax adjoin Adjoins the specified auxiliary tree into the named node. The daughters of the target node will become the daughters of the foot of the auxiliary tree. adjoin (VP (ADVP (ADV usually)) VP@) vp foot

16 On the command line java Tsurgeon -treeFile [ ]* aFile -> a file containing the trees to be transformed operationFile -> pattern (Tregex expression) an empty line operation(s) (one by line)

17 How to use the Tsurgeon class TregexPattern matchPattern = TregexPattern.compile("SQ=sq < (/^WH/ $++ VP)"); List ps = new ArrayList (); TsurgeonPattern p = Tsurgeon.parseOperation("relabel sq S"); ps.add(p); Collection result = Tsurgeon.processPatternOnTrees(matchPattern,Tsurgeon. collectOperations(ps),lTrees);

18 To become a specialist See Roger’s README! Practice tree surgery!


Download ppt "How to perform tree surgery Anna Rafferty Marie-Catherine de Marneffe."

Similar presentations


Ads by Google