Commit f3d7a392 by xiaotong

bug fixes of CYK

parent d0ba52a4
...@@ -3724,7 +3724,7 @@ d = r_1 \circ r_2 \circ r_3 \circ r_4 ...@@ -3724,7 +3724,7 @@ d = r_1 \circ r_2 \circ r_3 \circ r_4
\begin{center} \begin{center}
\begin{tikzpicture} \begin{tikzpicture}
\node [anchor=south west,rectangle,draw=ublue,thick,inner sep=0.4em,fill=white,drop shadow] (sourceG) at (0,0) {{\color{ublue} \footnotesize{\textbf{S端文法}}}}; \node [anchor=south west,rectangle,draw=ublue,thick,inner sep=0.4em,fill=white,drop shadow] (sourceG) at (0,0) {{\color{ublue} \footnotesize{\textbf{S端文法}}}};
\node [anchor=west,rectangle,draw=ublue,thick,inner sep=0.4em,fill=white,drop shadow] (chom) at ([xshift=3.5em]sourceG.east) {{\color{ublue} \footnotesize{\textbf{乔姆斯基范式}}}}; \node [anchor=west,rectangle,draw=ublue,thick,inner sep=0.4em,fill=white,drop shadow] (chom) at ([xshift=3.5em]sourceG.east) {{\color{ublue} \footnotesize{\textbf{乔姆斯基范式(CNF)}}}};
\node [anchor=west,rectangle,draw=ublue,thick,inner sep=0.4em,fill=white,drop shadow] (targetG) at ([xshift=3.5em]chom.east) {{\color{ublue} \footnotesize{\textbf{T端文法}}}}; \node [anchor=west,rectangle,draw=ublue,thick,inner sep=0.4em,fill=white,drop shadow] (targetG) at ([xshift=3.5em]chom.east) {{\color{ublue} \footnotesize{\textbf{T端文法}}}};
\draw[->,very thick] ([xshift=0.1em]sourceG.east) -- ([xshift=-0.1em]chom.west); \draw[->,very thick] ([xshift=0.1em]sourceG.east) -- ([xshift=-0.1em]chom.west);
...@@ -3751,27 +3751,28 @@ d = r_1 \circ r_2 \circ r_3 \circ r_4 ...@@ -3751,27 +3751,28 @@ d = r_1 \circ r_2 \circ r_3 \circ r_4
\begin{itemize} \begin{itemize}
\item CYK算法通过遍历不同\alert{span}来判断字符串是否符合文法 \item CYK算法通过遍历不同\alert{span}来判断字符串是否符合文法
\begin{itemize} \begin{itemize}
\item 输入:源语串\textbf{s =} $s_1 ... s_J$,以及上下文无关文法$G$ \item 输入:源语串\textbf{s =} $s_1 ... s_J$,以及CNF文法$G$
\item 输出:判断字符串是否符合上下文无关文法 \item 输出:判断字符串是否符合G
\end{itemize} \end{itemize}
\vspace{-0.7em} \vspace{-0.3em}
\begin{center} \begin{center}
\begin{tikzpicture} \begin{tikzpicture}
\tikzstyle{alignmentnode} = [rectangle,fill=blue!30,minimum size=0.45em,text=white,inner sep=0.1pt] \tikzstyle{alignmentnode} = [rectangle,fill=blue!30,minimum size=0.45em,text=white,inner sep=0.1pt]
\tikzstyle{selectnode} = [rectangle,fill=green!20,minimum height=1.5em,minimum width=1.5em,inner sep=1.2pt] \tikzstyle{selectnode} = [rectangle,fill=green!20,minimum height=1.5em,minimum width=1.5em,inner sep=1.2pt]
\tikzstyle{srcnode} = [anchor=south west] \tikzstyle{srcnode} = [anchor=south west]
\begin{scope}[scale=0.85] \begin{scope}[scale=0.85]
\node[srcnode] (c1) at (0,0) {\small{\textbf{Function} CKY-Algorithm($s,G$)}};
\node[srcnode,anchor=north west] (c21) at ([xshift=1.5em,yshift=0.4em]c1.south west) {\small{\textbf{foreach} ($j_1, j_2$): 0$ \leq j_1,j_2 \leq J$ and $ j_1 \textless j_2$}}; \node[srcnode] (c1) at (0,0) {\small{\textbf{Function} CYK-Algorithm($s,G$)}};
\node[srcnode,anchor=north west] (c22) at ([xshift=1.5em,yshift=0.4em]c21.south west) {\small{$span[j_1,j_2 ]$.updatePhrase($G$)}}; \node[srcnode,anchor=north west] (c21) at ([xshift=1.5em,yshift=0.4em]c1.south west) {\small{\textbf{fore} $j=0$ to $ J - 1$}};
\node[srcnode,anchor=north west] (c22) at ([xshift=1.5em,yshift=0.4em]c21.south west) {\small{$span[j,j+1 ]$.Add($A \to a \in G$)}};
\node[srcnode,anchor=north west] (c3) at ([xshift=-1.5em,yshift=0.4em]c22.south west) {\small{\textbf{for} $l_{span}$ = 1 to $J$}}; \node[srcnode,anchor=north west] (c3) at ([xshift=-1.5em,yshift=0.4em]c22.south west) {\small{\textbf{for} $l_{span}$ = 1 to $J$}};
\node[srcnode,anchor=west] (c31) at ([xshift=6em]c3.east) {\small{// length of span}}; \node[srcnode,anchor=west] (c31) at ([xshift=6em]c3.east) {\small{// length of span}};
\node[srcnode,anchor=north west] (c4) at ([xshift=1.5em,yshift=0.4em]c3.south west) {\small{\textbf{for} $j$ = 0 to $J-l_{span}$}}; \node[srcnode,anchor=north west] (c4) at ([xshift=1.5em,yshift=0.4em]c3.south west) {\small{\textbf{for} $j$ = 0 to $J-l$}};
\node[srcnode,anchor=north west] (c41) at ([yshift=0.4em]c31.south west) {\small{// begining of span}}; \node[srcnode,anchor=north west] (c41) at ([yshift=0.4em]c31.south west) {\small{// beginning of span}};
\node[srcnode,anchor=north west] (c5) at ([xshift=1.5em,yshift=0.4em]c4.south west) {\small{\textbf{for} $k$ = $j$ to $j+l_{span}$}}; \node[srcnode,anchor=north west] (c5) at ([xshift=1.5em,yshift=0.4em]c4.south west) {\small{\textbf{for} $k$ = $j$ to $j+l$}};
\node[srcnode,anchor=north west] (c51) at ([yshift=0.4em]c41.south west) {\small{// partition of span}}; \node[srcnode,anchor=north west] (c51) at ([yshift=0.4em]c41.south west) {\small{// partition of span}};
\node[srcnode,anchor=north west] (c6) at ([xshift=1.5em,yshift=0.4em]c5.south west) {\small{$hypos$ = Compose($span[j, k], span[k, j+l_{span}]$)}}; \node[srcnode,anchor=north west] (c6) at ([xshift=1.5em,yshift=0.4em]c5.south west) {\small{$hypos$ = Compose($span[j, k], span[k, j+l]$)}};
\node[srcnode,anchor=north west] (c7) at ([yshift=0.4em]c6.south west) {\small{$span[j, j+l_{span}]$.update($hypos$)}}; \node[srcnode,anchor=north west] (c7) at ([yshift=0.4em]c6.south west) {\small{$span[j, j+l]$.Update($hypos$)}};
\node[srcnode,anchor=north west] (c8) at ([xshift=-4.5em,yshift=0.4em]c7.south west) {\small{\textbf{return} $span[0, J]$}}; \node[srcnode,anchor=north west] (c8) at ([xshift=-4.5em,yshift=0.4em]c7.south west) {\small{\textbf{return} $span[0, J]$}};
...@@ -3784,13 +3785,13 @@ d = r_1 \circ r_2 \circ r_3 \circ r_4 ...@@ -3784,13 +3785,13 @@ d = r_1 \circ r_2 \circ r_3 \circ r_4
\node[srcnode] (s7) at ([xshift=1em]s6.south east) {$s_6$}; \node[srcnode] (s7) at ([xshift=1em]s6.south east) {$s_6$};
\node[srcnode] (s8) at ([xshift=1em]s7.south east) {$s_7$}; \node[srcnode] (s8) at ([xshift=1em]s7.south east) {$s_7$};
\node[srcnode,anchor=center] (j1) at ([yshift=-1.4em]s3.south) {$j$}; \node[srcnode,anchor=center] (j1) at ([yshift=-1.4em,xshift=-0.8em]s3.south) {$j$};
\node[srcnode,anchor=center] (j2) at ([yshift=-1.4em]s7.south) {$j+l_{span}$}; \node[srcnode,anchor=center] (j2) at ([yshift=-1.4em,xshift=0.8em]s7.south) {$j+l_{span}$};
\node[srcnode,anchor=center] (k) at ([xshift=1.5em,yshift=-1.5em]s4.south) {$k$}; \node[srcnode,anchor=center] (k) at ([xshift=1.5em,yshift=-1.5em]s4.south) {$k$};
\draw[->,thick] ([yshift=-0.1em]j1.north)--([yshift=0.1em]s3.south); \draw[->,thick] ([yshift=-0.3em,xshift=-0.8em]j1.north)--([yshift=0.5em,xshift=-0.8em]j1.north);
\draw[->,thick] ([yshift=-0.1em]j2.north)--([yshift=0.1em]s7.south); \draw[->,thick] ([yshift=-0.3em,xshift=0.8em]j2.north)--([yshift=0.5em,xshift=0.8em]j2.north);
\draw[->,thick] ([yshift=-0.1em]k.north)--([xshift=1.5em,yshift=0.1em]s4.south); \draw[->,thick] ([yshift=-0.1em]k.north)--([xshift=1.5em,yshift=0.1em]s4.south);
\node [rectangle,inner sep=0.3em,rounded corners=1pt,very thick,dotted,draw=ugreen] [fit = (s3) (s7)] (box1) {}; \node [rectangle,inner sep=0.3em,rounded corners=1pt,very thick,dotted,draw=ugreen] [fit = (s3) (s7)] (box1) {};
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论