Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
剪辑和java问题_Java_Clips - Fatal编程技术网

剪辑和java问题

剪辑和java问题,java,clips,Java,Clips,我在克里普斯尼有一个叫“关于购买割草机的建议”的人工智能项目要做 我有两个.CLP文件:konowledgebase.CLP,control.CLP 和1个java文件:Kosiarki.java knowledgebase.clp: (defrule philips "" (naped ENGINE) (mechanizm TRADYCYJNY) (dodatki KOSZ) (cena DO_500) => (assert(result

我在克里普斯尼有一个叫“关于购买割草机的建议”的人工智能项目要做

我有两个.CLP文件:konowledgebase.CLP,control.CLP 和1个java文件:Kosiarki.java

knowledgebase.clp:

(defrule philips ""
   (naped ENGINE)
   (mechanizm TRADYCYJNY)
   (dodatki KOSZ)
   (cena DO_500)
 =>
   (assert(result
            (producent "Philips")
            (typ "XDD3")
            (rodzaj "spalinowa"))
            (cena "450")))
control.clp:

(deftemplate currentState
   (slot name (default none))
   (slot state (default middle))
   (slot text)      
   (slot answerType (default radioButton))
   (multislot selected)
   (multislot answers)
)

(deftemplate result
   (slot producent (type STRING))
   (slot typ (type STRING))
   (slot rodzaj (type STRING))
   (slot cena (type INTEGER))
)

; Startup window
(defrule system-banner ""
 =>
   (assert (currentState 
      (text START_TEXT)
      (name start)
      (state initial)
      (answers))
   )
)

; Results window
(defrule EndOfQuestions ""
   ?state<-(currentState)
   (end)
 =>
   (retract ?state) 
   (assert (currentState 
      (text NO_RESULTS_END_TEXT)
      (state final)
   ))
)

; Pytanie o powierzchnie
(defrule selectPowierzchnia ""
    ?state<-(currentState)
    (not(pytaniePowierzchnia))
    =>
    (retract ?state) 
    (assert (pytaniePowierzchnia))  
    (assert (currentState
        (name powierzchnia)
        (text SELECT_PYTANIE_POWIERZCHNIA)
        (answerType checkBox)
        (answers 10 20 30 40 50 100 200 300 400 500 1000 2000 3000 4000 5000)
        (selected)
    ))
)

; Pytanie o mechanizm tnacy ====== bezsilnikowy ======
(defrule selectMechanizm ""
    ?state<-(currentState)
    (not(pytanieMechanizm))
    (powierzchnia)
    (naped NOENGINE)
    (naped ELECTRIC)
    =>
    (retract ?state) 
    (assert (pytanieMechanizm)) 
    (assert (currentState
        (name mechanizm)
        (text SELECT_PYTANIE_MECHANIZM)
        (answerType checkBox)
        (answers TRADYCYJNY ROTACYJNY ZYLKOWY WRZECIONOWY BIJAKOWY KARCZUJACY LISTWOWY)
        (selected)
    ))
)

; Pytanie o mechanizm tnacy ====== elektryczny ======
(defrule selectMechanizm ""
    ?state<-(currentState)
    (not(pytanieMechanizm))
    (powierzchnia)
    (naped ELECTRIC)
    (naped ENGINE)
    =>
    (retract ?state) 
    (assert (pytanieMechanizm)) 
    (assert (currentState
        (name mechanizm)
        (text SELECT_PYTANIE_MECHANIZM)
        (answerType checkBox)
        (answers TRADYCYJNY ROTACYJNY ZYLKOWY WRZECIONOWY BIJAKOWY KARCZUJACY LISTWOWY)
        (selected)
    ))
)

; Pytanie o mechanizm tnacy ====== spalinowy ======
(defrule selectMechanizm ""
    ?state<-(currentState)
    (not(pytanieMechanizm))
    (powierzchnia)
    (naped ENGINE)
    =>
    (retract ?state) 
    (assert (pytanieMechanizm)) 
    (assert (currentState
        (name mechanizm)
        (text SELECT_PYTANIE_MECHANIZM)
        (answerType checkBox)
        (answers TRADYCYJNY ROTACYJNY ZYLKOWY WRZECIONOWY BIJAKOWY KARCZUJACY LISTWOWY)
        (selected)
    ))
)

; Pytanie o dodatki
(defrule selectDodatki ""
    ?state<-(currentState)
    (not(pytanieDodatki))
    (mechanizm TRADYCYJNY|ROTACYJNY|ZYLKOWY|WRZECIONOWY|BIJAKOWY|KARCZUJACY|LISTWOWY)
    =>
    (retract ?state) 
    (assert (pytanieDodatki))   
    (assert (currentState
        (name dodatki)
        (text SELECT_PYTANIE_DODATKI)
        (answerType checkBox)
        (answers MULCZOWANIE KOSZ TARCZA ROZRUSZNIK BLOKADA NAPED NIE)
        (selected)
    ))
)

; Pytanie o cene
(defrule selectCena ""
    ?state<-(currentState)
    (not(pytanieCena))
    (dodatki MULCZOWANIE|KOSZ|TARCZA|ROZRUSZNIK|BLOKADA|NAPED)
    =>
    (retract ?state)
    (assert (PytanieCena))
    (assert (currentState
        (name cena)
        (text SELECT_PYTANIE_CENA)
        (answerType checkBox)
        (answers 10 20 30 40 50 100 200 300 400 500 1000 2000 3000 4000 5000)
        (selected)
    ))
    (assert (end))
)

(defrule suma_pow_init
   ?i<-(powierzchnia ?p $?rp)
   (not(suma_pow ?))
 =>
   (retract ?i)
   (assert(powierzchnia $?rp))
   (assert(suma_pow ?p)))

(defrule sumuj
   ?i<-(powierzchnia ?p $?rp)
   ?j<-(suma_pow ?s $?rs)
 =>
   (retract ?i ?j)
   (assert(powierzchnia $?rp))
   (assert(suma_pow (+ ?p ?s))))

(defrule nast_pyt_pow1
   (powierzchnia)
   (suma_pow ?s)
   (test(< ?s 150))
 =>
   (assert(naped NOENGINE))
   (assert(naped ELECTRIC)))

(defrule nast_pyt_pow2
   (powierzchnia)
   (suma_pow ?s)
   (test(>= ?s 150))
   (test(< ?s 750))
 =>
   (assert(naped ELECTRIC))
   (assert(naped ENGINE)))

(defrule nast_pyt_pow3
   (powierzchnia)
   (suma_pow ?s)
   (test(< ?s 750))
 =>
   (assert(naped ENGINE)))

(defrule suma_cen_init
   ?i<-(cena ?c $?rc)
   (not(suma_cen ?))
 =>
   (retract ?i)
   (assert(cena $?rc))
   (assert(suma_cen ?c)))

(defrule sumuj_ceny
   ?i<-(cena ?c $?rc)
   ?j<-(suma_cen ?s $?rs)
 =>
   (retract ?i ?j)
   (assert(cena $?rc))
   (assert(suma_cen (+ ?c ?s))))

(defrule nast_pyt_cena1
   (cena)
   (suma_cen ?s)
   (test(< ?s 450))
 =>
   (assert(cena MALA)))

(defrule nast_pyt_cena1
   (cena)
   (suma_cen ?s)
   (test(< ?s 500))
   (test(>= ?s 450))
 =>
   (assert(cena DO_500)))

(defrule nast_pyt_cena2
   (cena)
   (suma_cen ?s)
   (test(>= ?s 500))
   (test(< ?s 750))
 =>
   (assert(cena DO_750)))

(defrule nast_pyt_cena3
   (cena)
   (suma_cen ?s)
   (test(>= ?s 750))
   (test(< ?s 1500))
 =>
   (assert(cena DO_1500)))

(defrule nast_pyt_cena4
   (cena)
   (suma_cen ?s)
   (test(>= ?s 1500))
   (test(< ?s 3000))
 =>
   (assert(cena DO_3000)))

(defrule nast_pyt_cena5
   (cena)
   (suma_cen ?s)
   (test(>= ?s 3000))
   (test(< ?s 5000))
 =>
   (assert(cena DO_5000)))

(defrule nast_pyt_cena6
   (cena)
   (suma_cen ?s)
   (test(>= ?s 5000))
   (test(< ?s 10000))
 =>
   (assert(cena DO_10000)))

(defrule nast_pyt_cena7
   (cena)
   (suma_cen ?s)
   (test(>= ?s 10000))
 =>
   (assert(cena OD_10000)))
(deftemplate currentState
   (slot name (default none))
   (slot state (default middle))
   (slot text)      
   (slot answerType (default radioButton))
   (multislot selected)
   (multislot answers)
)

(deftemplate result
   (slot producent (type STRING))
   (slot typ (type STRING))
   (slot rodzaj (type STRING))
   (slot cena1 (type INTEGER))
)

; Startup window
(defrule system-banner ""
 =>
   (assert (currentState 
      (text START_TEXT)
      (name start)
      (state initial)
      (answers))
   )
)

; Results window
(defrule EndOfQuestions ""
   ?state<-(currentState)
   (end)
 =>
   (retract ?state) 
   (assert (currentState 
      (text NO_RESULTS_END_TEXT)
      (state final)
   ))
)

; Pytanie o powierzchnie
(defrule selectPowierzchnia ""
   ?state<-(currentState)
    (start)
   (not(pytaniePowierzchnia))
   =>
   (retract ?state) 
   (assert (pytaniePowierzchnia))   
   (assert (currentState
      (name powierzchnia)
      (text SELECT_PYTANIE_POWIERZCHNIA)
      (answerType checkBox)
      (answers 10 20 30 40 50 100 200 300 400 500 1000 2000 3000 4000 5000)
      (selected )
   ))
)

; Pytanie o mechanizm tnacy ====== bezsilnikowy ======
(defrule selectMechanizm ""
   ?state<-(currentState)
   (not(pytanieMechanizm))
   (not(powierzchnia ?))
   (naped NOENGINE)
   (naped ELECTRIC)
   =>
   (retract ?state) 
   (assert (pytanieMechanizm))   
   (assert (currentState
      (name mechanizm)
      (text SELECT_PYTANIE_MECHANIZM)
      (answerType checkBox)
      (answers TRADYCYJNY ROTACYJNY ZYLKOWY WRZECIONOWY BIJAKOWY KARCZUJACY LISTWOWY)
      (selected)
   ))
)

; Pytanie o mechanizm tnacy ====== elektryczny ======
(defrule selectMechanizm ""
   ?state<-(currentState)
   (not(pytanieMechanizm))
   (not(powierzchnia ?))
   (naped ELECTRIC)
   (naped ENGINE)
   =>
   (retract ?state) 
   (assert (pytanieMechanizm))   
   (assert (currentState
      (name mechanizm)
      (text SELECT_PYTANIE_MECHANIZM)
      (answerType checkBox)
      (answers TRADYCYJNY ROTACYJNY ZYLKOWY WRZECIONOWY BIJAKOWY KARCZUJACY LISTWOWY)
      (selected)
   ))
)

; Pytanie o mechanizm tnacy ====== spalinowy ======
(defrule selectMechanizm ""
   ?state<-(currentState)
   (not(pytanieMechanizm))
   (not(powierzchnia ?))
   (naped ENGINE)
   =>
   (retract ?state) 
   (assert (pytanieMechanizm))   
   (assert (currentState
      (name mechanizm)
      (text SELECT_PYTANIE_MECHANIZM)
      (answerType checkBox)
      (answers TRADYCYJNY ROTACYJNY ZYLKOWY WRZECIONOWY BIJAKOWY KARCZUJACY LISTWOWY)
      (selected)
   ))
)

; Pytanie o dodatki
(defrule selectDodatki ""
   ?state<-(currentState)
   (not(pytanieDodatki))
   (mechanizm TRADYCYJNY|ROTACYJNY|ZYLKOWY|WRZECIONOWY|BIJAKOWY|KARCZUJACY|LISTWOWY)  ;;;;;
   =>
   (retract ?state) 
   (assert (pytanieDodatki))   
   (assert (currentState
      (name dodatki)
      (text SELECT_PYTANIE_DODATKI)
      (answerType checkBox)
      (answers MULCZOWANIE KOSZ TARCZA ROZRUSZNIK BLOKADA NAPED NIE)
      (selected)
   ))
)

; Pytanie o cene
(defrule selectCena ""
   ?state<-(currentState)
   (not(pytanieCena))
   (dodatki MULCZOWANIE|KOSZ|TARCZA|ROZRUSZNIK|BLOKADA|NAPED|NIE)
   =>
   (retract ?state)
   (assert (PytanieCena))
   (assert (currentState
      (name cena)
      (text SELECT_PYTANIE_CENA)
      (answerType checkBox)
      (answers 10 20 30 40 50 100 200 300 400 500 1000 2000 3000 4000 5000)
      (selected)
   ))
   ;(assert (end))
)

(defrule suma_pow_init
   ?i<-(powierzchnia ?p)
   (not(suma_pow ?))
 =>
   (retract ?i)
   (assert(suma_pow ?p)))

(defrule sumuj_pow
   ?i<-(powierzchnia ?p)
   ?j<-(suma_pow ?s)
 =>
   (retract ?i ?j)
   (assert(suma_pow (+ ?p ?s))))

(defrule nast_pyt_pow1
   (not(powierzchnia ?))
   (suma_pow ?s)
   (test(< ?s 150))
 =>
   (assert(naped NOENGINE))
   (assert(naped ELECTRIC)))

(defrule nast_pyt_pow2
   (not(powierzchnia ?))
   (suma_pow ?s)
   (test(>= ?s 150))
   (test(< ?s 750))
 =>
   (assert(naped ELECTRIC))
   (assert(naped ENGINE)))

(defrule nast_pyt_pow3
   (not(powierzchnia ?))
   (suma_pow ?s)
   (test(> ?s 750))
 =>
   (assert(naped ENGINE)))

(defrule suma_cen_init
   ?i<-(cena ?c)
   (not(suma_cen ?))
 =>
   (retract ?i)
   (assert(suma_cen ?c)))

(defrule sumuj_ceny
   ?i<-(cena ?c)
   ?j<-(suma_cen ?s)
 =>
   (retract ?i ?j)
   (assert(suma_cen (+ ?s ?c))))

(defrule nast_pyt_cena1
   (not(cena ?))
   (suma_cen ?s)
   (test(>= ?s 450))
   (test(< ?s 500))
 =>
   (assert(cena DO_500))
   (assert (end)))

(defrule nast_pyt_cena2
   (not(cena ?))
   (suma_cen ?s)
   (test(>= ?s 500))
   (test(< ?s 750))
 =>
   (assert(cena DO_750))
   (assert (end)))

(defrule nast_pyt_cena3
   (not(cena ?))
   (suma_cen ?s)
   (test(>= ?s 750))
   (test(< ?s 1500))
 =>
   (assert(cena DO_1500))
   (assert (end)))

(defrule nast_pyt_cena4
   (not(cena ?))
   (suma_cen ?s)
   (test(>= ?s 1500))
   (test(< ?s 3000))
 =>
   (assert(cena DO_3000))
   (assert (end)))

(defrule nast_pyt_cena5
   (not(cena ?))
   (suma_cen ?s)
   (test(>= ?s 3000))
   (test(< ?s 5000))
 =>
   (assert(cena DO_5000))
   (assert (end)))

(defrule nast_pyt_cena6
   (not(cena ?))
   (suma_cen ?s)
   (test(>= ?s 5000))
   (test(< ?s 10000))
 =>
   (assert(cena DO_10000))
   (assert (end)))

(defrule nast_pyt_cena7
   (not(cena ?))
   (suma_cen ?s)
   (test(>= ?s 10000))
 =>
   (assert(cena OD_10000))
   (assert (end)))
(deftemplate currentState
(插槽名称(默认无))
(插槽状态(默认中间))
(插槽文本)
(插槽应答类型(默认单选按钮))
(选择多批次)
(多批次答案)
)
(d)模板结果
(槽产品(类型字符串))
(插槽类型(类型字符串))
(插槽rodzaj(类型字符串))
(插槽cena(整型))
)
; 启动窗口
(defrule系统横幅“”
=>
(断言(当前状态)
(文本开始\文本)
(名称开始)
(国家首字母)
(答复)
)
)
; 结果窗口
(defrule EndOfQuestions“”
?国家
(收回?状态)
(断言(当前状态)
(文本否\u结果\u结束\u文本)
(州决赛)
))
)
; 皮塔尼·奥波维耶什尼
(defrule SelectPovierzchnia“”
?国家
(收回?状态)
(断言(pytaniePowierzchnia))
(断言(当前状态)
(姓名:Povierzchnia)
(文本选择_PYTANIE_povierzchnia)
(应答类型复选框)
(答案1020300405001002030050000004000000)
(选定)
))
)
; Pytanie o mechanizm tnacy===========贝西尔尼科维======
(defrule selectMechanizm“”
?国家
(收回?状态)
(断言(pytanieMechanizm))
(断言(当前状态)
(名称:mechanizm)
(文本选择_PYTANIE_MECHANIZM)
(应答类型复选框)
(回答传统的ROTACYJNY ZYLKOWY WRZECIONOWY BIJAKOWY KARCZUJACY LISTWOWY)
(选定)
))
)
; Pytanie o mechanizm tnacy===========elektryczny======
(defrule selectMechanizm“”
?国家
(收回?状态)
(断言(pytanieMechanizm))
(断言(当前状态)
(名称:mechanizm)
(文本选择_PYTANIE_MECHANIZM)
(应答类型复选框)
(回答传统的ROTACYJNY ZYLKOWY WRZECIONOWY BIJAKOWY KARCZUJACY LISTWOWY)
(选定)
))
)
; Pytanie o mechanizm tnacy===斯帕利诺维======
(defrule selectMechanizm“”
?国家
(收回?状态)
(断言(pytanieMechanizm))
(断言(当前状态)
(名称:mechanizm)
(文本选择_PYTANIE_MECHANIZM)
(应答类型复选框)
(回答传统的ROTACYJNY ZYLKOWY WRZECIONOWY BIJAKOWY KARCZUJACY LISTWOWY)
(选定)
))
)
; 皮塔尼·奥多达斯基
(defrule selectDodatki“”
?国家
(收回?状态)
(断言(pytanieDodatki))
(断言(当前状态)
(姓名多达基)
(文本选择_PYTANIE_DODATKI)
(应答类型复选框)
(穆尔佐瓦尼·科兹·塔尔扎·罗兹鲁兹尼克·布罗卡达·纳佩德·涅的回答)
(选定)
))
)
; Pytanie o cene
(defrule selectCena“”
?国家
(收回?状态)
(断言(Pytanicena))
(断言(当前状态)
(名称cena)
(文本选择_PYTANIE_CENA)
(应答类型复选框)
(答案1020300405001002030050000004000000)
(选定)
))
(完)
)
(定义suma_pow_init)
我
(收回?i)
(资产(Povierzchnia$?卢比))
(assert(suma_pow?p)))
(defrule sumuj)
我
(断言(Napped NOENGINE))
(断言(Napped ELECTRIC)))
(第2条
(Povierzchnia)
(苏玛波)
(测试(>=?s 150))
(试验(<?s 750))
=>
(断言(Napped ELECTRIC))
(断言(naped引擎)))
(第3条
(Povierzchnia)
(苏玛波)
(试验(<?s 750))
=>
(断言(naped引擎)))
(定义suma_cen_init)
我
(收回?i)
(断言(cena$?rc))
(断言(suma_cen?c)))
(定义sumuj_ceny)
我
(断言(塞纳马拉)))
(定义nast_pyt_cena1)
(欧洲标准化委员会)
(苏马南)
(试验(<?s 500))
(测试(>=?s 450))
=>
(断言(cena DO_500)))
(第2部分)
(欧洲标准化委员会)
(苏马南)
(测试(>=?s 500))
(试验(<?s 750))
=>
(断言(cena DO_750)))
(修订nast_pyt_cena3)
(欧洲标准化委员会)
(苏马南)
(测试(>=?s 750))
(试验(<?s 1500))
=>
(断言(cena DO_1500)))
(定义nast_pyt_cena4)
(欧洲标准化委员会)
(苏马南)
(测试(>=?s 1500))
(测试(<?s 3000))
=>
(断言(cena DO_3000)))
(国家法律委员会第五次会议)
(欧洲标准化委员会)
(苏马南)
(测试(>=?s 3000))
(试验(<?s 5000))
=>
(断言(cena DO_5000)))
(国家标准化委员会6
(欧洲标准化委员会)
(苏马南)
(测试(>=?s 5000))
(测试(<?s 10000))
=>
(断言(cena DO_10000)))
(参见国家标准化委员会第7条)
(欧洲标准化委员会)
(苏马南)
(测试(>=?s 10000))
=>
(断言(cena OD_10000)))
Kosiarki.java:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.*;
import java.util.List;
import java.util.Properties;

import javax.swing.SwingUtilities;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JCheckBox;
import javax.swing.JTextPane;
import javax.swing.JToggleButton;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

import CLIPSJNI.Environment;
import CLIPSJNI.FactAddressValue;
import CLIPSJNI.MultifieldValue;
import CLIPSJNI.PrimitiveValue;
import CLIPSJNI.SymbolValue;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.util.Comparator;
import javax.swing.table.TableColumn;

public class Kosiarki implements ActionListener
{
 private Environment clips;
 private Properties properties;
 private ButtonGroup answerButtons;
 private JTextPane textPane;
 private JButton nextButton;
 private JPanel answerPanel;
 private JTable answersTable;
 private String assertedKosiarka;
 private String lastAssertedKosiarka="";

 public Kosiarki()
 {
  // okno
  JFrame frame=new JFrame("AI Name Project");
  frame.getContentPane().setLayout(new GridLayout(3, 1));
  frame.setSize(500, 300);
  frame.setLocationByPlatform(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  // panel - piewszy wiersz tableli 1x3 - do wyswietlania tekstow(glownie pytan)
  JPanel textPanel=new JPanel();
  textPane=new JTextPane();
  textPane.setOpaque(false);
  textPane.setEditable(false);

  StyledDocument doc=textPane.getStyledDocument();
  SimpleAttributeSet center=new SimpleAttributeSet();
  StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
  doc.setParagraphAttributes(0, doc.getLength(), center, false);

  textPanel.add(textPane);

  // panel - drugi wiersz tableli 1x3 - do wyswietlania checkboksow i radiobuttonow
  answerPanel=new JPanel();
  answerButtons=new ButtonGroup();

  // panel - trzeci i ostatni wiersz tableli 1x3 - do wyswietlania przycisku "next"
  JPanel nextButtonPanel=new JPanel();
  nextButton=new JButton();
  nextButton.setActionCommand("next");
  nextButtonPanel.add(nextButton);
  nextButton.addActionListener(this);

  // wstawiamy na okno wszystkie trzy panele
  frame.getContentPane().add(textPanel);
  frame.getContentPane().add(answerPanel);
  frame.getContentPane().add(nextButtonPanel);
  frame.setVisible(true);

  // inicjalizacja CLIPS-a
  clips=new Environment();
  clips.load("control.clp");
  clips.load("knowledgeBase.clp");
  clips.reset();
  clips.run(1);

  // ititializing file with properties
  properties=new Properties();
  loadProperties(new File("configuration.properties"));

  // w praktyce pokazujemy okno wstepne
  nextUIState();
 }

 private void nextUIState()
 {
  answerPanel.removeAll();

  // pobieramy aktualny stan UI
  MultifieldValue currentStateMultifieldValue=(MultifieldValue)clips.eval("(find-all-facts((?f currentState))TRUE)");
  List<FactAddressValue> currentStateList=currentStateMultifieldValue.listValue();
  if(currentStateList.isEmpty())
  {
   return;
  }
  FactAddressValue currentState=currentStateList.get(0);

  // sprawdzamy czy nie "zablokowalismy" sie na "name"
  assertedKosiarka=currentState.getFactSlot("name").toString();
  if(assertedKosiarka.contentEquals(lastAssertedKosiarka))
  {
   clips.run(1);
   nextUIState();
   return;
  }
  lastAssertedKosiarka=assertedKosiarka;

  // ustawienie nazw przycisku "next"/"restart"/"start"
  if(currentState.getFactSlot("state").toString().equals("final"))
  {
   nextButton.setActionCommand("restart");
   nextButton.setText(properties.getProperty("RESTART").toString());

   // Dodatkowo wypisywanie wynikow
   MultifieldValue namesMultifieldValue=(MultifieldValue)clips.eval("(find-all-facts((?f result))TRUE)");
   List<FactAddressValue> nameList=namesMultifieldValue.listValue();

   if(!nameList.isEmpty())
   {
    textPane.setText(properties.getProperty("RESULTS_END_TEXT").toString());
    System.out.println("pasujące kosiarki:");

    String headers[]={
      properties.getProperty("PRODUCENT"),
      properties.getProperty("TYP"),
      properties.getProperty("RODZAJ"),
      properties.getProperty("CENA")};

    ArrayList<Result> resultList=new ArrayList<Result>();
    for(FactAddressValue name : nameList)
    {
     resultList.add(new Result(
       name.getFactSlot("producent").getValue().toString(),
       name.getFactSlot("typ").getValue().toString(),
       name.getFactSlot("rodzaj").getValue().toString(),
       name.getFactSlot("cena").getValue().toString()));
    }

    Collections.sort(resultList, new ResultComperator());

    String data[][]=new String[nameList.size()][4];
    int i=0;
    for(Result result : resultList)
    {
     data[i][0]=properties.getProperty(result.getProducent());
     data[i][1]=result.getTyp();
     data[i][2]=result.getRodzaj();
     data[i][3]=result.getCena();

     String newName=data[i][0] + "(" + data[i][1] + ")";
     System.out.println(newName);

     i++;
    }

    answersTable=new JTable(data, headers);
    answersTable.setPreferredScrollableViewportSize(new Dimension(answerPanel.getWidth()- 25, answerPanel.getHeight()- 25));
    answersTable.getTableHeader().setReorderingAllowed(false);
    answersTable.setEnabled(false);

    TableColumn column=new TableColumn();
    column=answersTable.getColumnModel().getColumn(0);
    column.setMaxWidth(100);

    JScrollPane scrollPane=new JScrollPane(answersTable);

    answerPanel.add(scrollPane);
   }
   else
   {
    textPane.setText(properties.getProperty("NO_RESULTS_END_TEXT").toString());
   }

   answerPanel.repaint();
   return;
  }
  else if(currentState.getFactSlot("state").toString().equals("initial"))
  {
   nextButton.setActionCommand("start");
   nextButton.setText(properties.getProperty("START").toString());
  }
  else
  {
   nextButton.setActionCommand("next");
   nextButton.setText(properties.getProperty("NEXT").toString());
  }

  // ustawienie tekstu(np. pytania)
  String text=((SymbolValue)currentState.getFactSlot("text")).stringValue();
  textPane.setText(properties.getProperty(text).toString());

  // Wstawiamy przyciski(comboboksy/radioboksy)
  boolean checkboxes=false;
  if(currentState.getFactSlot("answerType").toString().equals("checkBox"))
  {
   checkboxes=true;
  }

  answerPanel.removeAll();
  answerButtons=!checkboxes ? new ButtonGroup(): null;

  MultifieldValue answersMultifieldValue=(MultifieldValue)currentState.getFactSlot("answers");
  List<PrimitiveValue> answersList=answersMultifieldValue.listValue();

  for(PrimitiveValue answer : answersList)
  {
   JToggleButton button;
   if(checkboxes)
   {
    button=new JCheckBox(properties.getProperty(answer.toString()).toString(), false);
   }
   else
   {
    button=new JRadioButton(properties.getProperty(answer.toString()).toString(), false);
   }

   // zaznaczanie domyslnie aktywnych przyciskow
   MultifieldValue selectedMultifieldValue=(MultifieldValue)currentState.getFactSlot("selected");
   List<PrimitiveValue> selectedList=selectedMultifieldValue.listValue();
   for(PrimitiveValue selected : selectedList)
   {
    if(answer.toString().equals(selected.toString()))
    {
     button.setSelected(true);
     break;
    }
   }

   button.setActionCommand(answer.toString());
   answerPanel.add(button);

   if(!checkboxes)
   {
    answerButtons.add(button);
   }
  }

  answerPanel.repaint();
 }

 @Override
 public void actionPerformed(ActionEvent event)
 {
  // po kliknieciu przycisku "next" dodawane sa fakty do CLIPS-a
  if(event.getActionCommand().equals("next"))
  {
   for(Component component : answerPanel.getComponents())
   {
    if(component instanceof JToggleButton)
    {
     JToggleButton button=(JToggleButton)component;
     if(button.isSelected())
     {
      String toAssert="(" + assertedKosiarka + " " + button.getActionCommand()+ ")";
      clips.assertString(toAssert);
      System.out.println(toAssert);
     }
    }
   }

   clips.run(1);
   nextUIState();
   return;
  }

  // po kliknieciu przycisku "start"
  if(event.getActionCommand().equals("start"))
  {
   clips.assertString("(start)");
   System.out.println("(start)");

   clips.run(1);
   nextUIState();
   return;
  }

  // po kliknieciu przycisku "restart" resetujemy srodowisko CLIPS-a
  if(event.getActionCommand().equals("restart"))
  {
   clips.reset();
   System.out.println("clips.reset");

   clips.run(1);
   nextUIState();
   return;
  }
 }

 private void loadProperties(File propertiesFile)
 {
  InputStream is;
  try
  {
   is=new FileInputStream(propertiesFile);
   properties.load(is);
  }
  catch(FileNotFoundException e)
  {
   System.out.println("Cannot find configuration file.");
  }
  catch(IOException e)
  {
   System.out.println("Some problems with configuration file.");
  }
 }

 public static void main(String[] args)
 {
  SwingUtilities.invokeLater(
   new Runnable()
   {
    public void run()
    {
     new Kosiarki();
    }
   }
  );
 }

}

class Result
{
 private String producent;
 private String typ;
 private String rodzaj;
 private String cena;

 public String getProducent()
 {
  return producent;
 }

 public void setProducent(String producent)
 {
  this.producent=producent;
 }

 public String getTyp()
 {
  return typ;
 }

 public void setTyp(String typ)
 {
  this.typ=typ;
 }

 public String getRodzaj()
 {
  return rodzaj;
 }

 public void setRodzaj(String rodzaj)
 {
  this.rodzaj=rodzaj;
 }

 public String getCena()
 {
  return cena;
 }

 public void setCena(String cena)
 {
  this.cena=cena;
 }


 public Result()
 {
 }

 public Result(String producent, String typ, String rodzaj, String cena)
 {
  this.producent=producent;
  this.typ=typ;
  this.rodzaj=rodzaj;
  this.cena=cena;
 }

}

class ResultComperator implements Comparator<Result>
{
 public int compare(Result o1, Result o2)
 {
  return o1.getProducent().compareTo(o2.getProducent());
 }

}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.*;
import java.util.List;
import java.util.Properties;

import javax.swing.SwingUtilities;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JCheckBox;
import javax.swing.JTextPane;
import javax.swing.JToggleButton;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

import CLIPSJNI.Environment;
import CLIPSJNI.FactAddressValue;
import CLIPSJNI.MultifieldValue;
import CLIPSJNI.PrimitiveValue;
import CLIPSJNI.SymbolValue;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.util.Comparator;
import javax.swing.table.TableColumn;

public class Kosiarki implements ActionListener
{
 private Environment clips;
 private Properties properties;
 private ButtonGroup answerButtons;
 private JTextPane textPane;
 private JButton nextButton;
 private JPanel answerPanel;
 private JTable answersTable;
 private String assertedKosiarka;
 private String lastAssertedKosiarka="";

 public Kosiarki()
 {
  // okno
  JFrame frame=new JFrame("AI Name Project");
  frame.getContentPane().setLayout(new GridLayout(3, 1));
  frame.setSize(500, 300);
  frame.setLocationByPlatform(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  // panel - piewszy wiersz tableli 1x3 - do wyswietlania tekstow(glownie pytan)
  JPanel textPanel=new JPanel();
  textPane=new JTextPane();
  textPane.setOpaque(false);
  textPane.setEditable(false);

  StyledDocument doc=textPane.getStyledDocument();
  SimpleAttributeSet center=new SimpleAttributeSet();
  StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
  doc.setParagraphAttributes(0, doc.getLength(), center, false);

  textPanel.add(textPane);

  // panel - drugi wiersz tableli 1x3 - do wyswietlania checkboksow i radiobuttonow
  answerPanel=new JPanel();
  answerButtons=new ButtonGroup();

  // panel - trzeci i ostatni wiersz tableli 1x3 - do wyswietlania przycisku "next"
  JPanel nextButtonPanel=new JPanel();
  nextButton=new JButton();
  nextButton.setActionCommand("next");
  nextButtonPanel.add(nextButton);
  nextButton.addActionListener(this);

  // wstawiamy na okno wszystkie trzy panele
  frame.getContentPane().add(textPanel);
  frame.getContentPane().add(answerPanel);
  frame.getContentPane().add(nextButtonPanel);
  frame.setVisible(true);

  // inicjalizacja CLIPS-a
  clips=new Environment();
  clips.load("control.clp");
  clips.load("knowledgeBase.clp");
  clips.reset();
  clips.run(1);

  // ititializing file with properties
  properties=new Properties();
  loadProperties(new File("configuration.properties"));

  // w praktyce pokazujemy okno wstepne
  nextUIState();
 }

 private void nextUIState()
 {
  answerPanel.removeAll();

  // pobieramy aktualny stan UI
  MultifieldValue currentStateMultifieldValue=(MultifieldValue)clips.eval("(find-all-facts((?f currentState))TRUE)");
  List<FactAddressValue> currentStateList=currentStateMultifieldValue.listValue();
  if(currentStateList.isEmpty())
  {
   return;
  }
  FactAddressValue currentState=currentStateList.get(0);

  // sprawdzamy czy nie "zablokowalismy" sie na "name"
  assertedKosiarka=currentState.getFactSlot("name").toString();
  if(assertedKosiarka.contentEquals(lastAssertedKosiarka))
  {
   clips.run(1);
   nextUIState();
   return;
  }
  lastAssertedKosiarka=assertedKosiarka;

  // ustawienie nazw przycisku "next"/"restart"/"start"
  if(currentState.getFactSlot("state").toString().equals("final"))
  {
   nextButton.setActionCommand("restart");
   nextButton.setText(properties.getProperty("RESTART").toString());

   // Dodatkowo wypisywanie wynikow
   MultifieldValue namesMultifieldValue=(MultifieldValue)clips.eval("(find-all-facts((?f result))TRUE)");
   List<FactAddressValue> nameList=namesMultifieldValue.listValue();

   if(!nameList.isEmpty())
   {
    textPane.setText(properties.getProperty("RESULTS_END_TEXT").toString());
    System.out.println("pasujące kosiarki:");

    String headers[]={
      properties.getProperty("PRODUCENT"),
      properties.getProperty("TYP"),
      properties.getProperty("RODZAJ"),
      properties.getProperty("CENA")};

    ArrayList<Result> resultList=new ArrayList<Result>();
    for(FactAddressValue name : nameList)
    {
     resultList.add(new Result(
       name.getFactSlot("producent").getValue().toString(),
       name.getFactSlot("typ").getValue().toString(),
       name.getFactSlot("rodzaj").getValue().toString(),
       name.getFactSlot("cena1").getValue().toString()));
    }

    Collections.sort(resultList, new ResultComperator());

    String data[][]=new String[nameList.size()][4];
    int i=0;
    for(Result result : resultList)
    {
     data[i][0]=properties.getProperty(result.getProducent());
     data[i][1]=result.getTyp();
     data[i][2]=result.getRodzaj();
     data[i][3]=result.getCena();

     String newKosiarka=data[i][0] + "(" + data[i][1] + ")";
     System.out.println(newKosiarka);

     i++;
    }

    answersTable=new JTable(data, headers);
    answersTable.setPreferredScrollableViewportSize(new Dimension(answerPanel.getWidth()- 25, answerPanel.getHeight()- 25));
    answersTable.getTableHeader().setReorderingAllowed(false);
    answersTable.setEnabled(false);

    TableColumn column=new TableColumn();
    column=answersTable.getColumnModel().getColumn(0);
    column.setMaxWidth(100);

    JScrollPane scrollPane=new JScrollPane(answersTable);

    answerPanel.add(scrollPane);
   }
   else
   {
    textPane.setText(properties.getProperty("NO_RESULTS_END_TEXT").toString());
   }

   answerPanel.repaint();
   return;
  }
  else if(currentState.getFactSlot("state").toString().equals("initial"))
  {
   nextButton.setActionCommand("start");
   nextButton.setText(properties.getProperty("START").toString());
  }
  else
  {
   nextButton.setActionCommand("next");
   nextButton.setText(properties.getProperty("NEXT").toString());
  }

  // ustawienie tekstu(np. pytania)
  String text=((SymbolValue)currentState.getFactSlot("text")).stringValue();
  textPane.setText(properties.getProperty(text).toString());

  // Wstawiamy przyciski(comboboksy/radioboksy)
  boolean checkboxes=false;
  if(currentState.getFactSlot("answerType").toString().equals("checkBox"))
  {
   checkboxes=true;
  }

  answerPanel.removeAll();
  answerButtons=!checkboxes ? new ButtonGroup(): null;

  MultifieldValue answersMultifieldValue=(MultifieldValue)currentState.getFactSlot("answers");
  List<PrimitiveValue> answersList=answersMultifieldValue.listValue();

  for(PrimitiveValue answer : answersList)
  {
   JToggleButton button;
   if(checkboxes)
   {
    button=new JCheckBox(properties.getProperty(answer.toString()).toString(), false);
   }
   else
   {
    button=new JRadioButton(properties.getProperty(answer.toString()).toString(), false);
   }

   // zaznaczanie domyslnie aktywnych przyciskow
   MultifieldValue selectedMultifieldValue=(MultifieldValue)currentState.getFactSlot("selected");
   List<PrimitiveValue> selectedList=selectedMultifieldValue.listValue();
   for(PrimitiveValue selected : selectedList)
   {
    if(answer.toString().equals(selected.toString()))
    {
     button.setSelected(true);
     break;
    }
   }

   button.setActionCommand(answer.toString());
   answerPanel.add(button);

   if(!checkboxes)
   {
    answerButtons.add(button);
   }
  }

  answerPanel.repaint();
 }

 @Override
 public void actionPerformed(ActionEvent event)
 {
  // po kliknieciu przycisku "next" dodawane sa fakty do CLIPS-a
  if(event.getActionCommand().equals("next"))
  {
   for(Component component : answerPanel.getComponents())
   {
    if(component instanceof JToggleButton)
    {
     JToggleButton button=(JToggleButton)component;
     if(button.isSelected())
     {
      String toAssert="(" + assertedKosiarka + " " + button.getActionCommand()+ ")";
      clips.assertString(toAssert);
      System.out.println(toAssert);
     }
    }
   }

   clips.run(1);
   nextUIState();
   return;
  }

  // po kliknieciu przycisku "start"
  if(event.getActionCommand().equals("start"))
  {
   clips.assertString("(start)");
   System.out.println("(start)");

   clips.run(1);
   nextUIState();
   return;
  }

  // po kliknieciu przycisku "restart" resetujemy srodowisko CLIPS-a
  if(event.getActionCommand().equals("restart"))
  {
   clips.reset();
   System.out.println("clips.reset");

   clips.run(1);
   nextUIState();
   return;
  }
 }

 private void loadProperties(File propertiesFile)
 {
  InputStream is;
  try
  {
   is=new FileInputStream(propertiesFile);
   properties.load(is);
  }
  catch(FileNotFoundException e)
  {
   System.out.println("Cannot find configuration file.");
  }
  catch(IOException e)
  {
   System.out.println("Some problems with configuration file.");
  }
 }

 public static void main(String[] args)
 {
  SwingUtilities.invokeLater(
   new Runnable()
   {
    public void run()
    {
     new Kosiarki();
    }
   }
  );
 }

}

class Result
{
 private String producent;
 private String typ;
 private String rodzaj;
 private String cena1;

 public String getProducent()
 {
  return producent;
 }

 public void setProducent(String producent)
 {
  this.producent=producent;
 }

 public String getTyp()
 {
  return typ;
 }

 public void setTyp(String typ)
 {
  this.typ=typ;
 }

 public String getRodzaj()
 {
  return rodzaj;
 }

 public void setRodzaj(String rodzaj)
 {
  this.rodzaj=rodzaj;
 }

 public String getCena()
 {
  return cena1;
 }

 public void setCena(String cena1)
 {
  this.cena1=cena1;
 }


 public Result()
 {
 }

 public Result(String producent, String typ, String rodzaj, String cena1)
 {
  this.producent=producent;
  this.typ=typ;
  this.rodzaj=rodzaj;
  this.cena1=cena1;
 }

}

class ResultComperator implements Comparator<Result>
{
 public int compare(Result o1, Result o2)
 {
  return o1.getProducent().compareTo(o2.getProducent());
 }

}
导入java.io.File;
导入java.io.FileInputStream;
导入java.io.FileNotFoundException;
导入java.io.IOException;
导入java.io.InputStream;
导入java.awt.Component;
导入java.awt.GridLayout;
导入java.awt.event.*;
导入java.util.List;
导入java.util.Properties;
导入javax.swing.SwingUtilities;
导入javax.swing.ButtonGroup;
导入javax.swing.JButton;
导入javax.swing.JFrame;
导入javax.swing.JPanel;
导入javax.swing.JRadioButton;
导入javax.swing.JCheckBox;
导入javax.swing.JTextPane;
导入javax.swing.JToggleButton;
导入javax.swing.text.SimpleAttributeSet;
导入javax.swing.text.StyleConstants;
导入javax.swing.text.StyledDocument;
导入CLIPSJNI.Environment;
导入CLIPSJNI.FactAddressValue;
导入CLIPSJNI.multifiedvalue;
导入CLIPSJNI.PrimitiveValue;
导入CLIPSJNI.SymbolValue;
导入java.awt.Dimension;
导入java.util.ArrayList;
导入java.util.Collections;
导入javax.swing.JScrollPane;
导入javax.swing.JTable;
导入java.util.Comparator;
导入javax.swing.table.TableColumn;
公共类Kosiarki实现ActionListener
{
私人环境短片;
私人物业;;
私人按钮组应答按钮;
私有JTextPane textPane;
私有JButton nextButton;
私人JPanel回答小组;
私人JTable answersTable;
私有字符串assertedKosiarka;
私有字符串lastasertedkosiarka=“”;
公共Kosiarki()
{
//奥克诺
START=100
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.*;
import java.util.List;
import java.util.Properties;

import javax.swing.SwingUtilities;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JCheckBox;
import javax.swing.JTextPane;
import javax.swing.JToggleButton;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

import CLIPSJNI.Environment;
import CLIPSJNI.FactAddressValue;
import CLIPSJNI.MultifieldValue;
import CLIPSJNI.PrimitiveValue;
import CLIPSJNI.SymbolValue;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.util.Comparator;
import javax.swing.table.TableColumn;

public class Kosiarki implements ActionListener
{
 private Environment clips;
 private Properties properties;
 private ButtonGroup answerButtons;
 private JTextPane textPane;
 private JButton nextButton;
 private JPanel answerPanel;
 private JTable answersTable;
 private String assertedKosiarka;
 private String lastAssertedKosiarka="";

 public Kosiarki()
 {
  // okno
  JFrame frame=new JFrame("AI Name Project");
  frame.getContentPane().setLayout(new GridLayout(3, 1));
  frame.setSize(500, 300);
  frame.setLocationByPlatform(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  // panel - piewszy wiersz tableli 1x3 - do wyswietlania tekstow(glownie pytan)
  JPanel textPanel=new JPanel();
  textPane=new JTextPane();
  textPane.setOpaque(false);
  textPane.setEditable(false);

  StyledDocument doc=textPane.getStyledDocument();
  SimpleAttributeSet center=new SimpleAttributeSet();
  StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
  doc.setParagraphAttributes(0, doc.getLength(), center, false);

  textPanel.add(textPane);

  // panel - drugi wiersz tableli 1x3 - do wyswietlania checkboksow i radiobuttonow
  answerPanel=new JPanel();
  answerButtons=new ButtonGroup();

  // panel - trzeci i ostatni wiersz tableli 1x3 - do wyswietlania przycisku "next"
  JPanel nextButtonPanel=new JPanel();
  nextButton=new JButton();
  nextButton.setActionCommand("next");
  nextButtonPanel.add(nextButton);
  nextButton.addActionListener(this);

  // wstawiamy na okno wszystkie trzy panele
  frame.getContentPane().add(textPanel);
  frame.getContentPane().add(answerPanel);
  frame.getContentPane().add(nextButtonPanel);
  frame.setVisible(true);

  // inicjalizacja CLIPS-a
  clips=new Environment();
  clips.load("control.clp");
  clips.load("knowledgeBase.clp");
  clips.reset();
  clips.run(1);

  // ititializing file with properties
  properties=new Properties();
  loadProperties(new File("configuration.properties"));

  // w praktyce pokazujemy okno wstepne
  nextUIState();
 }

 private void nextUIState()
 {
  answerPanel.removeAll();

  // pobieramy aktualny stan UI
  MultifieldValue currentStateMultifieldValue=(MultifieldValue)clips.eval("(find-all-facts((?f currentState))TRUE)");
  List<FactAddressValue> currentStateList=currentStateMultifieldValue.listValue();
  if(currentStateList.isEmpty())
  {
   return;
  }
  FactAddressValue currentState=currentStateList.get(0);

  // sprawdzamy czy nie "zablokowalismy" sie na "name"
  assertedKosiarka=currentState.getFactSlot("name").toString();
  if(assertedKosiarka.contentEquals(lastAssertedKosiarka))
  {
   clips.run(1);
   nextUIState();
   return;
  }
  lastAssertedKosiarka=assertedKosiarka;

  // ustawienie nazw przycisku "next"/"restart"/"start"
  if(currentState.getFactSlot("state").toString().equals("final"))
  {
   nextButton.setActionCommand("restart");
   nextButton.setText(properties.getProperty("RESTART").toString());

   // Dodatkowo wypisywanie wynikow
   MultifieldValue namesMultifieldValue=(MultifieldValue)clips.eval("(find-all-facts((?f result))TRUE)");
   List<FactAddressValue> nameList=namesMultifieldValue.listValue();

   if(!nameList.isEmpty())
   {
    textPane.setText(properties.getProperty("RESULTS_END_TEXT").toString());
    System.out.println("pasujące kosiarki:");

    String headers[]={
      properties.getProperty("PRODUCENT"),
      properties.getProperty("TYP"),
      properties.getProperty("RODZAJ"),
      properties.getProperty("CENA")};

    ArrayList<Result> resultList=new ArrayList<Result>();
    for(FactAddressValue name : nameList)
    {
     resultList.add(new Result(
       name.getFactSlot("producent").getValue().toString(),
       name.getFactSlot("typ").getValue().toString(),
       name.getFactSlot("rodzaj").getValue().toString(),
       name.getFactSlot("cena1").getValue().toString()));
    }

    Collections.sort(resultList, new ResultComperator());

    String data[][]=new String[nameList.size()][4];
    int i=0;
    for(Result result : resultList)
    {
     data[i][0]=properties.getProperty(result.getProducent());
     data[i][1]=result.getTyp();
     data[i][2]=result.getRodzaj();
     data[i][3]=result.getCena();

     String newKosiarka=data[i][0] + "(" + data[i][1] + ")";
     System.out.println(newKosiarka);

     i++;
    }

    answersTable=new JTable(data, headers);
    answersTable.setPreferredScrollableViewportSize(new Dimension(answerPanel.getWidth()- 25, answerPanel.getHeight()- 25));
    answersTable.getTableHeader().setReorderingAllowed(false);
    answersTable.setEnabled(false);

    TableColumn column=new TableColumn();
    column=answersTable.getColumnModel().getColumn(0);
    column.setMaxWidth(100);

    JScrollPane scrollPane=new JScrollPane(answersTable);

    answerPanel.add(scrollPane);
   }
   else
   {
    textPane.setText(properties.getProperty("NO_RESULTS_END_TEXT").toString());
   }

   answerPanel.repaint();
   return;
  }
  else if(currentState.getFactSlot("state").toString().equals("initial"))
  {
   nextButton.setActionCommand("start");
   nextButton.setText(properties.getProperty("START").toString());
  }
  else
  {
   nextButton.setActionCommand("next");
   nextButton.setText(properties.getProperty("NEXT").toString());
  }

  // ustawienie tekstu(np. pytania)
  String text=((SymbolValue)currentState.getFactSlot("text")).stringValue();
  textPane.setText(properties.getProperty(text).toString());

  // Wstawiamy przyciski(comboboksy/radioboksy)
  boolean checkboxes=false;
  if(currentState.getFactSlot("answerType").toString().equals("checkBox"))
  {
   checkboxes=true;
  }

  answerPanel.removeAll();
  answerButtons=!checkboxes ? new ButtonGroup(): null;

  MultifieldValue answersMultifieldValue=(MultifieldValue)currentState.getFactSlot("answers");
  List<PrimitiveValue> answersList=answersMultifieldValue.listValue();

  for(PrimitiveValue answer : answersList)
  {
   JToggleButton button;
   if(checkboxes)
   {
    button=new JCheckBox(properties.getProperty(answer.toString()).toString(), false);
   }
   else
   {
    button=new JRadioButton(properties.getProperty(answer.toString()).toString(), false);
   }

   // zaznaczanie domyslnie aktywnych przyciskow
   MultifieldValue selectedMultifieldValue=(MultifieldValue)currentState.getFactSlot("selected");
   List<PrimitiveValue> selectedList=selectedMultifieldValue.listValue();
   for(PrimitiveValue selected : selectedList)
   {
    if(answer.toString().equals(selected.toString()))
    {
     button.setSelected(true);
     break;
    }
   }

   button.setActionCommand(answer.toString());
   answerPanel.add(button);

   if(!checkboxes)
   {
    answerButtons.add(button);
   }
  }

  answerPanel.repaint();
 }

 @Override
 public void actionPerformed(ActionEvent event)
 {
  // po kliknieciu przycisku "next" dodawane sa fakty do CLIPS-a
  if(event.getActionCommand().equals("next"))
  {
   for(Component component : answerPanel.getComponents())
   {
    if(component instanceof JToggleButton)
    {
     JToggleButton button=(JToggleButton)component;
     if(button.isSelected())
     {
      String toAssert="(" + assertedKosiarka + " " + button.getActionCommand()+ ")";
      clips.assertString(toAssert);
      System.out.println(toAssert);
     }
    }
   }

   clips.run(1);
   nextUIState();
   return;
  }

  // po kliknieciu przycisku "start"
  if(event.getActionCommand().equals("start"))
  {
   clips.assertString("(start)");
   System.out.println("(start)");

   clips.run(1);
   nextUIState();
   return;
  }

  // po kliknieciu przycisku "restart" resetujemy srodowisko CLIPS-a
  if(event.getActionCommand().equals("restart"))
  {
   clips.reset();
   System.out.println("clips.reset");

   clips.run(1);
   nextUIState();
   return;
  }
 }

 private void loadProperties(File propertiesFile)
 {
  InputStream is;
  try
  {
   is=new FileInputStream(propertiesFile);
   properties.load(is);
  }
  catch(FileNotFoundException e)
  {
   System.out.println("Cannot find configuration file.");
  }
  catch(IOException e)
  {
   System.out.println("Some problems with configuration file.");
  }
 }

 public static void main(String[] args)
 {
  SwingUtilities.invokeLater(
   new Runnable()
   {
    public void run()
    {
     new Kosiarki();
    }
   }
  );
 }

}

class Result
{
 private String producent;
 private String typ;
 private String rodzaj;
 private String cena1;

 public String getProducent()
 {
  return producent;
 }

 public void setProducent(String producent)
 {
  this.producent=producent;
 }

 public String getTyp()
 {
  return typ;
 }

 public void setTyp(String typ)
 {
  this.typ=typ;
 }

 public String getRodzaj()
 {
  return rodzaj;
 }

 public void setRodzaj(String rodzaj)
 {
  this.rodzaj=rodzaj;
 }

 public String getCena()
 {
  return cena1;
 }

 public void setCena(String cena1)
 {
  this.cena1=cena1;
 }


 public Result()
 {
 }

 public Result(String producent, String typ, String rodzaj, String cena1)
 {
  this.producent=producent;
  this.typ=typ;
  this.rodzaj=rodzaj;
  this.cena1=cena1;
 }

}

class ResultComperator implements Comparator<Result>
{
 public int compare(Result o1, Result o2)
 {
  return o1.getProducent().compareTo(o2.getProducent());
 }

}
(deftemplate currentState
   (slot name (default none))
   (slot state (default middle))
   (slot text)      
   (slot answerType (default radioButton))
   (multislot selected)
   (multislot answers)
)

(deftemplate result
   (slot producent (type STRING))
   (slot typ (type STRING))
   (slot rodzaj (type STRING))
   (slot cena1 (type INTEGER))
)

; Startup window
(defrule system-banner ""
 =>
   (assert (currentState 
      (text START_TEXT)
      (name start)
      (state initial)
      (answers))
   )
)

; Results window
(defrule EndOfQuestions ""
   ?state<-(currentState)
   (end)
 =>
   (retract ?state) 
   (assert (currentState 
      (text NO_RESULTS_END_TEXT)
      (state final)
   ))
)

; Pytanie o powierzchnie
(defrule selectPowierzchnia ""
   ?state<-(currentState)
    (start)
   (not(pytaniePowierzchnia))
   =>
   (retract ?state) 
   (assert (pytaniePowierzchnia))   
   (assert (currentState
      (name powierzchnia)
      (text SELECT_PYTANIE_POWIERZCHNIA)
      (answerType checkBox)
      (answers 10 20 30 40 50 100 200 300 400 500 1000 2000 3000 4000 5000)
      (selected )
   ))
)

; Pytanie o mechanizm tnacy ====== bezsilnikowy ======
(defrule selectMechanizm ""
   ?state<-(currentState)
   (not(pytanieMechanizm))
   (not(powierzchnia ?))
   (naped NOENGINE)
   (naped ELECTRIC)
   =>
   (retract ?state) 
   (assert (pytanieMechanizm))   
   (assert (currentState
      (name mechanizm)
      (text SELECT_PYTANIE_MECHANIZM)
      (answerType checkBox)
      (answers TRADYCYJNY ROTACYJNY ZYLKOWY WRZECIONOWY BIJAKOWY KARCZUJACY LISTWOWY)
      (selected)
   ))
)

; Pytanie o mechanizm tnacy ====== elektryczny ======
(defrule selectMechanizm ""
   ?state<-(currentState)
   (not(pytanieMechanizm))
   (not(powierzchnia ?))
   (naped ELECTRIC)
   (naped ENGINE)
   =>
   (retract ?state) 
   (assert (pytanieMechanizm))   
   (assert (currentState
      (name mechanizm)
      (text SELECT_PYTANIE_MECHANIZM)
      (answerType checkBox)
      (answers TRADYCYJNY ROTACYJNY ZYLKOWY WRZECIONOWY BIJAKOWY KARCZUJACY LISTWOWY)
      (selected)
   ))
)

; Pytanie o mechanizm tnacy ====== spalinowy ======
(defrule selectMechanizm ""
   ?state<-(currentState)
   (not(pytanieMechanizm))
   (not(powierzchnia ?))
   (naped ENGINE)
   =>
   (retract ?state) 
   (assert (pytanieMechanizm))   
   (assert (currentState
      (name mechanizm)
      (text SELECT_PYTANIE_MECHANIZM)
      (answerType checkBox)
      (answers TRADYCYJNY ROTACYJNY ZYLKOWY WRZECIONOWY BIJAKOWY KARCZUJACY LISTWOWY)
      (selected)
   ))
)

; Pytanie o dodatki
(defrule selectDodatki ""
   ?state<-(currentState)
   (not(pytanieDodatki))
   (mechanizm TRADYCYJNY|ROTACYJNY|ZYLKOWY|WRZECIONOWY|BIJAKOWY|KARCZUJACY|LISTWOWY)  ;;;;;
   =>
   (retract ?state) 
   (assert (pytanieDodatki))   
   (assert (currentState
      (name dodatki)
      (text SELECT_PYTANIE_DODATKI)
      (answerType checkBox)
      (answers MULCZOWANIE KOSZ TARCZA ROZRUSZNIK BLOKADA NAPED NIE)
      (selected)
   ))
)

; Pytanie o cene
(defrule selectCena ""
   ?state<-(currentState)
   (not(pytanieCena))
   (dodatki MULCZOWANIE|KOSZ|TARCZA|ROZRUSZNIK|BLOKADA|NAPED|NIE)
   =>
   (retract ?state)
   (assert (PytanieCena))
   (assert (currentState
      (name cena)
      (text SELECT_PYTANIE_CENA)
      (answerType checkBox)
      (answers 10 20 30 40 50 100 200 300 400 500 1000 2000 3000 4000 5000)
      (selected)
   ))
   ;(assert (end))
)

(defrule suma_pow_init
   ?i<-(powierzchnia ?p)
   (not(suma_pow ?))
 =>
   (retract ?i)
   (assert(suma_pow ?p)))

(defrule sumuj_pow
   ?i<-(powierzchnia ?p)
   ?j<-(suma_pow ?s)
 =>
   (retract ?i ?j)
   (assert(suma_pow (+ ?p ?s))))

(defrule nast_pyt_pow1
   (not(powierzchnia ?))
   (suma_pow ?s)
   (test(< ?s 150))
 =>
   (assert(naped NOENGINE))
   (assert(naped ELECTRIC)))

(defrule nast_pyt_pow2
   (not(powierzchnia ?))
   (suma_pow ?s)
   (test(>= ?s 150))
   (test(< ?s 750))
 =>
   (assert(naped ELECTRIC))
   (assert(naped ENGINE)))

(defrule nast_pyt_pow3
   (not(powierzchnia ?))
   (suma_pow ?s)
   (test(> ?s 750))
 =>
   (assert(naped ENGINE)))

(defrule suma_cen_init
   ?i<-(cena ?c)
   (not(suma_cen ?))
 =>
   (retract ?i)
   (assert(suma_cen ?c)))

(defrule sumuj_ceny
   ?i<-(cena ?c)
   ?j<-(suma_cen ?s)
 =>
   (retract ?i ?j)
   (assert(suma_cen (+ ?s ?c))))

(defrule nast_pyt_cena1
   (not(cena ?))
   (suma_cen ?s)
   (test(>= ?s 450))
   (test(< ?s 500))
 =>
   (assert(cena DO_500))
   (assert (end)))

(defrule nast_pyt_cena2
   (not(cena ?))
   (suma_cen ?s)
   (test(>= ?s 500))
   (test(< ?s 750))
 =>
   (assert(cena DO_750))
   (assert (end)))

(defrule nast_pyt_cena3
   (not(cena ?))
   (suma_cen ?s)
   (test(>= ?s 750))
   (test(< ?s 1500))
 =>
   (assert(cena DO_1500))
   (assert (end)))

(defrule nast_pyt_cena4
   (not(cena ?))
   (suma_cen ?s)
   (test(>= ?s 1500))
   (test(< ?s 3000))
 =>
   (assert(cena DO_3000))
   (assert (end)))

(defrule nast_pyt_cena5
   (not(cena ?))
   (suma_cen ?s)
   (test(>= ?s 3000))
   (test(< ?s 5000))
 =>
   (assert(cena DO_5000))
   (assert (end)))

(defrule nast_pyt_cena6
   (not(cena ?))
   (suma_cen ?s)
   (test(>= ?s 5000))
   (test(< ?s 10000))
 =>
   (assert(cena DO_10000))
   (assert (end)))

(defrule nast_pyt_cena7
   (not(cena ?))
   (suma_cen ?s)
   (test(>= ?s 10000))
 =>
   (assert(cena OD_10000))
   (assert (end)))