Example #1
0
        public void ExtendDatabaseWithArticle(LabeledArticle article)
        {
            Annotation       annotation         = _processor.Annotate(article.Article);
            HashSet <string> persons            = NLPCoreHelper.GetPersons(annotation);
            HashSet <string> organizations      = NLPCoreHelper.GetOrganizations(annotation);
            HashSet <string> locations          = NLPCoreHelper.GetLocation(annotation);
            HashSet <string> sportSpecificWords = NLPCoreHelper.GetOccurence(annotation, _sportSpecificWords);

            foreach (string person in persons)
            {
                PersonOccurenceDatabase.AddWord(person, article.Category);
            }

            foreach (string organization in organizations)
            {
                OrganizationOccurenceDatabase.AddWord(organization, article.Category);
            }

            foreach (string location in locations)
            {
                LocationsOccurenceDatabase.AddWord(location, article.Category);
            }

            foreach (string sportSpecificWord in sportSpecificWords)
            {
                SportSpecificWordsOccurenceDatabase.AddWord(sportSpecificWord, article.Category);
            }
        }
Example #2
0
        public double TrainClassifierWithArticle(LabeledArticle article)
        {
            double[] input  = GetRawFeatures(article.Article);
            double[] output = GetOutput(article);

            double error = _teacher.Run(input, output);

            Console.WriteLine(error);
            return(error);
        }
Example #3
0
        public double CalculateError(LabeledArticle article)
        {
            double[] input  = GetRawFeatures(article.Article);
            double[] output = _classifier.Compute(input);
            double   sum    = output.Sum();

            for (int i = 0; i < output.Length; i++)
            {
                output[i] /= sum;
            }
            double[] correct = GetOutput(article);
            double   error   = 0;

            for (int i = 0; i < output.Length; i++)
            {
                error += Math.Abs(output[i] - correct[i]);
            }
            return(error);
        }
Example #4
0
 private double[] GetOutput(LabeledArticle article)
 {
     double[] output = new double[_categoriesCount];
     output[_categoryIndex[article.Category]] = 1;
     return(output);
 }