追加の矢印が付いた依存関係ツリーグラフ

追加の矢印が付いた依存関係ツリーグラフ

私は、Stanford Parser を使用してツリー (黒いコンポーネント) を構築しました。ただし、グラフをエクスポートできないため、スクリーンショットを撮る必要がありました。次に、そのグラフに、そのラベルが付いた 2 つの新しいカラフルな行を追加する必要がありました。

当然のことながら、これを JPG として LaTeX にインポートすると、印刷時に非常に悪い結果になります。このグラフまたはその一部を再現する方法と、これを実現するために何を使用すればよいかについて、誰か助けやヒントをくれませんか?

ここに画像の説明を入力してください

答え1

パッケージを使用して LaTeX 自体でツリーを実行する 1 つの方法を次に示しますforest

\documentclass[tikz,border=5pt]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\begin{document}
  \begin{forest}
    for tree={
      parent anchor=south,
      child anchor=north,
      tier/.wrap pgfmath arg={tier#1}{level()},
      font=\sffamily
    }
    [ROOT, name=root
      [SBARQ
        [WHNP
          [WDT
            [Which]
          ]
          [NP
            [NN
              [animal]
            ]
          ]
        ]
        [SQ
          [VBD
            [was]
          ]
          [RB
            [not, name=not]
          ]
          [VP
            [VBN
              [eaten, name=eaten]
            ]
          ]
        ]
        [.
          [?]
        ]
      ]
    ]
    \draw [ultra thick, blue, -{Triangle[]}] (root.south east) [bend left=65] to node [pos=.25, right, fill=blue, font=\sffamily\footnotesize, text=white, inner sep=1pt, xshift=5pt]  {ROOT}  (eaten.north east) ;
    \draw [ultra thick, red, -{Triangle[]}] (eaten.west) [bend left] to node [pos=.25, left, fill=red, font=\sffamily\footnotesize, text=white, inner sep=1pt, xshift=-5pt]  {NEG}  (not) ;
  \end{forest}
\end{document}

木

答え2

cfr はパッケージで優れたソリューションを提供しているのでforest、ここでは Tikz を使用したソリューションを紹介します。

出力

図1

コード

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{trees,calc,arrows.meta,positioning,bending}

\tikzset{
    edge from parent/.style={draw, gray},
    coln/.style={scale=0.6,inner sep=2pt, outer sep=0mm,draw=none,fill=#1, text=white},
    >=latex,
}

\begin{document}

\begin{tikzpicture}[
    level/.style={level distance=8mm},
    level 1/.style={sibling distance=25mm},
    level 3/.style={sibling distance=10mm},
    font=\sffamily
    ]

\node (root) {ROOT}
    child {node {SBARQ}
        child {node {WHNP}
            child {node {WDT}
                child {node {Which}
                }
            }
            child {node {NP}
                child {node {NN}
                    child {node {animal}
                    }
                }
            }
        }
        child {node {SQ}
            child {node {VBD}
                child {node {was}
                }}
            child {node {RB}
                child {node (not) {not}
                }}
            child {node {VP}
                child {node {VBN}
                    child {node (eat) {eaten}
                }}
            }
        }
        child[sibling distance=18mm] {node {.}
            child {node {?}
        }
    }
};

\draw[thick, blue!60!black] (root.east)
    edge[out=-10,in=45,->,looseness=1.4] node [midway,right,xshift=.3em,coln=blue!55] {Root}
        ($(eat.north east)+(-1mm,-1mm)$);
\draw[thick, red] (eat.west)
    edge[out=180,in=270,->] node [midway,left,xshift=-.3em,coln=red!60] {NEG}
        (not.south);

\end{tikzpicture}
\end{document}

関連情報