linguistics
¶%load_ext tikz_magic
forest
¶%%tikz -p forest --no-wrap -s 0.5
\begin{forest}
[VP
[DP[John]]
[V’
[V[sent]]
[DP[Mary]]
[DP[D[a]][NP[letter]]]
]
]
\end{forest}
%%tikz -p forest --no-wrap -s 0.5
\begin{forest}
[VP, for tree={parent anchor=south, child anchor=north}
[DP[John,tier=word]]
[V’
[V[sent,tier=word]]
[DP[Mary,tier=word]]
[DP[D[a,tier=word]][NP[letter,tier=word]]]
]
]
\end{forest}
tikz-dependency
¶%%tikz -p tikz-dependency --no-wrap -s 0.5
\begin{dependency}
\begin{deptext}
My \& dog \& also \& likes \& eating \& parsnips \\
\end{deptext}
\depedge{2}{1}{poss}
\depedge{4}{2}{nsubj}
\depedge{4}{3}{advmod}
\depedge{4}{5}{xcomp}
\depedge{5}{6}{dobj}
\end{dependency}
%%tikz -p tikz-dependency --no-wrap -s 0.5
\begin{dependency}[theme = simple]
\begin{deptext}[column sep=1em]
A \& hearing \& is \& scheduled \& on \& the \& issue \& today \& . \\
\end{deptext}
\deproot{3}{ROOT}
\depedge{2}{1}{ATT}
\depedge{2}{5}{ATT}
\depedge{3}{2}{SBJ}
\depedge{3}{9}{PU}
\depedge{3}{4}{VC}
\depedge{4}{8}{TMP}
\depedge{5}{7}{PC}
\depedge[arc angle=50]{7}{6}{ATT}
\end{dependency}
nltk
¶import nltk
sentence = [("the", "DT"), ("little", "JJ"), ("yellow", "JJ"),
("dog", "NN"), ("barked", "VBD"), ("at", "IN"), ("the", "DT"), ("cat", "NN")]
grammar = "NP: {<DT>?<JJ>*<NN>}"
cp = nltk.RegexpParser(grammar)
result = cp.parse(sentence)
print(result)
(S (NP the/DT little/JJ yellow/JJ dog/NN) barked/VBD at/IN (NP the/DT cat/NN))
#issue - https://github.com/nltk/nltk/issues/1765
result