Exemple #1
0
        // Display console information for generating a new book.
        public void RenderGenerateBook(InsightFacade insightFacade)
        {
            Console.WriteLine("\nGenerate book after two or more books are trained together.");

            var trainedCollections = RenderListBookCollectionids(insightFacade);

            if (trainedCollections == null)
            {
                Console.WriteLine("\nNo bookCollections added.");
                return;
            }

            Console.WriteLine("\nThe following bookCollections are trained:" + trainedCollections);
            Console.WriteLine("\nWrite the id of the collection you wish to generate a book for. Format: id");

            var id          = Console.ReadLine().Trim();
            var addedColIds = insightFacade.ListBookCollectionNames();

            if (!IdUtil.IdAlreadyAdded(id, addedColIds) || !IdUtil.IsValid(id))
            {
                Console.WriteLine($"Aborting, id: {id} is invalid.");
                return;
            }

            try
            {
                var outputLocation = insightFacade.GenerateBook(id, _maxDepth, _numTrees, _numAdjacentExamples);
                Console.WriteLine($"New book generated at {outputLocation}.");
            }
            catch (Exception e)
            {
                Console.WriteLine($"New book not generated. " + e.Message);
                return;
            }
        }
Exemple #2
0
        // Display console information for listing book collections. Helper for now.
        private string RenderListBookCollectionids(InsightFacade insightFacade)
        {
            var addedBookCollections = insightFacade.ListBookCollectionNames();
            var idString             = new StringBuilder();

            for (int i = 0; i < addedBookCollections.Count - 1; i++)
            {
                idString.Append(addedBookCollections[i] + ", ");
            }

            if (addedBookCollections.Count == 0)
            {
                return(null);
            }

            return(idString.Append(addedBookCollections[addedBookCollections.Count - 1]).ToString());
        }