Пример #1
0
        /// <summary>
        /// just the default comparison
        /// </summary>
        private static void EvaluateStandardSet()
        {
            try
            {
                var factory   = new MutexTokenFactory();
                var watch     = Stopwatch.StartNew();
                var evalModel = new EvaluationRunModel(TEST_SUITE_DIRECTORY);
                cLogger.DebugFormat("evaluation run finished in {0} ms", watch.ElapsedMilliseconds);
                new ListResultsExport().Run(evalModel);

                File.WriteAllLines(@"test\tokens\tok1.txt", factory.GetTokenWrapperListFromFile(@"test\tokens\main-01.c").GetDebugTokenStrings());
                File.WriteAllLines(@"test\tokens\tok2.txt", factory.GetTokenWrapperListFromFile(@"test\tokens\main-03.c").GetDebugTokenStrings());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            //if ("y" == decision)
            {
                new ComparisonExcelExport("comparisons").Run(
                    ComparisonHistoryModel.AllHistories);

                new RuntimeExcelExport("runtime").Run(
                    new[]
                {
                    new ComparisonHistoryModel("TPLV04-S01-02"),
                });
            }

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Done!");
            Console.ReadLine();
        }
Пример #2
0
        private static GSTTokenList <GSTToken <TokenWrapper> > GetTokens(FileInfo file)
        {
            var factory = new MutexTokenFactory();
            var tokens  = factory.GetTokenWrapperListFromFile(file.FullName);

            return(tokens.ToGSTTokenList());
        }
Пример #3
0
        /// <summary>
        /// creates the token list from the file at pathToFile
        /// </summary>
        /// <param name="pathToFile"></param>
        /// <param name="referenceData"></param>
        public ComparisonModel(string pathToFile, IEnumerable <SourceEntityData> referenceData)
        {
            ReferenceData = referenceData;
            var factory = new MutexTokenFactory();

            Tokens = factory.GetTokenWrapperListFromSource(pathToFile);
        }
Пример #4
0
        /// <summary>
        /// takes the two sources and performs the GST
        /// </summary>
        /// <param name="sourcePath1"></param>
        /// <param name="sourcePath2"></param>
        public ComparisonModel(string name, Int64 evalRunID, string sourcePath1, string sourcePath2)
        {
            Name            = name;
            EvaluationRunID = evalRunID;

            var  directory      = Path.GetDirectoryName(Path.GetFullPath(sourcePath1));
            bool tmplFileExists = File.Exists(Path.Combine(directory, "template.c"));

            var watch = Stopwatch.StartNew();

            var tmplFile = Directory.GetFiles(directory, "template.c").FirstOrDefault();
            var path1    = tmplFileExists ? TemplatingHelper.StripTemplateFromSourceFile(sourcePath1, tmplFile) : sourcePath1;
            var path2    = tmplFileExists ? TemplatingHelper.StripTemplateFromSourceFile(sourcePath2, tmplFile) : sourcePath2;
            var factory  = new MutexTokenFactory();
            var tokens1  = factory.GetTokenWrapperListFromFile(path1);
            var tokens2  = factory.GetTokenWrapperListFromFile(path2);


            cLogger.DebugFormat("TokenStream Length: {0} -- {1}", tokens1.Count(), tokens2.Count());
            var algo = new GSTAlgorithm <GSTToken <TokenWrapper> >(
                tokens1.ToGSTTokenList <TokenWrapper>(),
                tokens2.ToGSTTokenList <TokenWrapper>());

            algo.RunToCompletion();
            Result = algo.Similarity;

            Source1 = new SourceModel(Path.GetFileNameWithoutExtension(sourcePath1), factory.GetJoinedTokenString(tokens1));
            Source2 = new SourceModel(Path.GetFileNameWithoutExtension(sourcePath2), factory.GetJoinedTokenString(tokens2));
            SQLFacade.Instance.CreateComparison(name, Result, watch.ElapsedMilliseconds, evalRunID, Source1.ID, Source2.ID);
        }
Пример #5
0
        public void Default()
        {
            var factory = new MutexTokenFactory();
            var model   = new ComparisonModel(factory.GetTokenWrapperEnumerable(defaultTokenSet),
                                              new [] {
                new SourceEntityData("stud1", "assignment1", defaultTokenSet, "bla"),
                new SourceEntityData("stud2", "assignment1", new[] { "CASE", "DECREMENT" }, "bla2")
            }, factory);

            model.Calculate();

            Assert.AreEqual(100, model.MaximumSimilarity);
        }
Пример #6
0
        /// <summary>
        /// Compares the two files and returns the Similarity.
        /// Lexer used: MutexCLexer
        /// Algorithm used: HashingGSTAlgorithm (MML = 8)
        /// </summary>
        /// <param name="path1"></param>
        /// <param name="path2"></param>
        /// <returns></returns>
        public static Int32 CompareFiles(string path1, string path2)
        {
            var factory = new MutexTokenFactory();

            var tokens1 = factory.GetTokenWrapperListFromFile(path1);
            var tokens2 = factory.GetTokenWrapperListFromFile(path2);

            var algo = new HashingGSTAlgorithm <GSTToken <TokenWrapper> >(
                tokens1.ToGSTTokenList <TokenWrapper>(),
                tokens2.ToGSTTokenList <TokenWrapper>())
            {
                MinimumMatchLength = 8
            };

            algo.RunToCompletion();


            return(algo.Similarity);
        }
Пример #7
0
        /// <summary>
        /// calculates the maximum similarity of the provided source against
        /// all sources for the given asignment in the reference database
        /// </summary>
        /// <param name="student"></param>
        /// <param name="assignment"></param>
        /// <param name="source"></param>
        public void Start(string student, string assignment, string source)
        {
            cLogger.DebugFormat("starting with threshold {0}", Threshold);
            TokenFactory factory = new MutexTokenFactory();

            var tokens = factory.GetTokenWrapperListFromSource(source);

            //LexerHelper.CreateLexerFromSource(source).GetTokenWrappers().ToList();
            cLogger.Debug("tokenized source... loading Data Repository");
            var repo = Repository.GetRepository();

            comparisonModel = new ComparisonModel(tokens, repo.LoadByAssignment(assignment), factory);

            comparisonModel.Calculate();

            var sourceEntityData = new SourceEntityData(student, assignment, tokens.ToStringEnumerable(), source);

            repo.Store(sourceEntityData, MaximumSimilarity < Threshold);
        }
Пример #8
0
        public void ANTLRITokenVersusMutexTokenImpl()
        {
            var factory = new MutexTokenFactory();
            var itokens = factory.GetTokenWrapperListFromSource("void main(int argc, char** argv)").ToGSTTokenList();

            var tokennames  = new[] { "VOID", "IDENTIFIER", "INTEGER_DATATYPE", "IDENTIFIER", "POINTER_DATATYPE", "IDENTIFIER" };
            var mutextokens = factory.GetTokenWrapperEnumerable(tokennames).ToGSTTokenList();

            for (int i = 0; i < itokens.Count; i++)
            {
                Assert.AreEqual(itokens[i].GetHashCode(), mutextokens[i].GetHashCode());
            }

            var algo = new HashingGSTAlgorithm <GSTToken <TokenWrapper> >(itokens, mutextokens)
            {
                MinimumMatchLength = 3
            };

            algo.RunToCompletion();


            Assert.AreEqual(100, algo.Similarity);
        }