/// <summary>Parse a CoNLL formatted tree into a SemanticGraph object (along with a list of tokens).</summary> /// <param name="conll">The CoNLL formatted tree.</param> /// <returns> /// A pair of a SemanticGraph and a token list, corresponding to the parse of the sentence /// and to tokens in the sentence. /// </returns> protected internal virtual Pair <SemanticGraph, IList <CoreLabel> > MkTree(string conll) { IList <CoreLabel> sentence = new List <CoreLabel>(); SemanticGraph tree = new SemanticGraph(); foreach (string line in conll.Split("\n")) { if (line.Trim().Equals(string.Empty)) { continue; } string[] fields = line.Trim().Split("\\s+"); int index = System.Convert.ToInt32(fields[0]); string word = fields[1]; CoreLabel label = IETestUtils.MkWord(word, index); sentence.Add(label); if (fields[2].Equals("0")) { tree.AddRoot(new IndexedWord(label)); } else { tree.AddVertex(new IndexedWord(label)); } if (fields.Length > 4) { label.SetTag(fields[4]); } if (fields.Length > 5) { label.SetNER(fields[5]); } if (fields.Length > 6) { label.SetLemma(fields[6]); } } int i = 0; foreach (string line_1 in conll.Split("\n")) { if (line_1.Trim().Equals(string.Empty)) { continue; } string[] fields = line_1.Trim().Split("\\s+"); int parent = System.Convert.ToInt32(fields[2]); string reln = fields[3]; if (parent > 0) { tree.AddEdge(new IndexedWord(sentence[parent - 1]), new IndexedWord(sentence[i]), new GrammaticalRelation(Language.UniversalEnglish, reln, null, null), 1.0, false); } i += 1; } return(Pair.MakePair(tree, sentence)); }
public _List_166() { { this.Add(IETestUtils.MkWord("yarn", 0)); this.Add(IETestUtils.MkWord("blue", 1)); this.Add(IETestUtils.MkWord("cats", 2)); this.Add(IETestUtils.MkWord("play", 3)); this.Add(IETestUtils.MkWord("with", 4)); } }
public _List_146() { { this.Add(IETestUtils.MkWord("blue", -1)); this.Add(IETestUtils.MkWord("cats", -1)); this.Add(IETestUtils.MkWord("play", -1)); this.Add(IETestUtils.MkWord("with", -1)); this.Add(IETestUtils.MkWord("yarn", -1)); } }
protected internal virtual RelationTriple YarnBlueCatsPlayWith() { IList <CoreLabel> sentence = new List <CoreLabel>(); sentence.Add(IETestUtils.MkWord("yarn", 0)); sentence.Add(IETestUtils.MkWord("blue", 1)); sentence.Add(IETestUtils.MkWord("cats", 2)); sentence.Add(IETestUtils.MkWord("play", 3)); sentence.Add(IETestUtils.MkWord("with", 4)); return(new RelationTriple(sentence.SubList(1, 3), sentence.SubList(3, 5), sentence.SubList(0, 1))); }
protected internal virtual RelationTriple BlueCatsPlayWithYarnNoIndices() { IList <CoreLabel> sentence = new List <CoreLabel>(); sentence.Add(IETestUtils.MkWord("blue", -1)); sentence.Add(IETestUtils.MkWord("cats", -1)); sentence.Add(IETestUtils.MkWord("play", -1)); sentence.Add(IETestUtils.MkWord("with", -1)); sentence.Add(IETestUtils.MkWord("yarn", -1)); return(new RelationTriple(sentence.SubList(0, 2), sentence.SubList(2, 4), sentence.SubList(4, 5))); }