Example #1
0
        // Display console information for training.
        public void RenderTrainBook(InsightFacade insightFacade)
        {
            Console.WriteLine("\nInput the ids of books to be combined, books must already " +
                              "be added, min 2. Format: id1,id2,...,idN");

            var ids      = Console.ReadLine().Split(",");
            var addedIds = insightFacade.ListBooks();

            foreach (var id in ids)
            {
                if (!IdUtil.IdAlreadyAdded(id, addedIds) || !IdUtil.IsValid(id))
                {
                    Console.WriteLine($"Aborting, id: {id} is invalid.");
                    return;
                }
            }

            Console.WriteLine($"\nA sentence will be displayed, followed by {_numAdjacentExamples} other " +
                              $"sentences. Rank the {_numAdjacentExamples} from best to worst as the next sentence. " +
                              $"Right is best, left is worst.\n");

            try
            {
                insightFacade.TrainModel(ids.ToList(), _numExamplesToClassify, _numAdjacentExamples);
                Console.WriteLine("Model trained.");
            } catch (Exception e)
            {
                Console.WriteLine("Model not trained. " + e.Message);
                return;
            }
        }