Beispiel #1
0
        private bool RestoreKeywordClusterer()
        {
            List <MechanicQuery>  mechanicQueries  = DataSource.LoadMechanicQueries();
            List <KeywordExample> trainingExamples = new List <KeywordExample>();

            foreach (MechanicQuery query in mechanicQueries)
            {
                List <List <string> > complaintTags = PartOfSpeechTagger.Tag(
                    SentenceTokenizer.TokenizeSentence(query.Complaint.ToLower())
                    );
                List <string>  keywords = KeywordPredictor.PredictKeywords(complaintTags);
                KeywordExample example  = new KeywordExample();
                foreach (string s in keywords)
                {
                    example.AddKeyword(s);
                }
                trainingExamples.Add(example);
            }
            KeywordClusterer.Train(trainingExamples);
            try
            {
                AnsEncoderStream streamOut = new AnsEncoderStream(
                    new FileStream(DefaultModelFileLocations.KEYWORD_SIMILARITY_CLUSTERER_FILE, FileMode.Create, FileAccess.Write),
                    1048576,
                    4096
                    );
                KeywordClusterer.Save(streamOut);
                streamOut.Close();
            } catch (IOException)
            {
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        private static bool TrainModel(KeywordPredictorFileMapping mapping)
        {
            IKeywordPredictor predictor = mapping.KeywordPredictorType.GetMethod("GetGlobalModel").Invoke(null, null) as IKeywordPredictor;
            var keywordData             = new FileSystemDataSource().LoadKeywordTrainingExamples();
            var X = KeywordPredictorTrainingUtils.GenerateKeywordTrainingData(keywordData);
            var Y = KeywordPredictorTrainingUtils.GenerateKeywordTargetData(keywordData);

            predictor.Train(X, Y);
            AnsEncoderStream stream;

            try
            {
                stream = new AnsEncoderStream(
                    new FileStream(mapping.DefaultFileLocation, FileMode.Create, FileAccess.Write),
                    1048576,
                    4096);
            } catch (IOException)
            {
                return(false);
            }
            using (stream)
            {
                bool res = predictor.Save(stream);
                stream.Flush();
                return(res);
            }
        }
Beispiel #3
0
        private bool RestoreProblemPredictor()
        {
            List <MechanicQuery>  mechanicQueries  = DataSource.LoadMechanicQueries();
            List <List <object> > trainingExamples = new List <List <object> >();
            List <object>         targetExamples   = new List <object>();

            foreach (MechanicQuery query in mechanicQueries)
            {
                List <object> currExample = new List <object>();
                currExample.Add(query.Make);
                currExample.Add(query.Model);
                List <List <string> > complaintTags = PartOfSpeechTagger.Tag(
                    SentenceTokenizer.TokenizeSentence(query.Complaint.ToLower())
                    );
                List <string>  keywords = KeywordPredictor.PredictKeywords(complaintTags);
                KeywordExample example  = new KeywordExample();
                foreach (string s in keywords)
                {
                    example.AddKeyword(s);
                }
                List <int> groupsOut = KeywordClusterer.PredictTopNSimilarGroups(example, NUMBER_COMPLAINT_GROUPS);
                foreach (int i in groupsOut)
                {
                    currExample.Add(i);
                }
                trainingExamples.Add(currExample);
                targetExamples.Add(query.Problem.ToLower());
            }
            ProblemPredictor.Train(trainingExamples, targetExamples);
            try
            {
                AnsEncoderStream saveStream = new AnsEncoderStream(
                    new FileStream(DefaultModelFileLocations.KNN_QUERY_PROBLEM_PREDICTOR_FILE, FileMode.Create, FileAccess.Write),
                    1048576,
                    4096
                    );
                ProblemPredictor.Save(saveStream);
                saveStream.Flush();
                saveStream.Close();
            } catch (IOException)
            {
                return(false);
            }
            return(true);
        }
Beispiel #4
0
        private bool RestoreKeywordPredictor()
        {
            var examplesIn = DataSource.LoadKeywordTrainingExamples();
            var X          = KeywordPredictorTrainingUtils.GenerateKeywordTrainingData(examplesIn);
            var Y          = KeywordPredictorTrainingUtils.GenerateKeywordTargetData(examplesIn);

            KeywordPredictor.Train(X, Y);
            try
            {
                AnsEncoderStream stream = new AnsEncoderStream(
                    new FileStream(DefaultModelFileLocations.NAIVE_BAYES_KEYWORD_PREDICTOR_FILE, FileMode.Create, FileAccess.Write),
                    1048576,
                    4096);
                KeywordPredictor.Save(stream);
                stream.Flush();
                stream.Close();
            } catch (IOException)
            {
                return(false);
            }
            return(true);
        }