private void btnForwardChaining_Click(object sender, EventArgs e)
 {
     try
     {
         var engine = new ProductionInferenceEngine(ProductionRulesConverter.ConvertToRules(txtbxRules.Text));
         var result = engine.ExecuteForwardChaining(txtbxFact.Text, txtbxGoal.Text);
         if (result.HasSolution)
         {
             txtbxSolution.Text = ProductionRulesConverter.ConvertForwardRulesToText(result.Explanation);
         }
         else
         {
             txtbxSolution.Text = "Нет решений";
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 private void btnBackwardChaining_Click(object sender, EventArgs e)
 {
     try
     {
         if (rbProduction.Checked)
         {
             var engine = new ProductionInferenceEngine(ProductionRulesConverter.ConvertToRules(txtbxRules.Text));
             var result = engine.ExecuteBackwardChaining(txtbxFact.Text, txtbxGoal.Text);
             if (result.HasSolution)
             {
                 txtbxSolution.Text = ProductionRulesConverter.ConvertBackwardRulesToText(result.Explanation);
             }
             else
             {
                 txtbxSolution.Text = "Нет решений";
             }
         }
         else if (rbLogic.Checked)
         {
             var engine = new LogicInferenceEngine(LogicRulesLoader.LoadFromFile(txtbxRules.Text));
             var rule   = LogicRulesLoader.ParseRule(txtbxGoal.Text);
             var result = engine.ExecuteBackwardChaining(rule);
             if (result.HasSolution)
             {
                 txtbxSolution.Text = LogicRulesConverter.ConvertToString(result.Explanation);
             }
             else
             {
                 txtbxSolution.Text = "Доказываемое утверждение неверно";
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }