public SuggesterConfig Clone() { SuggesterConfig temp = new SuggesterConfig(); temp.UseIsoRankSimSuggester = this.UseIsoRankSimSuggester; temp.UseValueSimSuggester = this.UseValueSimSuggester; temp.UseTypeSimSuggester = this.UseTypeSimSuggester; temp.UseStructSimSuggester = this.UseStructSimSuggester; temp.UseNameSimSuggester = this.UseNameSimSuggester; temp.UseNeighborSimSuggester = this.UseNeighborSimSuggester; temp.UseLevDistNameSimSuggester = this.UseLevDistNameSimSuggester; return temp; }
private void VisElementCanvas_Drop(object sender, System.Windows.DragEventArgs e) { if (!string.IsNullOrEmpty(modelFile) && sourceASTL != null) //sourceASTL was tvvm (before 15/08/2012) { System.Windows.Point pos = e.GetPosition(VisElementCanvas); /*if (e.Data.GetDataPresent("ToolboxItem")) { //clear canvas children VisElementCanvas.Children.Clear(); //get toolbox item ToolboxItem t = e.Data.GetData("ToolboxItem") as ToolboxItem; visEl = new VisualElement(); visEl = (t.visualElement.Clone()) as VisualElement;//must be call by value visEl.Position = pos; Canvas.SetLeft(visEl, Math.Max(0, pos.X - 100 / 2)); Canvas.SetTop(visEl, Math.Max(0, pos.Y - 100 / 2)); visEl.Content = t.visualElement.Content; VisElementCanvas.Children.Add(visEl); //suggestions visEl.abstractTree.prepare(); this.sourceASTL.prepare(); SuggesterConfig config = new SuggesterConfig(); config.UseNameSimSuggester = true; config.UseTypeSimSuggester = true; config.UseIsoRankSimSuggester = false; config.UseValueSimSuggester = true; config.UseStructSimSuggester = false; this.visualiserSuggester = new Suggester(sourceASTL, visEl.abstractTree, config); this.updateSuggestions(this.visualiserSuggester.getSuggestionsAsStrings(this.visualiserSuggester.imFeelingLucky())); } else*/ if (e.Data.GetDataPresent("VisualElement")) { //clear canvas children VisElementCanvas.Children.Clear(); VisualElement temp = new VisualElement(); temp = (e.Data.GetData("VisualElement") as VisualElement).Clone() as VisualElement; visEl = xrenderer.render(temp.ItemXML) as VisualElement; //render visual elements, no need for return valu, the notation contents will be added to same visual element 6/11/2012 visEl.templateVM.TemplateXmlNode = temp.templateVM.TemplateXmlNode.Clone() as XmlNode; // visEl.templateVMR.TemplateXmlNode = temp.templateVMR.TemplateXmlNode.Clone() as XmlNode; visEl.templateVM.TemplateName = temp.templateVM.TemplateName; visEl.templateVMR.TemplateName = temp.templateVMR.TemplateName; visEl.Data = temp.Data.Clone() as XmlNode; //visEl.ReverseData = temp.ReverseData.Clone() as XmlNode; visEl.Position = pos; //prepare view box for large items Viewbox vb = new Viewbox(); vb.MaxHeight = 180; vb.MaxWidth = 180; vb.StretchDirection = StretchDirection.DownOnly; vb.Stretch = System.Windows.Media.Stretch.Fill; vb.Child = visEl; Canvas.SetLeft(vb, Math.Max(0, pos.X - 100 / 2)); Canvas.SetTop(vb, Math.Max(0, pos.Y - 100 / 2)); if (visEl != null) { VisElementCanvas.Children.Add(vb); //suggestions visEl.abstractTree.prepare(); this.sourceASTL.prepare(); SuggesterConfig config = new SuggesterConfig(); config.UseNameSimSuggester = true; config.UseTypeSimSuggester = true; config.UseIsoRankSimSuggester = false; config.UseValueSimSuggester = true; config.UseStructSimSuggester = false; this.visualiserSuggester = new Suggester(sourceASTL, visEl.abstractTree, config); this.updateSuggestions(this.visualiserSuggester.getSuggestionsAsStrings(this.visualiserSuggester.imFeelingLucky())); //log event logger.log("Visual Element \"" + visEl.VEName + "\" droppped on Visualisation canvas."); } else { reportMessage("Unable to render visual", ReportIcon.Error); } } else if (e.Data.GetDataPresent("VisualFunction")) { VisualFunction vf = e.Data.GetData("VisualFunction") as VisualFunction; if (VisElementCanvas.Children.Count > 0)//if there exists visual element, match functions header node with the element header node { foreach (UIElement u in VisElementCanvas.Children)//assign same header node to the function as well if (u is Viewbox) { if (((u as Viewbox).Child as VisualElement).templateVM.HeaderNode != null)//header node has been set { //set visualfunction's target metamodel as this visual element vf.targetASTL = new AbstractLattice(((u as Viewbox).Child as VisualElement).abstractTree.Root.duplicate()); //set visualfunction's source abstraction from source model vf.sourceASTL = new AbstractLattice(this.sourceASTL.getAbstractNodeAtAddress(((u as Viewbox).Child as VisualElement).templateVM.TemplateAddress).duplicate()); vf.sourceRootNode = ((u as Viewbox).Child as VisualElement).templateVM.HeaderNode; Canvas.SetLeft(vf, Math.Max(0, pos.X - 100 / 2)); Canvas.SetTop(vf, Math.Max(0, pos.Y - 100 / 2)); VisElementCanvas.Children.Add(vf); //log event logger.log("Visual Finction droppped on Visualisation canvas.", ReportIcon.Info); break; } else { reportMessage("Set header node for visual Element first", ReportIcon.Error); } } } else reportMessage("No visual element has been set yet", ReportIcon.Error); } else if (e.Data.GetDataPresent("VisualCondition")) { VisualCondition vc = e.Data.GetData("VisualCondition") as VisualCondition; if (VisElementCanvas.Children.Count > 0)//if there exists visual element, match functions header node with the element header node { foreach (UIElement u in VisElementCanvas.Children)//assign same header node to the condition as well if (u is Viewbox) { if (((u as Viewbox).Child as VisualElement).templateVM.HeaderNode != null)//header node has been set { //set visualfunction's target metamodel as this visual element vc.targetASTL = new AbstractLattice(((u as Viewbox).Child as VisualElement).abstractTree.Root.duplicate()); //set visualfunction's source abstraction from source model vc.sourceASTL = new AbstractLattice(this.sourceASTL.getAbstractNodeAtAddress(((u as Viewbox).Child as VisualElement).templateVM.TemplateAddress).duplicate()); vc.sourceRootNode = ((u as Viewbox).Child as VisualElement).templateVM.HeaderNode; Canvas.SetLeft(vc, Math.Max(0, pos.X - 100 / 2)); Canvas.SetTop(vc, Math.Max(0, pos.Y - 100 / 2)); VisElementCanvas.Children.Add(vc); //log event logger.log("Visual Condition droppped on Visualisation canvas.", ReportIcon.Info); break; } else { reportMessage("Set header node for visual Element first", ReportIcon.Error); } } } else reportMessage("No visual element has been set yet", ReportIcon.Error); } } else reportMessage("Please open input model first!", ReportIcon.Error); }
/// <summary> /// prepare suggestion for suggesting based on whole input models /// A pretty CPU intensive task! /// </summary> private void prepareSuggestions() { if (sourceASTL != null && targetASTL != null) { SuggesterConfig config = new SuggesterConfig(); config.UseIsoRankSimSuggester = true; config.UseNameSimSuggester = true; config.UseStructSimSuggester = true; config.UseValueSimSuggester = true; config.UseTypeSimSuggester = true; this.sourceASTL.prepare(); this.targetASTL.prepare(); mapperSuggester = new Suggester(sourceASTL, targetASTL, config); //this.updateSuggestions(this.mapperSuggester.getOrderedSuggestionsAsStrings(this.mapperSuggester.getSuggestions())); //this.updateSuggestions(this.mapperSuggester.getSuggestionsAsStrings(this.mapperSuggester.getRankedSuggestions(1))); this.updateSuggestions(this.mapperSuggester.getSuggestionsAsStrings(this.mapperSuggester.imFeelingLucky()), true); ReportStatusBar.ShowStatus("Suggestions updated.", ReportIcon.Info); } }
public void evaluateCombination() { List<SuggesterConfig> MaxPrecisionConfigurations = new List<SuggesterConfig>(); List<SuggesterConfig> MaxRecallConfigurations = new List<SuggesterConfig>(); List<SuggesterConfig> MaxFMeasureConfigurations = new List<SuggesterConfig>(); double maxPrecision = 0; double maxRecall = 0; double maxFMeasure = 0; if (sourceASTL != null && targetASTL != null) { this.sourceASTL.prepare(); this.targetASTL.prepare(); SuggesterConfig config = new SuggesterConfig(); //use different combintions for (int i = 0; i < 2; i++) { config.UseIsoRankSimSuggester = !config.UseIsoRankSimSuggester; for (int j = 0; j < 2; j++) { config.UseNameSimSuggester = !config.UseNameSimSuggester; for (int k = 0; k < 2; k++) { config.UseStructSimSuggester = !config.UseStructSimSuggester; for (int l = 0; l < 2; l++) { config.UseTypeSimSuggester = !config.UseTypeSimSuggester; for (int m = 0; m < 2; m++) { config.UseValueSimSuggester = !config.UseValueSimSuggester; for (int p = 0; p < 2; p++) { config.UseNeighborSimSuggester = !config.UseNeighborSimSuggester; //create suggester and test it mapperSuggester = new Suggester(sourceASTL, targetASTL, config); mapperSuggester.imFeelingLucky(); //apperSuggester.getRankedSuggestions(2); SuggesterEvaluator eval = new SuggesterEvaluator(mapperSuggester); //get max precision if (eval.Precision > maxPrecision) { MaxPrecisionConfigurations.Clear(); MaxPrecisionConfigurations.Add(config.Clone()); maxPrecision = eval.Precision; } else if (eval.Precision == maxPrecision) MaxPrecisionConfigurations.Add(config.Clone()); //get best recalls if (eval.Recall > maxRecall) { MaxRecallConfigurations.Clear(); MaxRecallConfigurations.Add(config.Clone()); maxRecall = eval.Recall; } else if (eval.Recall == maxRecall) MaxRecallConfigurations.Add(config.Clone()); //get best FMeasures if (eval.FMeasure > maxFMeasure) { MaxFMeasureConfigurations.Clear(); MaxFMeasureConfigurations.Add(config.Clone()); maxFMeasure = eval.FMeasure; } else if (eval.FMeasure == maxFMeasure) MaxFMeasureConfigurations.Add(config.Clone()); //SuggesterEvaluator eval = new SuggesterEvaluator(mapperSuggester);//evaluation is included in imFeelingLucky } } } } } } StreamWriter writer = new StreamWriter("Eval.csv"); //write best precisions writer.WriteLine("Max precision of: " + maxPrecision + " Achieved by:"); writer.WriteLine(""); string header = "ISO, Name, Struct, Type, Value, Neighbors, Precision, Recall, FMeasure"; writer.WriteLine(header); writer.WriteLine(""); foreach (SuggesterConfig sc in MaxPrecisionConfigurations) { string rl = (sc.UseIsoRankSimSuggester ? "1" : "0") + ", "; rl += (sc.UseNameSimSuggester ? "1" : "0") + ", "; rl += (sc.UseStructSimSuggester ? "1" : "0") + ", "; rl += (sc.UseTypeSimSuggester ? "1" : "0") + ", "; rl += (sc.UseValueSimSuggester ? "1" : "0") + ", "; rl += (sc.UseNeighborSimSuggester ? "1" : "0"); writer.WriteLine(rl); } writer.WriteLine(""); writer.WriteLine(""); //write best recalls writer.WriteLine("Max Recall of: " + maxRecall + " Achieved by:"); writer.WriteLine(""); writer.WriteLine(header); writer.WriteLine(""); foreach (SuggesterConfig sc in MaxRecallConfigurations) { string rl = (sc.UseIsoRankSimSuggester ? "1" : "0") + ", "; rl += (sc.UseNameSimSuggester ? "1" : "0") + ", "; rl += (sc.UseStructSimSuggester ? "1" : "0") + ", "; rl += (sc.UseTypeSimSuggester ? "1" : "0") + ", "; rl += (sc.UseValueSimSuggester ? "1" : "0") + ", "; rl += (sc.UseNeighborSimSuggester ? "1" : "0"); writer.WriteLine(rl); } writer.WriteLine(""); writer.WriteLine(""); //write best FMeasures writer.WriteLine("Max FMeasure of: " + maxFMeasure + " Achieved by:"); writer.WriteLine(""); writer.WriteLine(header); writer.WriteLine(""); foreach (SuggesterConfig sc in MaxFMeasureConfigurations) { string rl = (sc.UseIsoRankSimSuggester ? "1" : "0") + ", "; rl += (sc.UseNameSimSuggester ? "1" : "0") + ", "; rl += (sc.UseStructSimSuggester ? "1" : "0") + ", "; rl += (sc.UseTypeSimSuggester ? "1" : "0") + ", "; rl += (sc.UseValueSimSuggester ? "1" : "0") + ", "; rl += (sc.UseNeighborSimSuggester ? "1" : "0"); writer.WriteLine(rl); } writer.Flush(); writer.Close(); ReportStatusBar.ShowStatus("Suggestor valuation complete!", ReportIcon.Info); } }
private void Test_Click(object sender, RoutedEventArgs e) { //AbstractLattice sabs = new AbstractLattice(@"C:\Users\iavazpour\Desktop\CitationsEndNote.xml"); //AbstractLattice tabs = new AbstractLattice(@"C:\Users\iavazpour\Desktop\FromJobRefDocBook.xml"); AbstractLattice tabs = new AbstractLattice("real_estate_nky.xml"); //AbstractLattice sabs = new AbstractLattice("real_estate_texas.xml"); //AbstractLattice tabs = new AbstractLattice("real_estate_yahoo.xml"); //AbstractLattice tabs = new AbstractLattice("real_estate_homeseeker.xml"); AbstractLattice sabs = new AbstractLattice("real_estate_windermere.xml"); Suggester testSugg; SuggesterConfig scP = new SuggesterConfig(); SuggesterConfig scR = new SuggesterConfig(); double prec = 0; double reca = 1; SuggesterConfig sct = new SuggesterConfig(); sct.UseIsoRankSimSuggester = true; sct.UseNameSimSuggester = true; sct.UseNeighborSimSuggester = true; sct.UseStructSimSuggester = true; sct.UseTypeSimSuggester = true; sct.UseValueSimSuggester = true; testSugg = new Suggester(sabs, tabs, sct); testSugg.imFeelingLucky(); String test1 = "Evaluation Results for test1 " + testSugg.evaluator.printAnalysisResults(); //MessageBox.Show(test1); SuggesterConfig sc = new SuggesterConfig(); sc.UseIsoRankSimSuggester = false; sc.UseNameSimSuggester = false; sc.UseNeighborSimSuggester = false; sc.UseStructSimSuggester = false; sc.UseTypeSimSuggester = false; sc.UseValueSimSuggester = false; for (int i = 1; i < 2; i++) { sc.UseIsoRankSimSuggester = !sc.UseIsoRankSimSuggester; for (int j = 1; j < 2; j++) { sc.UseNameSimSuggester = !sc.UseNameSimSuggester; for (int t = 0; t < 2; t++) { sc.UseNeighborSimSuggester = !sc.UseNeighborSimSuggester; for (int a = 0; a < 2; a++) { sc.UseStructSimSuggester = !sc.UseStructSimSuggester; for (int b = 0; b < 2; b++) { sc.UseTypeSimSuggester = !sc.UseTypeSimSuggester; for (int d = 0; d < 2; d++) { sc.UseValueSimSuggester = !sc.UseValueSimSuggester; testSugg = new Suggester(sabs, tabs, sc); testSugg.imFeelingLucky(); if (testSugg.evaluator.Precision > prec) { scP = sc; prec = testSugg.evaluator.Precision; } if (testSugg.evaluator.Recall < reca) { scR = sc; reca = testSugg.evaluator.Recall; } } } } } } } testSugg = new Suggester(sabs, tabs, scP); testSugg.imFeelingLucky(); //MessageBox.Show(scP.ToString() + testSugg.evaluator.printAnalysisResults(), "Evaluation Results for precision"); string test2 = "Evaluation Results for precision" + testSugg.evaluator.printAnalysisResults(); testSugg = new Suggester(sabs, tabs, scR); testSugg.imFeelingLucky(); //MessageBox.Show(scR.ToString() + testSugg.evaluator.printAnalysisResults(), "Evaluation Results for recall"); string test3 = "Evaluation Results for recall" + testSugg.evaluator.printAnalysisResults(); MessageBox.Show(test1 + test2 + test3); //AbstractLattice sabsR = new AbstractLattice(@"C:\Users\iavazpour\Desktop\CitationsEndNote.xml"); //AbstractLattice tabsR = new AbstractLattice(@"C:\Users\iavazpour\Desktop\FromJobRefDocBook.xml"); //First Create the instance of Stopwatch Class //Stopwatch sw = new Stopwatch(); // Start The StopWatch ...From 000 //sw.Start(); //testSugg.imFeelingLucky(); //sw.Stop(); //this.updateSuggestions(testSugg.getSuggestionsAsStrings(testSugg.LastResults)); //MessageBox.Show(string.Format("Minutes :{0}\nSeconds :{1}\n Mili seconds :{2}", sw.Elapsed.Minutes, // sw.Elapsed.Seconds, sw.Elapsed.TotalMilliseconds)); //testSugg = new Suggester(sabs, tabs, sc); //sw = new Stopwatch(); // Start The StopWatch ...From 000 //sw.Start(); //testSugg.imFeelingLucky(); //sw.Stop(); //this.updateSuggestions(testSugg.getSuggestionsAsStrings(testSugg.LastResults)); //MessageBox.Show(string.Format("Minutes :{0}\nSeconds :{1}\n Mili seconds :{2}", sw.Elapsed.Minutes, // sw.Elapsed.Seconds, sw.Elapsed.TotalMilliseconds)); /*Object obj = TestVisual.Resources["sourceData"]; MessageBox.Show(obj.GetType().ToString()); if ((obj as XmlDataProvider) != null) { XmlNode xnode = (obj as XmlDataProvider).Document.DocumentElement.Clone(); if (xnode != null) { XElement xmlDocumentWithoutNs = RemoveAllNamespaces(XElement.Parse(xnode.OuterXml)); MessageBox.Show(xmlDocumentWithoutNs.ToString()); XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(xmlDocumentWithoutNs.ToString()); TestVisual.Data = xdoc.DocumentElement; } }*/ //string test = @"javasource/class_declarations/class_declaration/properties/java_property/identifier"; //MyLogicalTreeHelper helper = new MyLogicalTreeHelper(); //Collection<object> results = helper.getVisualElementsByName(SourceCanvas, QualifiedNameString.Convert("javasource")); //foreach (var obj in results) //{ // AdornerLayer myAdornerLayer = AdornerLayer.GetAdornerLayer(this); // FrameworkElement found = (obj) as FrameworkElement; // FrameworkElementAdorner fea = new FrameworkElementAdorner(found); // if (myAdornerLayer != null) // { // myAdornerLayer.Add(fea); // } //} //var foundTextBox = LogicalTreeHelper.FindLogicalNode(SourceCanvas, "type"); //if (foundTextBox != null) //{ // AdornerLayer myAdornerLayer = AdornerLayer.GetAdornerLayer(this); // FrameworkElementAdorner fea = new FrameworkElementAdorner(foundTextBox as FrameworkElement); // if (myAdornerLayer != null) // { // myAdornerLayer.Add(fea); // //(foundTextBox as Label).Background = Brushes.Red; // } //} //else // ReportStatusBar.ShowMessage("not found", ReportIcon.Error); //evaluateCombination(); }
public void processVisual_TreeNodeDrop(TreeNodeViewModel treeN, String FullAddress) { //set header for template XSLT templateVM.HeaderNode = treeN; // I do not think these will be used, they have been used in visualiser to check and set visualfunction abstraction //set address Id for template XSLT templateVM.TemplateAddress = FullAddress; // I do not think these will be used AbstractTreeLatticeNode matchingNode = (ParentWindow as Visualiser).sourceASTL.getAbstractNodeAtAddress(FullAddress); //define correspondence if (matchingNode != null)//if you have found the node { if (matchingNode.ruleIndex == -1) { sourceLatticeNodeToMatch = matchingNode; } else if (matchingNode.parent != null) { //create a duplicate****************************** duplicate not implemented yet sourceLatticeNodeToMatch = matchingNode.duplicate(); matchingNode.parent.Children.Add(sourceLatticeNodeToMatch); } sourceLatticeNodeToMatch.isMatched = true; sourceLatticeNodeToMatch.ruleIndex = RULEINDEX;//assign an index for current rule //assign same rule index for this.abstractTree this.abstractTree.Root.ruleIndex = sourceLatticeNodeToMatch.ruleIndex; this.abstractTree.Root.isMatched = true; //increment index for other correspondences RULEINDEX++; //go for reverse, the top part will be obsolete //this.abstractTreeReverse = new AbstractLattice(matchingNode);//might not need abstract tree for reverse, as one way suggestion will eb shown this.ReverseData = matchingNode.ToXML();// treeNode.ToXML();//matchingNode might have worked as well but the signature problems might get in the way this.templateVMR.TemplateName = this.Data.Name; } //suggester initiation AbstractLattice sourceAST = new AbstractLattice(matchingNode); this.abstractTree.prepare(); SuggesterConfig config = new SuggesterConfig(); config.UseNameSimSuggester = true; config.UseTypeSimSuggester = true; config.UseIsoRankSimSuggester = true; config.UseValueSimSuggester = true; config.UseStructSimSuggester = true; (ParentWindow as Visualiser).visualiserSuggester = new Suggester(sourceAST, this.abstractTree, config); (ParentWindow as Visualiser).updateSuggestions((ParentWindow as Visualiser).visualiserSuggester.getSuggestionsAsStrings((ParentWindow as Visualiser).visualiserSuggester.imFeelingLucky())); //log event (ParentWindow as Visualiser).logger.log("\"" + FullAddress + "\" was dropped on \"" + this.VEName + "\"", ReportIcon.OK); (ParentWindow as Visualiser).ReportStatusBar.ShowStatus("Mapping " + treeN.Name + " to " + this.Data.Name, ReportIcon.Info); }