Esempio n. 1
0
        public IActionResult SimpleComparison([FromBody] ComparisonRequest request)
        {
            try
            {
                //var matches = new Dictionary<string, IList<Match>>();
                var matches     = new List <MatchResult>();
                var submissions = request.Submissions.Select(
                    s => new StudentSequence()
                {
                    FirstName     = s.FirstName,
                    LastName      = s.LastName,
                    TokenSequence = CreateCombinedSequence(s)
                }).ToList();

                // compare every submission with every other submission
                foreach (var curSequence in submissions)
                {
                    foreach (var otherSequence in submissions)
                    {
                        var tmpResult = new MatchResult(
                            new Student(curSequence.FirstName, curSequence.LastName),
                            new Student(otherSequence.FirstName, otherSequence.LastName));

                        if (curSequence == otherSequence)
                        {
                            continue;
                        }

                        var match = GstComparator.Compare <int>(curSequence.TokenSequence, otherSequence.TokenSequence, 9)
                                    .OrderBy(m => m.PatternIndex)
                                    .ToList();

                        tmpResult.Matches = match;
                        if (match != null && match.Count > 0)
                        {
                            matches.Add(tmpResult);
                        }
                        //matches.Add($"{curSequence.Name} - {otherSequence.Name}", match);

                        curSequence.TokenSequence.Reset();
                        otherSequence.TokenSequence.Reset();
                    }
                }

                return(new ObjectResult(matches));
            }
            catch (Exception)
            {
                return(new BadRequestObjectResult("Invalid request format"));
            }
        }
Esempio n. 2
0
        public void BasicGstTest()
        {
            var s1 = new Sequence <int>(
                new List <Token <int> >()
            {
                new Token <int>(1),
                new Token <int>(2),
                new Token <int>(3),
                new Token <int>(4),
                new Token <int>(5),
                new Token <int>(6),
                new Token <int>(7),
                new Token <int>(8),
                new Token <int>(9),
                new Token <int>(10),
                new Token <int>(11),
                new Token <int>(12),
            });

            var s2 = new Sequence <int>(
                new List <Token <int> >()
            {
                new Token <int>(1),
                new Token <int>(2),
                new Token <int>(3),
                new Token <int>(1),
                new Token <int>(2),
                new Token <int>(3),
                new Token <int>(8),
                new Token <int>(9),
                new Token <int>(4),
                new Token <int>(5),
                new Token <int>(6),
                new Token <int>(7),
            });

            var result = GstComparator.Compare(s1, s2, 3);

            Assert.AreEqual(2, result.Count);

            // First match 4,5,6,7 from pattern pos 3 and text pos 8
            Assert.AreEqual(3, result[0].PatternIndex);
            Assert.AreEqual(8, result[0].TextIndex);
            Assert.AreEqual(4, result[0].Length);

            // Second match 1,2,3 from pattern pos 0 and text pos 0
            Assert.AreEqual(0, result[1].PatternIndex);
            Assert.AreEqual(0, result[1].TextIndex);
            Assert.AreEqual(3, result[1].Length);
        }