public static DirectedGraph ConstructGraph(this LeafNodeDictionaryAnalysis analysis, DataPointMapperResult output) { //graphWrapNode<LeafNodeDictionaryEntry> dynamicContent = graphTools.BuildGraphFromItems<LeafNodeDictionaryEntry, graphWrapNode<LeafNodeDictionaryEntry>>(analysis.DynamicContent.items, new Func<LeafNodeDictionaryEntry, string>(x => x.XPath), "/"); //graphWrapNode<LeafNodeDictionaryEntry> staticContent = graphTools.BuildGraphFromItems<LeafNodeDictionaryEntry, graphWrapNode<LeafNodeDictionaryEntry>>(analysis.StaticContent.items, new Func<LeafNodeDictionaryEntry, string>(x => x.XPath), "/"); Dictionary <IGraphNode, Double> Weight = new Dictionary <IGraphNode, double>(); foreach (graphWrapNode <LeafNodeDictionaryEntry> leaf in analysis.CompleteGraph.getAllLeafs()) { if (leaf.item != null) { if (leaf.item.Category.HasFlag(NodeInTemplateRole.Dynamic)) { var nd = leaf.Add("$DYNAMIC$"); Weight[leaf] = 1; } else if (leaf.item.Category.HasFlag(NodeInTemplateRole.Static)) { Weight[leaf] = 0.8; if (!leaf.item.Content.isNullOrEmpty()) { var nd = leaf.Add(leaf.item.Content.trimToLimit(50, true)); } } } } Func <graphWrapNode <LeafNodeDictionaryEntry>, Int32> typeID = x => { if (x.item == null) { return(0); } return(1); }; Func <graphWrapNode <LeafNodeDictionaryEntry>, Double> nodeW = x => { if (x.item == null) { return(0.2); } if (Weight.ContainsKey(x)) { return(Weight[x]); } return(0.3); //return (1 - (((Double)0.8 / ((Double)x.Count() + 1)))); }; Func <graphWrapNode <LeafNodeDictionaryEntry>, String> categoryID = x => { foreach (var b in output.MapBlocks) { if (x == null) { return("Null"); } if (x.item == null) { return("Null"); } if (x.item.XPath.StartsWith(b.BlockXPathRoot)) { String dpr = x.item.XPath.removeStartsWith(b.BlockXPathRoot); foreach (var dp in b.DataPoints) { if (dpr == dp.DataPointXPathRoot + dp.LabelXPathRelative) { return("Label"); } if (dpr == dp.DataPointXPathRoot + dp.DataXPathRelative) { return("Data"); } } return(b.name); } } if (x.item != null) { return(x.item.Category.ToString()); } return("Structure"); }; List <String> Categories = new List <string>(); foreach (graphWrapNode <LeafNodeDictionaryEntry> g in analysis.CompleteGraph.getAllChildren()) { Categories.AddUnique(categoryID(g)); } StructureGraphConverter converter = new StructureGraphConverter() { CategoryID = categoryID, TypeID = typeID, NodeWeight = nodeW, LinkWeight = (x, y) => 1 }; var c_dmgl = converter.Convert(analysis.CompleteGraph, 500); return(c_dmgl); }
public static DirectedGraph ConstructDPBGraph(this LeafNodeDictionaryAnalysis input, DataPointMapperResult output) { Func <graphWrapNode <LeafNodeDictionaryEntry>, Double> nodeW = x => { foreach (var b in output.MapBlocks) { if (x.path.StartsWith(b.BlockXPathRoot)) { return(1); } } return(0.5); }; StructureGraphConverter converter = new StructureGraphConverter() { CategoryID = x => "Default", TypeID = x => 1, NodeWeight = nodeW, LinkWeight = (x, y) => 1 }; var c_dmgl = converter.Convert(input.CompleteGraph, 500); return(c_dmgl); }