37
This commit is contained in:
		
							parent
							
								
									b63a8fce5f
								
							
						
					
					
						commit
						f4148bde44
					
				| @ -1,6 +0,0 @@ | ||||
| Je to ovocie alebo zelenina? | ||||
| *Jablko | ||||
| *Mrkva | ||||
| 
 | ||||
| a | ||||
| 
 | ||||
| @ -78,7 +78,6 @@ void run_expert_system(Node *node, FILE *input) { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void free_tree(Node *node) { | ||||
|     if (node) { | ||||
|         free_tree(node->yes); | ||||
| @ -87,32 +86,50 @@ void free_tree(Node *node) { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void create_default_knowledge_base() { | ||||
|     FILE *file = fopen("knowledge_base.txt", "w"); | ||||
|     if (!file) { | ||||
|         perror("Failed to create the knowledge base file"); | ||||
|         exit(1); | ||||
|     } | ||||
|     fprintf(file, "Je to ovocie alebo zelenina?\n"); | ||||
|     fprintf(file, "*Jablko\n"); | ||||
|     fprintf(file, "*Mrkva\n"); | ||||
|     fprintf(file, "\n"); // Пустая строка для разделения базы знаний и ответов
 | ||||
|     fprintf(file, "a\n"); // Предустановленный ответ
 | ||||
|     fclose(file); | ||||
| } | ||||
| 
 | ||||
| int main() { | ||||
|     FILE *file = fopen("knowledge_base.txt", "r"); | ||||
|     if (!file) { | ||||
|         perror("Failed to open the knowledge base file"); | ||||
|         return 1; | ||||
|         create_default_knowledge_base();  // Создаем файл по умолчанию
 | ||||
|         file = fopen("knowledge_base.txt", "r"); | ||||
|         if (!file) { | ||||
|             perror("Failed to open the knowledge base file"); | ||||
|             return 1; // Завершение с кодом ошибки, если файл так и не открылся
 | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     Node *root = parse_knowledge_base(file); | ||||
|     if (!root) { | ||||
|         printf("Báza znalostí sa nedá načítať.\n"); | ||||
|         fclose(file); | ||||
|         return 1; | ||||
|         return 1; // Завершение с кодом ошибки, если база знаний не загружена
 | ||||
|     } | ||||
| 
 | ||||
|     printf("Expert z bufetu to vie.\n"); | ||||
|     int product_count = count_products(root); | ||||
|     printf("Pozna %d druhov ovocia a zeleniny.\n", product_count); | ||||
| 
 | ||||
|     // Пропуск пустой строки, которая разделяет базу знаний и ответы
 | ||||
|     // Пропуск пустой строки после базы знаний
 | ||||
|     char line[MAX_LINE_LENGTH]; | ||||
|     while (fgets(line, sizeof(line), file) && line[0] != '\n'); | ||||
| 
 | ||||
|     run_expert_system(root, file); | ||||
|     run_expert_system(root, file); // Запуск системы с использованием оставшихся ответов
 | ||||
| 
 | ||||
|     free_tree(root); | ||||
|     fclose(file); | ||||
|     return 0; | ||||
|     return 0; // Успешное завершение программы
 | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user