private List <ComparationDetail> prepareDetails(int i, int j, string sentence1, string sentence2, List <string> commonParts)
        {
            List <ComparationDetail> details = new List <ComparationDetail>();

            foreach (String part in commonParts)
            {
                ComparationDetail detail = prepareDetail(i, j, sentence1, sentence2, part);
                details.Add(detail);
            }
            return(details);
        }
        private ComparationDetail prepareDetail(int i, int j, string sentence1, string sentence2, string part)
        {
            ComparationDetail detail = new ComparationDetail();

            detail.file1_full_sentence   = sentence1;
            detail.file1_sentence_number = i;
            detail.file2_full_sentence   = sentence2;
            detail.file2_sentence_number = j;
            detail.similarity            = new List <string>(part.Split(SPACE_CHAR));
            return(detail);
        }
        private ComparationDetail prepareDetail(int i, int j, string sentence1, string sentence2, List <String> part)
        {
            ComparationDetail detail = new ComparationDetail();

            detail.file1_full_sentence   = sentence1;
            detail.file1_sentence_number = i;
            detail.file2_full_sentence   = sentence2;
            detail.file2_sentence_number = j;
            detail.similarity            = part;
            return(detail);
        }
Exemple #4
0
        public override ComparationResult compare(ComparationInput input)
        {
            String text1LowerCase = toLowerCase(input.file1);
            String text2LowerCase = toLowerCase(input.file2);

            String text1RemovedManySpaces = changeManySpacesToOne(text1LowerCase);
            String text2RemovedManySpaces = changeManySpacesToOne(text2LowerCase);

            List <String> text1Sentences = splitToSentence(text1RemovedManySpaces);
            List <String> text2Sentences = splitToSentence(text2RemovedManySpaces);

            List <String> text1ToAnalyze = reduceListByEmpty(trim(text1Sentences));
            List <String> text2ToAnalyze = reduceListByEmpty(trim(text2Sentences));


            ComparationResult result = new ComparationResult();

            result.filename1 = input.filename1;
            result.filename2 = input.filename2;
            result.details   = new List <ComparationDetail>();
            for (int i = 0; i < text1ToAnalyze.Count(); i++)
            {
                for (int j = 0; j < text2ToAnalyze.Count(); j++)
                {
                    var sentence1 = text1ToAnalyze[i];
                    var sentence2 = text2ToAnalyze[j];
                    if (sentence1.Equals(sentence2))
                    {
                        ComparationDetail detail = new ComparationDetail();
                        detail.file1_full_sentence   = sentence1;
                        detail.file1_sentence_number = i;
                        detail.file2_full_sentence   = sentence2;
                        detail.file2_sentence_number = j;
                        detail.similarity            = new List <String>(sentence1.Split(SPACE_CHAR));
                        result.details.Add(detail);
                    }
                }
            }
            HashSet <String> uniqueResult    = new HashSet <String>(result.details.Select(r => r.file1_full_sentence));
            HashSet <String> uniqueSentence1 = new HashSet <String>(text1ToAnalyze);
            HashSet <String> uniqueSentence2 = new HashSet <String>(text2ToAnalyze);

            result.score  = countScore(uniqueResult, uniqueSentence1, uniqueSentence2);
            result.weigth = weight;
            return(result);
        }