public virtual bool HasOtherChild(int k, DependencyTree goldTree) { for (int i = 1; i <= tree.n; ++i) { if (goldTree.GetHead(i) == k && tree.GetHead(i) != k) { return(true); } } return(false); }
// O(n) implementation public override string GetOracle(Configuration c, DependencyTree dTree) { int w1 = c.GetStack(1); int w2 = c.GetStack(0); if (w1 > 0 && dTree.GetHead(w1) == w2) { return("L(" + dTree.GetLabel(w1) + ')'); } else { if (w1 >= 0 && dTree.GetHead(w2) == w1 && !c.HasOtherChild(w2, dTree)) { return("R(" + dTree.GetLabel(w2) + ')'); } else { return("S"); } } }
/// <param name="k"> /// Word index (zero = root node; actual word indexing /// begins at 1) /// </param> public virtual int GetHead(int k) { return(tree.GetHead(k)); }
public static void WriteConllFile(string outFile, IList <ICoreMap> sentences, IList <DependencyTree> trees) { try { PrintWriter output = IOUtils.GetPrintWriter(outFile); for (int i = 0; i < sentences.Count; i++) { ICoreMap sentence = sentences[i]; DependencyTree tree = trees[i]; IList <CoreLabel> tokens = sentence.Get(typeof(CoreAnnotations.TokensAnnotation)); for (int j = 1; j <= size; ++j) { CoreLabel token = tokens[j - 1]; output.Printf("%d\t%s\t_\t%s\t%s\t_\t%d\t%s\t_\t_%n", j, token.Word(), token.Tag(), token.Tag(), tree.GetHead(j), tree.GetLabel(j)); } output.Println(); } output.Close(); } catch (Exception e) { throw new RuntimeIOException(e); } }
// NOTE: need to check the correctness again. private static bool CanReach(Configuration c, DependencyTree dTree) { int n = c.GetSentenceSize(); for (int i = 1; i <= n; ++i) { if (c.GetHead(i) != Config.Nonexist && c.GetHead(i) != dTree.GetHead(i)) { return(false); } } bool[] inBuffer = new bool[n + 1]; bool[] depInList = new bool[n + 1]; int[] leftL = new int[n + 2]; int[] rightL = new int[n + 2]; for (int i_1 = 0; i_1 < c.GetBufferSize(); ++i_1) { inBuffer[c.buffer[i_1]] = true; } int nLeft = c.GetStackSize(); for (int i_2 = 0; i_2 < nLeft; ++i_2) { int x = c.stack[i_2]; leftL[nLeft - i_2] = x; if (x > 0) { depInList[dTree.GetHead(x)] = true; } } int nRight = 1; rightL[nRight] = leftL[1]; for (int i_3 = 0; i_3 < c.GetBufferSize(); ++i_3) { // boolean inList = false; int x = c.buffer[i_3]; if (!inBuffer[dTree.GetHead(x)] || depInList[x]) { rightL[++nRight] = x; depInList[dTree.GetHead(x)] = true; } } int[][] g = new int[][] { }; for (int i_4 = 1; i_4 <= nLeft; ++i_4) { for (int j = 1; j <= nRight; ++j) { g[i_4][j] = -1; } } g[1][1] = leftL[1]; for (int i_5 = 1; i_5 <= nLeft; ++i_5) { for (int j_1 = 1; j_1 <= nRight; ++j_1) { if (g[i_5][j_1] != -1) { int x = g[i_5][j_1]; if (j_1 < nRight && dTree.GetHead(rightL[j_1 + 1]) == x) { g[i_5][j_1 + 1] = x; } if (j_1 < nRight && dTree.GetHead(x) == rightL[j_1 + 1]) { g[i_5][j_1 + 1] = rightL[j_1 + 1]; } if (i_5 < nLeft && dTree.GetHead(leftL[i_5 + 1]) == x) { g[i_5 + 1][j_1] = x; } if (i_5 < nLeft && dTree.GetHead(x) == leftL[i_5 + 1]) { g[i_5 + 1][j_1] = leftL[i_5 + 1]; } } } } return(g[nLeft][nRight] != -1); }