JESS 사용법

●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))
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by Kornuri


Trackback URL : http://www.kornuri.com/blog/trackback/24

Leave a comment
[로그인][오픈아이디란?]
« Previous : 1 : ... 26 : 27 : 28 : 29 : 30 : 31 : 32 : 33 : 34 : ... 52 : Next »

블로그 이미지

항상 행복하자고 하면 행복해질까?

- Kornuri

Calendar

«   2010/07   »
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Site Stats

Total hits:
115913
Today:
31
Yesterday:
46