Ejemplo n.º 1
0
        public ComparableNode Merge(ComparableNode left, ComparableNode right)
        {
            var head = new ComparableNode(0);

            var current = head;

            while (left != null && right != null)
            {
                if (left == null || right == null)
                {
                    current.Next = right ?? left;
                    break;
                }

                if (left.CompareTo(right) == -1)
                {
                    current.Next = left;
                    left         = left.Next;
                }
                else
                {
                    current.Next = right;
                    right        = right.Next;
                }
            }

            return(head);
        }
Ejemplo n.º 2
0
            private SyntaxNode UnwrapAndClean(ComparableNode comparableNode)
            {
                var node = comparableNode.Node;

                if (!node.HasLeadingTrivia)
                {
                    return(node);
                }

                var trivia = node.GetLeadingTrivia();

                var trim = trivia.Where(x => x.IsKind(SyntaxKind.EndOfLineTrivia)).ToList();

                foreach (var t in trim)
                {
                    trivia = trivia.Remove(t);
                }

                if (comparableNode.Section != CodeSections.PrivateField || comparableNode.Section != CodeSections.PrivateReadonlyField)
                {
                    trivia = trivia.Insert(0, SyntaxFactory.EndOfLine("\r\n"));
                }

                return(node.WithLeadingTrivia(trivia));
            }
Ejemplo n.º 3
0
 private bool CompareChild(ComparableNode node1, ComparableNode node2)
 {
     if ((node1 != null && node1.Value is Wz_File) ||
         (node2 != null && node2.Value is Wz_File))
     {
         return(!IgnoreWzFile);
     }
     return(true);
 }
Ejemplo n.º 4
0
        private IEnumerable <CompareDifference> Compare(ComparableNode nodeNew, ComparableNode nodeOld)
        {
            var cmp = Compare(
                nodeNew == null ? null : nodeNew.Children,
                nodeOld == null ? null : nodeOld.Children);

            foreach (var diff in cmp)
            {
                yield return(diff);
            }
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.core.syntaxgraph.edge.Edge addSecondaryEdge(org.maltparser.core.syntaxgraph.node.ComparableNode source, org.maltparser.core.syntaxgraph.node.ComparableNode target) throws org.maltparser.core.exception.MaltChainedException
        public virtual Edge.Edge addSecondaryEdge(ComparableNode source, ComparableNode target)
        {
            if (source == null || target == null)
            {
                throw new SyntaxGraphException("Head or dependent node is missing.");
            }
            else if (!target.Root)
            {
                Edge.Edge e = edgePool.checkOut();
                e.BelongsToGraph = this;
                e.setEdge((Node.Node)source, (Node.Node)target, Edge_Fields.SECONDARY_EDGE);
                graphEdges.Add(e);
                return(e);
            }
            return(null);
        }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void removeSecondaryEdge(org.maltparser.core.syntaxgraph.node.ComparableNode source, org.maltparser.core.syntaxgraph.node.ComparableNode target) throws org.maltparser.core.exception.MaltChainedException
        public virtual void removeSecondaryEdge(ComparableNode source, ComparableNode target)
        {
            if (source == null || target == null || source.BelongsToGraph != this || target.BelongsToGraph != this)
            {
                throw new SyntaxGraphException("Head or dependent node is missing.");
            }
            else if (!target.Root)
            {
                IEnumerator <Edge.Edge> ie = ((Node.Node)target).IncomingEdgeIterator;
                while (ie.MoveNext())
                {
                    Edge.Edge e = ie.Current;
                    if (e.Source == source)
                    {
//JAVA TO C# CONVERTER TODO TASK: .NET enumerators are read-only:
                        ie.remove();
                        graphEdges.remove(e);
                        edgePool.checkIn(e);
                    }
                }
            }
        }
Ejemplo n.º 7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void removeSecondaryEdge(org.maltparser.core.syntaxgraph.node.ComparableNode source, org.maltparser.core.syntaxgraph.node.ComparableNode target) throws org.maltparser.core.exception.MaltChainedException
        public virtual void removeSecondaryEdge(ComparableNode source, ComparableNode target)
        {
            if (source == null || target == null)
            {
                throw new SyntaxGraphException("Head or dependent node is missing.");
            }
            else if (!target.Root)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Iterator<org.maltparser.core.syntaxgraph.edge.Edge> ie = ((org.maltparser.core.syntaxgraph.node.Node)target).getIncomingEdgeIterator();
                IEnumerator <Edge.Edge> ie = ((Node.Node)target).IncomingEdgeIterator;
                while (ie.MoveNext())
                {
                    Edge.Edge e = ie.Current;
                    if (e.Source == source)
                    {
//JAVA TO C# CONVERTER TODO TASK: .NET enumerators are read-only:
                        ie.remove();
                        graphEdges.remove(e);
                        edgePool.checkIn(e);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private bool TryGetLink(ComparableNode node, out PngLinkInfo linkInfo)
        {
            linkInfo = new PngLinkInfo();
            var png = node.Value as Wz_Png;

            if (png != null && png.Width == 1 && png.Height == 1)
            {
                var           node1 = node.LinkNode;
                WzLib.Wz_Node linkNode;
                if ((linkNode = node1.Nodes["_inlink"]) != null)
                {
                    linkInfo.LinkType = PngLinkType.Inlink;
                    linkInfo.LinkUrl  = linkNode.GetValue <string>();
                    return(true);
                }
                else if ((linkNode = node1.Nodes["_outlink"]) != null)
                {
                    linkInfo.LinkType = PngLinkType.Inlink;
                    linkInfo.LinkUrl  = linkNode.GetValue <string>();
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 9
0
        private IEnumerable <CompareDifference> CompareSortedNodes(IList <ComparableNode> arrayNew, IList <ComparableNode> arrayOld, Comparison <ComparableNode> compFunc = null)
        {
            //逐层对比
            int l = 0, r = 0;

            while (l < arrayNew.Count || r < arrayOld.Count)
            {
                int?comp = null;
                if (r == arrayOld.Count) //输出左边
                {
                    comp = -1;
                }
                else if (l == arrayNew.Count) //输出右边
                {
                    comp = 1;
                }
                else
                {
                    comp = compFunc != null?compFunc(arrayNew[l], arrayOld[r]) : arrayNew[l].CompareTo(arrayOld[r]);
                }

                switch (comp)
                {
                case -1:
                    yield return(new CompareDifference(arrayNew[l].LinkNode, null, DifferenceType.Append));

                    if (CompareChild(arrayNew[l], null))
                    {
                        foreach (CompareDifference diff in Compare(arrayNew[l], null))
                        {
                            yield return(diff);
                        }
                    }
                    l++;
                    break;

                case 0:
                    //TODO: 试着比较多linkNode的场合。。
                    if ((arrayNew[l].HasMultiValues || arrayOld[r].HasMultiValues) &&
                        !(arrayNew[l].Value is Wz_File wzf1 && !wzf1.IsSubDir || arrayOld[r].Value is Wz_File wzf2 && !wzf2.IsSubDir)        //file跳过
                        )
                    {
                        //对比node的绝对路径
                        var left      = (arrayNew[l] as WzVirtualNodeAgent).Target.LinkNodes;
                        var right     = (arrayOld[r] as WzVirtualNodeAgent).Target.LinkNodes;
                        var compFunc2 = new Comparison <Wz_Node>((a, b) => string.Compare(a.FullPathToFile, b.FullPathToFile));
                        left.Sort(compFunc2);
                        right.Sort(compFunc2);

                        foreach (var diff in CompareSortedNodes(
                                     left.Select(n => (ComparableNode) new WzNodeAgent(n)).ToList(),
                                     right.Select(n => (ComparableNode) new WzNodeAgent(n)).ToList(),
                                     (a, b) => Math.Sign(string.CompareOrdinal(a.LinkNode.FullPath, b.LinkNode.FullPath)))
                                 )
                        {
                            yield return(diff);
                        }
                    }
                    else
                    {
                        bool compared   = false;
                        bool linkFilter = false;

                        //同是png 检测link
                        if (ResolvePngLink)
                        {
                            ComparableNode nodeNew = arrayNew[l],
                                           nodeOld = arrayOld[r];
                            PngLinkInfo linkInfoNew, linkInfoOld;
                            bool        linkNew = TryGetLink(nodeNew, out linkInfoNew),
                                        linkOld = TryGetLink(nodeOld, out linkInfoOld);

                            if (linkNew && !linkOld && nodeOld.Value is Wz_Png)     //图片转化为link
                            {
                                var newPng = GetLinkedPng(nodeNew.LinkNode);
                                if (newPng != null)
                                {
                                    if (!CompareData(newPng, nodeOld.Value))
                                    {
                                        yield return(new CompareDifference(nodeNew.LinkNode, nodeOld.LinkNode, DifferenceType.Changed));
                                    }
                                    else     //链接后图片一致 过滤link标记
                                    {
                                        linkFilter = true;
                                    }
                                    compared = true;
                                }
                            }
                            else if (!linkNew && linkOld && nodeNew.Value is Wz_Png)     //link恢复为图片
                            {
                                var oldPng = GetLinkedPng(nodeOld.LinkNode);
                                if (oldPng != null)
                                {
                                    if (!CompareData(nodeNew.Value, oldPng))
                                    {
                                        yield return(new CompareDifference(nodeNew.LinkNode, nodeOld.LinkNode, DifferenceType.Changed));
                                    }
                                    else     //链接后图片一致 过滤link标记
                                    {
                                        linkFilter = true;
                                    }
                                    compared = true;
                                }
                            }
                            else if (linkNew && linkOld)     //两边都是link
                            {
                                if (linkInfoNew.LinkType == linkInfoOld.LinkType &&
                                    linkInfoNew.LinkUrl == linkInfoOld.LinkUrl)        //link没有变动
                                {
                                    compared = true;
                                }
                                else
                                {
                                    var newPng = GetLinkedPng(nodeNew.LinkNode);
                                    var oldPng = GetLinkedPng(nodeOld.LinkNode);
                                    if (newPng != null && oldPng != null)
                                    {
                                        if (newPng != oldPng && !CompareData(newPng, oldPng))     //对比有差异 不输出dummy
                                        {
                                            //yield return new CompareDifference(nodeNew.LinkNode, nodeOld.LinkNode, DifferenceType.Changed);
                                        }
                                        else
                                        {
                                            linkFilter = true;
                                        }
                                        compared = true;
                                    }
                                }
                            }
                        }

                        //正常对比
                        if (!compared && !CompareData(arrayNew[l].Value, arrayOld[r].Value))
                        {
                            yield return(new CompareDifference(arrayNew[l].LinkNode, arrayOld[r].LinkNode, DifferenceType.Changed));
                        }

                        //对比子集
                        if (CompareChild(arrayNew[l], arrayOld[r]))
                        {
                            foreach (CompareDifference diff in Compare(arrayNew[l], arrayOld[r]))
                            {
                                if (linkFilter)     // && diff.DifferenceType != DifferenceType.Changed) [s]过滤新增或删除[/s] 全部过滤
                                {
                                    if ((diff.NodeNew?.ParentNode == arrayNew[l].LinkNode ||
                                         diff.NodeOld?.ParentNode == arrayOld[r].LinkNode))       //差异节点为当前的子级
                                    {
                                        var nodeText = diff.NodeNew?.Text ?? diff.NodeOld?.Text;
                                        if (nodeText == "_inlink" || nodeText == "_outlink")
                                        {
                                            continue;
                                        }
                                    }
                                }
                                yield return(diff);
                            }
                        }
                    }

                    l++; r++;
                    break;
Ejemplo n.º 10
0
        public override int compareTo(ComparableNode o)
        {
            const int BEFORE = -1;
            const int EQUAL  = 0;
            const int AFTER  = 1;

            if (this == o)
            {
                return(EQUAL);
            }
            try
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int thisLCorner = this.getLeftmostProperDescendantIndex();
                int thisLCorner = LeftmostProperDescendantIndex;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int thatLCorner = (o instanceof TokenNode)?o.getCompareToIndex():o.getLeftmostProperDescendantIndex();
                int thatLCorner = (o is TokenNode)?o.CompareToIndex:o.LeftmostProperDescendantIndex;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int thisRCorner = this.getRightmostProperDescendantIndex();
                int thisRCorner = RightmostProperDescendantIndex;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int thatRCorner = (o instanceof TokenNode)?o.getCompareToIndex():o.getRightmostProperDescendantIndex();
                int thatRCorner = (o is TokenNode)?o.CompareToIndex:o.RightmostProperDescendantIndex;

                //		    if (thisLCorner == -1 || thatLCorner == -1) {
                //			    if (thisRCorner < thatRCorner) return BEFORE;
                //			    if (thisRCorner > thatRCorner) return AFTER;
                //		    }
                //		    if (thisRCorner == -1 || thatRCorner == -1) {
                //			    if (thisLCorner < thatLCorner) return BEFORE;
                //			    if (thisLCorner > thatLCorner) return AFTER;
                //		    }
                if (thisLCorner != -1 && thatLCorner != -1 && thisRCorner != -1 && thatRCorner != -1)
                {
                    if (thisLCorner < thatLCorner && thisRCorner < thatRCorner)
                    {
                        return(BEFORE);
                    }
                    if (thisLCorner > thatLCorner && thisRCorner > thatRCorner)
                    {
                        return(AFTER);
                    }
                    if (thisLCorner > thatLCorner && thisRCorner < thatRCorner)
                    {
                        return(BEFORE);
                    }
                    if (thisLCorner < thatLCorner && thisRCorner > thatRCorner)
                    {
                        return(AFTER);
                    }
                }
                else
                {
                    if (thisLCorner != -1 && thatLCorner != -1)
                    {
                        if (thisLCorner < thatLCorner)
                        {
                            return(BEFORE);
                        }
                        if (thisLCorner > thatLCorner)
                        {
                            return(AFTER);
                        }
                    }
                    if (thisRCorner != -1 && thatRCorner != -1)
                    {
                        if (thisRCorner < thatRCorner)
                        {
                            return(BEFORE);
                        }
                        if (thisRCorner > thatRCorner)
                        {
                            return(AFTER);
                        }
                    }
                }

                //		    final int thisLCorner = this.getLeftmostDescendantIndex();
                //		    final int thatLCorner = (o instanceof TerminalNode)?o.getCompareToIndex():o.getLeftmostDescendantIndex();
                //		    final int thisRCorner = this.getRightmostDescendantIndex();
                //		    final int thatRCorner = (o instanceof TerminalNode)?o.getCompareToIndex():o.getRightmostDescendantIndex();
                //
                //		    if (thisLCorner == -1 || thatLCorner == -1) {
                //			    if (thisRCorner < thatRCorner) return BEFORE;
                //			    if (thisRCorner > thatRCorner) return AFTER;
                //		    }
                //		    if (thisRCorner == -1 || thatRCorner == -1) {
                //			    if (thisLCorner < thatLCorner) return BEFORE;
                //			    if (thisLCorner > thatLCorner) return AFTER;
                //		    }
                //		    if (thisLCorner < thatLCorner && thisRCorner < thatRCorner) return BEFORE;
                //		    if (thisLCorner > thatLCorner && thisRCorner > thatRCorner) return AFTER;
                //		    if (thisLCorner > thatLCorner && thisRCorner < thatRCorner) return BEFORE;
                //		    if (thisLCorner < thatLCorner && thisRCorner > thatRCorner) return AFTER;


                //		    int thisCorner = this.getLeftmostDescendantIndex();
                //		    int thatCorner = (o instanceof TerminalNode)?o.getCompareToIndex():o.getLeftmostDescendantIndex();
                //		    if (thisCorner != -1 && thatCorner != -1) {
                //			    if (thisCorner < thatCorner) return BEFORE;
                //			    if (thisCorner > thatCorner) return AFTER;
                //		    }
                //		    thisCorner = this.getRightmostDescendantIndex();
                //		    thatCorner = (o instanceof TerminalNode)?o.getCompareToIndex():o.getRightmostDescendantIndex();
                //		    if (thisCorner != -1 && thatCorner != -1) {
                //			    if (thisCorner < thatCorner) return BEFORE;
                //			    if (thisCorner > thatCorner) return AFTER;
                //		    }
            }
            catch (MaltChainedException e)
            {
                if (SystemLogger.logger().DebugEnabled)
                {
                    SystemLogger.logger().debug("", e);
                }
                else
                {
                    SystemLogger.logger().error(e.MessageChain);
                }
                Environment.Exit(1);
            }
            if (0 < o.CompareToIndex)
            {
                return(BEFORE);
            }
            if (0 > o.CompareToIndex)
            {
                return(AFTER);
            }
            return(base.CompareTo(o));
            //
            //		if (o instanceof TerminalNode) {
            //			if (0 == o.getIndex()) {
            //
            //			} else if (0 < o.getIndex()) {
            //				return -1;
            //			} else {
            //				return 1;
            //			}
            //		} else if (o instanceof Root) {
            //			return super.compareTo(o);
            //		} else if (o instanceof NonTerminalNode) {
            //			int lcorner = ((NonTerminalNode)o).getLeftCornerIndex();
            //			if (0 == lcorner) {
            //				int rcorner = ((NonTerminalNode)o).getRightCornerIndex();
            //				if (0 == rcorner) {
            //					if (0 == o.getIndex()) {
            //						return super.compareTo(o);
            //					} else if (0 < o.getIndex()) {
            //						return 1;
            //					} else {
            //						return -1;
            //					}
            //				} else if (0 < rcorner) {
            //					return -1;
            //				} else {
            //					return 1;
            //				}
            //			} else if (0 < lcorner) {
            //				return -1;
            //			} else {
            //				return 1;
            //			}
            //		}
            //		return super.compareTo(o);
        }
Ejemplo n.º 11
0
 public virtual int compareTo(ComparableNode o)
 {
     return(base.compareTo((GraphElement)o));
 }
Ejemplo n.º 12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public void removeSecondaryEdge(org.maltparser.core.syntaxgraph.node.ComparableNode source, org.maltparser.core.syntaxgraph.node.ComparableNode target) throws org.maltparser.core.exception.MaltChainedException
        public void removeSecondaryEdge(ComparableNode source, ComparableNode target)
        {
            throw new LWGraphException("Not implemented in light-weight dependency graph");
        }