Esempio n. 1
0
        private static void Run()

        {
            //Console.WriteLine("Mama", "Mom");
            var    codeInput = "'Object obj = new Object();'";
            var    codeCSV   = "'Object ob = new Object();'";
            double distance  = (double)StringDistance.LevenshteinDistance(codeInput, codeCSV);
            //Console.WriteLine((codeInput.Length - (distance)) / codeInput.Length + "%");
            //Console.WriteLine((6 - StringDistance.LevenshteinDistance("climax", "volmax")) / 100 + "%");
            //Console.WriteLine(StringDistance.LevenshteinDistance("Ram", "Raman"));
            //Console.WriteLine(StringDistance.LevenshteinDistance("Mama", "Mom"));
        }
Esempio n. 2
0
        //static List data;
        public static List <string>[] Run(string input)
        {
            /*var input = "{"
             + "  \"document\": \"This is horrible code. It looks like it was written by a MMU student. I would not trust you to solve a kindergarten maths problem.\""
             + "}";
             + JArray result = (Newtonsoft.Json.Linq.JArray)getSentiment(input).result;
             + Console.WriteLine((float)result[0]["sentiment"]);
             +
             + using (var reader = new StreamReader("/Users/inderdeepbhatia/Projects/HTBTest1/HTBTest1/data_please.csv"))
             + using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
             + {
             +  var records = csv.GetRecords<dynamic>();
             +  data = records.ToArray();
             + }
             + var codeInput = "'Object obj = new Object();'";
             + var codeCSV = "'Object ob = new Object();'";
             + var matchRatio = "python3 sequence.py " + codeInput + " " + codeCSV;
             + Console.WriteLine(run_cmd("python3 /Users/inderdeepbhatia/Projects/HTBTest1/HTBTest1", codeInput + " " + codeCSV));*/
            //HTBTest1.SequenceMatcher sequenceMatcher = new HTBTest1.SequenceMatcher();

            //var input = "Object obj = new Object();";

            List <string> goodAnswers = new List <string>();
            List <string> badAnswers  = new List <string>();
            List <string> extraData   = new List <string>();

            using (var reader = new StreamReader("/Users/inderdeepbhatia/Projects/HTBTest1/HTBTest1/data_please.csv"))
                using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                {
                    var data = csv.GetRecords <dynamic>().ToList();
                    //data.GetEnumerator().MoveNext();
                    //Console.WriteLine(data.ElementAt(0).QuestionBody);
                    double score = 0.0;
                    double total = 0.0;
                    for (int i = 0; i < data.Count; i++)
                    {
                        var    row      = data.ElementAt(i);
                        string hasCode  = row.HasCode;
                        double newScore = 0.0;
                        if (hasCode == "True")
                        {
                            string answerBody      = row.AnswerBody;
                            string commentBody     = row.CommentText;
                            int    answerScore     = int.Parse(row.AnswerScore);
                            double distance        = (double)StringDistance.LevenshteinDistance(input, answerBody);
                            double matchPercentage = (input.Length - (distance)) / input.Length;
                            if (matchPercentage > 0.6)
                            {
                                newScore = getScore(answerBody, commentBody, matchPercentage, answerScore);
                                total   += matchPercentage * answerScore;
                                if (newScore >= 0)
                                {
                                    goodAnswers.Add(commentBody);
                                }
                                else
                                {
                                    badAnswers.Add(commentBody);
                                }
                            }
                        }
                        else
                        {
                            String questionBody    = row.QuestionBody;
                            String answerBody      = row.AnswerBody;
                            int    answerScore     = int.Parse(row.AnswerScore);
                            double distance        = (double)StringDistance.LevenshteinDistance(input, questionBody);
                            double matchPercentage = (input.Length - distance) / input.Length;
                            if (matchPercentage > 0.6)
                            {
                                newScore = getScore(questionBody, answerBody, matchPercentage, answerScore);
                                total   += matchPercentage * answerScore;
                                if (newScore >= 0)
                                {
                                    goodAnswers.Add(answerBody);
                                }
                                else
                                {
                                    badAnswers.Add(answerBody);
                                }
                            }
                        }
                        score += newScore;
                        //Console.WriteLine("Current Score: " + score);
                    }
                    extraData.Add("" + score);
                    extraData.Add("" + total);
                }
            return(new List <string>[] { goodAnswers, badAnswers, extraData });

            /*String answerBody = "Object obj = new Object();";
             * String commentBody = "That is acceptable code, but can use more memory than what you might be intending to";
             * double matchPercentage = 0.8;
             * int answerScore = 30;
             * WriteLine(getScore(answerBody, commentBody, matchPercentage, answerScore));*/
        }