Beispiel #1
0
            private void OnGetClassifiers(GetClassifiersTopLevelBrief classifiers)
            {
                bool bFound = false;

                foreach (var c in classifiers.classifiers)
                {
                    if (c.name.ToLower().StartsWith(ClassifierName.ToLower()))
                    {
                        bFound = Service.GetClassifier(c.classifier_id, OnGetClassifier);
                        break;
                    }
                }

                if (!bFound)
                {
                    Log.Warning("VisualRecognition", "Failed to find classifier {0}", ClassifierName);
                    Callback(null);
                }
            }
Beispiel #2
0
            private void GetClassifiers(Classifiers classifiers)
            {
                bool bFound = false;

                foreach (var c in classifiers.classifiers)
                {
                    if (c.name.ToLower().StartsWith(ClassifierName.ToLower()))
                    {
                        // now get the classifier details..
                        bFound = Service.GetClassifier(c.classifier_id, GetClassifier);
                        break;
                    }
                }

                if (!bFound)
                {
                    Log.Error("Natural Language Classifier", "Fail to find classifier {0}", ClassifierName);
                    Callback(null);
                }
            }
        /// <summary>
        /// This is the constructor for BOF  user reviews. Overloaded Method
        /// </summary>
        /// <param name="inputFramesList"></param>
        public WekaClassifier(List <List <string> > inputBoFList, string trainingFilePath, string directoryName, ClassifierName classificationName, TextFilterType textFilterType)
        {
            ConstructFramesArffFile(inputBoFList, directoryName);
            switch (classificationName)
            {
            case ClassifierName.SupportVectorMachine:
                FilteredSVM("BOF", trainingFilePath, directoryName, textFilterType);
                break;

            case ClassifierName.NaiveBayes:
                FilteredNaiveBayes("BOF", trainingFilePath, directoryName, textFilterType);
                break;

            case ClassifierName.RandomForest:
                break;

            default:
                break;
            }
        }
        /// <summary>
        /// Classify all user reviews and export. Takes in a list of user reviews and training File path
        /// </summary>
        /// <param name="userReviews"></param>
        /// <param name="trainingFilePath"></param>
        private void classifyAllReviews(List <string> userReviews, string trainingFilePath, string indicatorTermFilePath, ClassifierName classifierName)
        {
            ResolveTextFilterType();
            WekaClassifier.WekaClassifier classifier;
            allNFRClassification = new List <string>();

            filteredReviews = new List <string>();
            foreach (string review in userReviews)
            {
                filteredReviews.Add(FilterText(review));
            }

            try
            {
                classifier           = new WekaClassifier.WekaClassifier(filteredReviews, trainingFilePath, Directory.GetCurrentDirectory(), classifierName, txtfilterType, ClassificationScheme.Binary, indicatorTermFilePath);
                allNFRClassification = classifier.predictedLabel;
                //Instead of adding filtered text add the original review.
                var temp = new List <string>();
                foreach (var item in classifier.predictedData)
                {
                    for (int i = 0; i < userReviews.Count; i++)
                    {
                        if (FilterText(userReviews[i]) == item)
                        {
                            temp.Add(userReviews[i]);
                            break;
                        }
                    }
                }
                allNFRReviews = temp;
            }
            catch (Exception e)
            {
                exceptionMessage = e.ToString();
            }
        }
        /// <summary>
        /// Classify all user reviews and export. Takes in a list of user reviews and training File path
        /// </summary>
        /// <param name="userReviews"></param>
        /// <param name="trainingFilePath"></param>
        private void classifyAllReviews(List <string> userReviews, string trainingFilePath, ClassifierName classifierName)
        {
            ResolveTextFilterType();


            WekaClassifier.WekaClassifier classifier;
            allClassification = new List <string>();

            if (BOFCheckboxCheckedState)
            {
                //Server Test
                FrameNetOnline.FrameNetOnline frameNetServerTest = new FrameNetOnline.FrameNetOnline("This is a test.");

                //if server test passes (returns more than 0 frames) then proceed with frame extraction.
                if (frameNetServerTest.output.Count != 0)
                {
                    listOfReviewsBoF   = new List <List <string> >();
                    currentReviewIndex = 0;
                    foreach (string review in userReviews)
                    {
                        currentReviewIndex++;
                        FrameNetOnline.FrameNetOnline abc = new FrameNetOnline.FrameNetOnline(review);
                        listOfReviewsBoF.Add(abc.output);
                    }
                    try
                    {
                        classifier = new WekaClassifier.WekaClassifier(listOfReviewsBoF, trainingFilePath, Directory.GetCurrentDirectory(), classifierName, txtfilterType);

                        foreach (string data in classifier.AllClassification)
                        {
                            allClassification.Add(data);
                        }
                    }
                    catch (Exception e)
                    {
                        exceptionMessage = e.ToString();
                    }
                }
                else
                {
                    MessageBox.Show("Looks like the server is down");
                }
            }
            else if (BOWCheckboxCheckedState)
            {
                filteredReviews = new List <string>();
                foreach (string review in userReviews)
                {
                    filteredReviews.Add(FilterText(review));
                }

                try
                {
                    classifier = new WekaClassifier.WekaClassifier(filteredReviews, trainingFilePath, Directory.GetCurrentDirectory(), classifierName, txtfilterType);
                    foreach (string data in classifier.AllClassification)
                    {
                        allClassification.Add(data);
                    }
                }
                catch (Exception e)
                {
                    exceptionMessage = e.ToString();
                }
            }
        }