Beispiel #1
0
 public Node(bool first, string id, int x, int y)
 {
     this.first  = first;
     this.id     = id;
     this.x      = x;
     this.y      = y;
     nodePattern = new GenericNode(this);
 }
        /// <summary>
        /// Hash
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            unchecked
            {
                var hashCode = NodePattern.GetHashCode();
                hashCode = (hashCode * 397) ^ PatternElementChain?.Aggregate(
                    hashCode,
                    (hc, e) => { return(hc ^ e.Item1.GetHashCode() ^ e.Item2.GetHashCode()); }
                    ) ?? 0;

                return(hashCode);
            }
        }
Beispiel #3
0
            public override Tree Evaluate(Tree tree, TregexMatcher tregex)
            {
                Tree nodeToRelabel = ChildMatcher[0].Evaluate(tree, tregex);

                switch (node.mode)
                {
                case RelabelMode.Fixed:
                {
                    nodeToRelabel.Label().SetValue(node.newLabel);
                    break;
                }

                case RelabelMode.Regex:
                {
                    var label = new StringBuilder();
                    foreach (string chunk in node.replacementPieces)
                    {
                        if (VariablePattern.IsMatch(chunk))
                        {
                            //String name = chunk.Substring(2, chunk.Length - 1);
                            string name = chunk.Substring(2, chunk.Length - 3);
                            //label.Append(Matcher.quoteReplacement(tregex.getVariableString(name)));
                            label.Append(tregex.GetVariableString(name).Replace("'", "").Replace("\"", ""));
                        }
                        else if (NodePattern.IsMatch(chunk))
                        {
                            //String name = chunk.Substring(2, chunk.Length - 1);
                            string name = chunk.Substring(2, chunk.Length - 3);
                            //label.Append(Matcher.quoteReplacement(tregex.getNode(name).value()));
                            label.Append(tregex.GetNode(name).Value().Replace("'", "").Replace("\"", ""));
                        }
                        else
                        {
                            label.Append(chunk);
                        }
                    }
                    //var m = node.labelRegex.Match(nodeToRelabel.label().value());
                    //nodeToRelabel.label().setValue(m.replaceAll(label.ToString()));
                    var newS = node.labelRegex.Replace(nodeToRelabel.Label().Value(), label.ToString());
                    nodeToRelabel.Label().SetValue(/*m.replaceAll(label.ToString())*/ newS);
                    break;
                }

                default:
                    throw new ArgumentException("Unsupported relabel mode " + node.mode);
                }
                return(tree);
            }