Exemplo n.º 1
0
        public static List<ICSM11DataSet> ImportDatasets(FilePath XMLfile)
        {
            XmlDocument XMLdoc = new XmlDocument();
            XMLdoc.Load(XMLfile.Absolute);

            string[] s = XMLfile.Absolute.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
            StringBuilder path = new StringBuilder();
            for (long i = 0; i < s.Length - 1; i++)
            {
                path.Append(s[i]);
                path.Append("\\");
            }
            path.Append(XMLdoc.GetElementsByTagName("Datasets")[0].Attributes["Directory"].Value.Replace('/', '\\'));
            string RTMsimspath = XMLdoc.GetElementsByTagName("Datasets")[0].Attributes["PrecomputedRTMSimilaritiesDirectory"].Value.Replace('/', '\\');

            List<ICSM11DataSet> datasets = new List<ICSM11DataSet>();
            XmlNodeList nodelist = XMLdoc.GetElementsByTagName("Dataset");

            foreach (XmlNode node in nodelist)
            {
                ICSM11DataSet dataset = new ICSM11DataSet();
                dataset.SourceArtifacts = path + node["Corpus"].Attributes["Directory"].Value + node["Corpus"]["SourceArtifacts"].InnerText
                    + "#" + node["Corpus"]["SourceArtifacts"].Attributes["Extension"].Value;
                dataset.TargetArtifacts = path + node["Corpus"].Attributes["Directory"].Value + node["Corpus"]["TargetArtifacts"].InnerText
                    + "#" + node["Corpus"]["TargetArtifacts"].Attributes["Extension"].Value;
                dataset.Oracle = path + node["Corpus"].Attributes["Directory"].Value + node["Corpus"]["Oracle"].InnerText;
                dataset.Name = node.Attributes["Name"].Value;
                dataset.PrecomputedRTMSimilarities = path + RTMsimspath + node["Settings"]["PrecomputedRTMSimilarities"].InnerText;
                dataset.RTM = new RTMSettings
                {
                    Alpha = Convert.ToDouble(node["Settings"]["RTM"]["Alpha"].InnerText),
                    Beta = Convert.ToDouble(node["Settings"]["RTM"]["Beta"].InnerText),
                    Eta = Convert.ToDouble(node["Settings"]["RTM"]["Eta"].InnerText),
                    NumTopics = Convert.ToInt32(node["Settings"]["RTM"]["NumTopics"].InnerText),
                };
                dataset.PCA = new PCASettings
                {
                    VSM_JS = Convert.ToDouble(node["Settings"]["PCA"]["VSM_JS"].InnerText),
                    VSM_RTM = Convert.ToDouble(node["Settings"]["PCA"]["VSM_RTM"].InnerText),
                    JS_RTM = Convert.ToDouble(node["Settings"]["PCA"]["JS_RTM"].InnerText),
                };
                datasets.Add(dataset);
            }

            return datasets;
        }
 private SummaryData ExtractSummaryData(ICSM11DataSet ds, string modelName, DataSetPairsType type)
 {
     DataSetPairs model = null;
     foreach (DataSetPairs dsp in ds.Metrics)
     {
         if (dsp.Name.Split(new char[] { '.' })[0].Equals(modelName))
         {
             model = dsp;
         }
     }
     if (model == null)
         throw new ArgumentException("Model \"" + modelName + "\" not found.");
     switch (type)
     {
         case DataSetPairsType.Precision:
             return CreateSummaryData(model.PrecisionData, modelName);
         case DataSetPairsType.Recall:
             return CreateSummaryData(model.RecallData, modelName);
         case DataSetPairsType.AveragePrecision:
             return CreateSummaryData(model.AveragePrecisionData, modelName);
         case DataSetPairsType.MeanAveragePrecision:
             return CreateSummaryData(model.MeanAveragePrecisionData, modelName);
         default:
             throw new ArgumentException("Unknown DataSetPairsType");
     }
 }