// sort edges in a way that remote edges end up toward the end of list private int CompareEdgesBasedOnRemoteness(IEdge e1, IEdge e2) { IMatchEdge me1 = (IMatchEdge)e1; IMatchEdge me2 = (IMatchEdge)e2; bool bothRemote = me1.IsRemote && me2.IsRemote; bool bothLocal = !me1.IsRemote && !me2.IsRemote; if (bothLocal || bothRemote) { return(0); } if (me1.IsRemote) { return(1); } if (me2.IsRemote) { return(-1); } throw new InvalidOperationException("Cannot decide which edge comes first..."); }
public IModel Deserialize(Stream stream) { logger.Info("Matcher data deserialization started."); XmlReader reader = XmlReader.Create(stream); Dictionary <IId, CrossingEdge> crossingEdges = null; IModel model = null; if (reader.ReadToFollowing(PartitionSerializerTags.CrossingEdgesTag)) { crossingEdges = ReadCrossingEdges(reader.ReadSubtree()); } if (reader.ReadToFollowing(PartitionSerializerTags.ModelTag)) { // Data fromat comes from is in DMT.Partition.Module.Remote.Service.PartitionSerializer model = modelSerializer.Deserialize(reader.ReadSubtree(), e => { IMatchEdge edge = (IMatchEdge)e; // if crossing edge, mark it that way if (crossingEdges.ContainsKey(edge.Id)) { edge.RemotePartitionId = crossingEdges[edge.Id].PartitionId; } }); } logger.Info("Deserialization finished. Loaded {0} node(s).", model.Nodes.Count); SortEdgesInNodes(model); return(model); }
public void TestSortingEdges() { var factory = new VirEntityFactory(); Person node = new Person(factory); for (int i = 0; i < 5; i++) { IMatchEdge edge = (IMatchEdge)node.ConnectTo(new Person(factory), Core.Interfaces.EdgeDirection.Both); if (i % 2 == 0) { edge.RemotePartitionId = factory.CreateId(); } } // 3 out of 5 nodes are remote node.SortEdges(); var list = node.Edges.Cast <IMatchEdge>().ToList(); // first two are local Assert.False(list[0].IsRemote); Assert.False(list[1].IsRemote); // rest is remote Assert.True(list.Skip(2).All(e => e.IsRemote)); }
protected bool TryMatchCommunityScore(INode node, IMatchEdge incomingEdge) { return(TryMatchNode(new MatchNodeArg <CommunityScore>( node, pattern.GetNodeByName(PatternNodes.CommunityScore), new Predicate <CommunityScore>(PatternCriteria.CheckCommunityScore), incomingEdge)).IsMatched); }
protected bool TryMatchGroupLeader(INode node, IMatchEdge incomingEdge) { return(TryMatchNode(new MatchNodeArg <Membership>( node, pattern.GetNodeByName(PatternNodes.GroupLeader), n => PatternCriteria.HasGroupLeader(n.Posts), incomingEdge)).IsMatched); }
public void Deserialize(XmlReader reader, IContext context) { if (reader.Name != "CurrentPatternNodeName") { reader.ReadToFollowing("CurrentPatternNodeName"); } this.CurrentPatternNodeName = reader.ReadElementContentAsString(); this.CurrentNode = context.EntityFactory.CreateId(); this.CurrentNode.Deserialize(reader, context); this.MatchedFullSubpattern = bool.Parse(reader.ReadElementContentAsString()); if (reader.Name != "PatternNodes") { reader.ReadToFollowing("PatternNodes"); } var subreader = reader.ReadSubtree(); Dictionary <string, PatternNode> nodes = new Dictionary <string, PatternNode>(); while (subreader.ReadToFollowing("PatternNode")) { var pn = new PatternNode(context.EntityFactory); pn.Deserialize(subreader.ReadSubtree(), context); nodes.Add(pn.Name, pn); } this.patternNodes = nodes; List <IMatchEdge> remoteEdges = new List <IMatchEdge>(); if (reader.Name != "RemoteEdges") { reader.ReadToFollowing("RemoteEdges"); } subreader = reader.ReadSubtree(); while (subreader.ReadToFollowing("RemoteEdge")) { IMatchEdge e = (IMatchEdge)context.EntityFactory.CreateEdge(); e.Deserialize(subreader.ReadSubtree(), context); remoteEdges.Add(e); } foreach (var pn in this.patternNodes.Values) { if (pn.IsMatched) { pn.RemoteEdges = remoteEdges.Where(e => { return(e.EndA.Id.Equals(pn.MatchedNode.Id) || e.EndB.Id.Equals(pn.MatchedNode.Id)); }); } } }
public void Read(XmlReader xmlReader) { xmlReader.ReadToFollowing("Neighbour"); var nid = this.factory.CreateId(); nid.Deserialize(xmlReader, null); var remoteNode = factory.CreateRemoteNode(nid); // HACK: direction might be important. :( this.Edge = (IMatchEdge)this.node.ConnectTo(remoteNode, EdgeDirection.Both); this.Edge.Id.Deserialize(xmlReader, null); bool remote = xmlReader.ReadElementContentAsBoolean(); if (remote) { this.Edge.RemotePartitionId = factory.CreateId(); this.Edge.RemotePartitionId.Deserialize(xmlReader, null); } }
public EdgeWrapper(IMatchEdge edge, INode node) { this.Edge = edge; this.node = node; }
protected virtual T ConvertNode <T>(IMatchEdge incomingEdge, INode node) where T : class, INode { return(node as T); }
protected virtual bool SkipEdge(IMatchEdge edge) { return(false); }
protected override bool SkipEdge(IMatchEdge edge) { return(edge.IsRemote); }
public MatchNodeArg(INode node, PatternNode patternNode, Predicate <T> predicate, IMatchEdge incomingEdge) : this(node, patternNode, predicate) { if (incomingEdge != null) { this.IsRemote = incomingEdge.IsRemote; this.RemotePartitionId = incomingEdge.RemotePartitionId; } else { this.IsRemote = false; this.RemotePartitionId = null; } }