●JESS의 실행
cmd) java -classpath jess.jar jess.Main
●간단한 기본 명령어
(batch filename)
Load a file into working memory and rule base
(run)
Start the program
(facts)
Display all facts in working memory
(reset)
Remove all facts in working memory
●출력
(printout t “Hello World!” crlf)
●함수 match
(bind ?x 1) ; x = 1
(bind ?x 1.11) ; x = 1.11
(bind ?x “abc”) ; x = “abc”
(bind ?x (a b c)) ; x = (a b c) //List
●Facts의 정의
(assert fact)
(assert (parent mary jane))
●Rule의 정의
(defrule name “comment” rule)
예시
(defrule grandparent “”
(parent ?a ?x)
(parent ?x ?b)
=>
(printout t ?a “ is a grandparent of “ ?b crlf)
)
●a ≠ b
(test (not (eq ?a ?b))) //True, False로 반환
●프로그래밍 예시
(assert (parent mary jane))
(assert (parent mary john))
(assert (parent jane karen))
(assert (parent jane bill))
(assert (parent john jim))
(assert (female mary))
(assert (female jane))
(assert (female karen))
(assert (male john))
(assert (male bill))
(assert (male jim))
(defrule sibling ""
(parent ?x ?a)
(parent ?x ?b)
(test (not (eq ?a ?b)))
=>
(assert (sibling ?a ?b))
(printout t ?a " and " ?b " are siblings." crlf))
(defrule cousin ""
(sibling ?x ?y)
(parent ?x ?a)
(parent ?y ?b)
=>
(assert (cousin ?a ?b))
(printout t ?a " is a cousin of " ?b crlf))
(defrule brother ""
(parent ?x ?a)
(parent ?x ?b)
(male ?a)
(male ?b)
(test (not (eq ?a ?b)))
=>
(assert (brother ?a ?b))
(printout t ?a " is a brother of " ?b crlf))
(defrule sister ""
(parent ?x ?a)
(parent ?x ?b)
(female ?a)
(female ?b)
(test (not (eq ?a ?b)))
=>
(assert (sister ?a ?b))
(printout t ?a " is a sister of " ?b crlf))
(defrule mother ""
(parent ?x ?a)
(female ?x)
=>
(assert (mother ?x ?a))
(printout t ?x " is the mother of " ?a crlf))
(defrule father ""
(parent ?x ?a)
(male ?x)
=>
(assert (father ?x ?a))
(printout t ?x " is the father of " ?a crlf))
(defrule grandfather ""
(father ?x ?y)
(father ?y ?z)
=>
(assert (grandfather ?x ?z))
(printout t ?x " is a grandfather of " ?z crlf))
(defrule grandmother ""
(mother ?x ?y)
(father ?y ?z)
=>
(assert (grandmother ?x ?z))
(printout t ?x " is a grandmother of " ?z crlf))
(defrule descendent ""
(parent ?x ?y)
(parent ?y ?z)
=>
(assert (descendent ?z ?x))
(printout t ?z " is a descendent of " ?x crlf))
(defrule ancestor ""
(parent ?x ?y)
(parent ?y ?z)
=>
(assert (ancestor ?x ?z))
(printout t ?x " is an ancestor of " ?z crlf))