public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj is MappingPair) { MappingPair p = (MappingPair)obj; return(this._x.Equals(p.X) && this._y.Equals(p.Y) && this._type == p.Type); } else { return(false); } }
/// <summary> /// Helper method for brute forcing the possible mappings /// </summary> /// <param name="possibleMappings">Possible Mappings</param> /// <param name="subDependencies">Dependencies in the 1st Graph</param> /// <param name="parentDependencies">Dependencies in the 2nd Graph</param> /// <param name="target">Target Graph (2nd Graph)</param> /// <returns></returns> private List <Dictionary <INode, INode> > GenerateMappings(Dictionary <INode, List <INode> > possibleMappings, List <MappingPair> subDependencies, List <MappingPair> parentDependencies, IGraph target) { List <Dictionary <INode, INode> > mappings = new List <Dictionary <INode, INode> >(); mappings.Add(new Dictionary <INode, INode>()); foreach (INode x in possibleMappings.Keys) { if (possibleMappings[x].Count == 1) { // Only one possible for this Node // This means we can just add this to the dictionaries and continue mappings.ForEach(m => m.Add(x, possibleMappings[x].First())); } else { // Multiple possibilities each of which generates a potential mapping List <Dictionary <INode, INode> > temp = new List <Dictionary <INode, INode> >(); // Need to know whether there are any dependencies we can use to limit possible mappings bool dependent = subDependencies.Any(p => p.Contains(x)); foreach (INode y in possibleMappings[x]) { foreach (Dictionary <INode, INode> m in mappings) { if (m.ContainsValue(y)) { continue; } Dictionary <INode, INode> n = new Dictionary <INode, INode>(m); n.Add(x, y); if (dependent) { foreach (MappingPair dependency in subDependencies) { if (n.ContainsKey(dependency.X) && n.ContainsKey(dependency.Y)) { MappingPair targetDependency = new MappingPair(n[dependency.X], n[dependency.Y], dependency.Type); if (!parentDependencies.Contains(targetDependency)) { continue; } } } } temp.Add(n); } } mappings.Clear(); mappings = temp; } // List of Triples for doing partial mapping Tests foreach (INode test in possibleMappings.Keys) { List <Triple> xs = (from t in _subTriples where t.Involves(test) select t).ToList(); foreach (Dictionary <INode, INode> m in mappings) { // Are all the Blank Nodes involved in these Triples mapped at this stage? if (xs.All(t => t.Nodes.All(node => node.NodeType != NodeType.Blank || m.ContainsKey(node)))) { // Then we can do a partial mapping test IEnumerable <Triple> ys = (from t in xs where _parentTriples.Contains(t.MapTriple(target, m)) select t); if (xs.Count != ys.Count()) { continue; } } } } } return(mappings); }
/// <summary> /// Helper method for brute forcing the possible mappings /// </summary> /// <param name="possibleMappings">Possible Mappings</param> /// <param name="subDependencies">Dependencies in the 1st Graph</param> /// <param name="parentDependencies">Dependencies in the 2nd Graph</param> /// <param name="target">Target Graph (2nd Graph)</param> /// <returns></returns> private List<Dictionary<INode, INode>> GenerateMappings(Dictionary<INode, List<INode>> possibleMappings, List<MappingPair> subDependencies, List<MappingPair> parentDependencies, IGraph target) { List<Dictionary<INode, INode>> mappings = new List<Dictionary<INode, INode>>(); mappings.Add(new Dictionary<INode, INode>()); foreach (INode x in possibleMappings.Keys) { if (possibleMappings[x].Count == 1) { //Only one possible for this Node //This means we can just add this to the dictionaries and continue mappings.ForEach(m => m.Add(x, possibleMappings[x].First())); } else { //Multiple possibilities each of which generates a potential mapping List<Dictionary<INode, INode>> temp = new List<Dictionary<INode, INode>>(); //Need to know whether there are any dependencies we can use to limit possible mappings bool dependent = subDependencies.Any(p => p.Contains(x)); foreach (INode y in possibleMappings[x]) { foreach (Dictionary<INode, INode> m in mappings) { if (m.ContainsValue(y)) continue; Dictionary<INode, INode> n = new Dictionary<INode, INode>(m); n.Add(x, y); if (dependent) { foreach (MappingPair dependency in subDependencies) { if (n.ContainsKey(dependency.X) && n.ContainsKey(dependency.Y)) { MappingPair targetDependency = new MappingPair(n[dependency.X], n[dependency.Y], dependency.Type); if (!parentDependencies.Contains(targetDependency)) { continue; } } } } temp.Add(n); } } mappings.Clear(); mappings = temp; } //List of Triples for doing partial mapping Tests foreach (INode test in possibleMappings.Keys) { List<Triple> xs = (from t in this._subTriples where t.Involves(test) select t).ToList(); foreach (Dictionary<INode, INode> m in mappings) { //Are all the Blank Nodes involved in these Triples mapped at this stage? if (xs.All(t => t.Nodes.All(node => node.NodeType != NodeType.Blank || m.ContainsKey(node)))) { //Then we can do a partial mapping test IEnumerable<Triple> ys = (from t in xs where this._parentTriples.Contains(t.MapTriple(target, m)) select t); if (xs.Count != ys.Count()) { continue; } } } } } return mappings; }