/// <summary> /// Returns a <code>string</code> representation of this node and /// its subtree with one node per line, indented according to <code>indentLevel</code>. /// </summary> /// <param name="indentLevel">how many levels to indent (0 for root node)</param> /// <returns><code>string</code> representation of this subtree</returns> public string ToPrettyString(int indentLevel) { var buf = new StringBuilder("\n"); for (int i = 0; i < indentLevel; i++) { buf.Append(" "); } if (_children == null || _children.Length == 0) { buf.Append(_label.ToString(CoreLabel.OutputFormat.VALUE_INDEX_MAP)); } else { buf.Append('(').Append(_label.ToString(CoreLabel.OutputFormat.VALUE_INDEX_MAP)); foreach (TreeGraphNode child in _children) { buf.Append(' ').Append(child.ToPrettyString(indentLevel + 1)); } buf.Append(')'); } return(buf.ToString()); }
/// <summary> /// Returns a /// <c>String</c> /// representation of this node and /// its subtree with one node per line, indented according to /// <paramref name="indentLevel"/> /// . /// </summary> /// <param name="indentLevel">how many levels to indent (0 for root node)</param> /// <returns> /// /// <c>String</c> /// representation of this subtree /// </returns> public virtual string ToPrettyString(int indentLevel) { StringBuilder buf = new StringBuilder("\n"); for (int i = 0; i < indentLevel; i++) { buf.Append(" "); } if (children == null || children.Length == 0) { buf.Append(label.ToString(CoreLabel.OutputFormat.ValueIndexMap)); } else { buf.Append('(').Append(label.ToString(CoreLabel.OutputFormat.ValueIndexMap)); foreach (TreeGraphNode child in children) { buf.Append(' ').Append(child.ToPrettyString(indentLevel + 1)); } buf.Append(')'); } return(buf.ToString()); }
public static DepPattern PatternToDepPattern(Pair <IndexedWord, GrammaticalRelation> p, DataInstance sent) { Token token = new Token(PatternFactory.PatternType.Dep); CoreLabel backingLabel = sent.GetTokens()[p.First().Index() - 1]; System.Diagnostics.Debug.Assert(backingLabel.ContainsKey(typeof(PatternsAnnotations.ProcessedTextAnnotation)), "the keyset are " + backingLabel.ToString(CoreLabel.OutputFormat.All)); token.AddORRestriction(typeof(PatternsAnnotations.ProcessedTextAnnotation), backingLabel.Get(typeof(PatternsAnnotations.ProcessedTextAnnotation))); return(new DepPattern(token, p.Second())); }
internal static Triple <bool, Token, string> GetContextTokenStr(CoreLabel tokenj) { Token strgeneric = new Token(PatternFactory.PatternType.Surface); string strOriginal = string.Empty; bool isLabeledO = true; // for (Entry<String, Class<? extends TypesafeMap.Key<String>>> e : getAnswerClass().entrySet()) { // if (!tokenj.get(e.getValue()).equals(backgroundSymbol)) { // isLabeledO = false; // if (strOriginal.isEmpty()) { // strOriginal = e.getKey(); // } else { // strOriginal += "|" + e.getKey(); // } // strgeneric.addRestriction(e.getKey(), e.getKey()); // } // } foreach (KeyValuePair <string, Type> e in ConstantsAndVariables.GetGeneralizeClasses()) { if (!tokenj.ContainsKey(e.Value) || tokenj.Get(e.Value) == null) { throw new Exception(" Why does the token not have the class " + e.Value + " set? Existing classes " + tokenj.ToString(CoreLabel.OutputFormat.All)); } if (!tokenj.Get(e.Value).Equals(ConstantsAndVariables.backgroundSymbol)) { isLabeledO = false; if (strOriginal.IsEmpty()) { strOriginal = e.Key; } else { strOriginal += "|" + e.Key; } strgeneric.AddORRestriction(e.Value, e.Key); } } if (useContextNERRestriction) { string nerTag = tokenj.Get(typeof(CoreAnnotations.NamedEntityTagAnnotation)); if (nerTag != null && !nerTag.Equals(SeqClassifierFlags.DefaultBackgroundSymbol)) { isLabeledO = false; if (strOriginal.IsEmpty()) { strOriginal = nerTag; } else { strOriginal += "|" + nerTag; } strgeneric.AddORRestriction(typeof(CoreAnnotations.NamedEntityTagAnnotation), nerTag); } } return(new Triple <bool, Token, string>(isLabeledO, strgeneric, strOriginal)); }