ERESYE: ArtificialIntelligence in Erlang Programs ...

66 downloads 0 Views 323KB Size Report
This—fun“ is derived by analyzing the source code of the function defining the rule .... grape = [ set_of (wine_grape), mandatory , nodefault], sugar = [ string ...
! "

! $

#

&

' () *+ "

1

%

*, -. -//.

2

3 & 3 4 ( # + 5 * + $

!

6 # * ) "

# )

!

3 + # + +% 2

3 3

$ 6 #

0

! *

*

0

' -//. "

*, -. -//.

-

& 3 " 2) < ! 3 ) * ,:

#

89 *;

: =)

5

)

#

$ ( "2

*

) *

3

;

!#

; # 8$

! *)

*)

; #

**

2) )

)

(* + + + # + *

>*#* # )

8 (9 2 > # 2 ) * ) *

: *

( 2 *

# # >)

#

) 0

0

' -//. "

7

*, -. -//.

4 ( # 3

5 *

!

*

#

( 2

;

5* 3

5 *

!

* # 3

$ )

*

#

;!

*#

8

9 >; 9 2 !# 3 ) ! ; " < ! >* 6 ! > ;@ = ) 3 ") !# $ > ( ! 52) * )

:

) *

(color pen blue) 0

0

' -//. "

*, -. -//.

?

$

5 *

(defrule convert ?temp (retract ?temp ) (assert (temperature (+ ( - ? x 32) (/ 5 9) C )))) (defrule move (declare salience 99) (on_table ?object ) ((color ?object red ) or (color ?object blue )) => (assert (move_object ?object )) (retract (on_table ?object )) )

3

#

;! ) * * 8 ; ! *# 2 8 :

) 3 ")

0

) %4 : #

0

5 #

#

3 # 3 ") *

' -//. "

)

5

.

*, -. -//.

"

)) *

)

# !

*)8

2 (: 3 B 2 (

*

+ C> *# + -> *# ; 2

3

*

8 8

:* :* *

2

)

# ; ;

!

)

+ +

!

)

E#

*) > )

D *

#

3 ') 2 ( D + + +

) # ) (

0

8 ) D ) ( ) );

:

*

)

* * )

0

2 ( )

' -//. "

*, -. -//.

) #

A

5 * CC

--

8 C:

77

CCG :: G88 H H --G G8; 8;H H :: 77G G88 ::

α α

% β

α

!

!

α "

" !

α α

!#

"

!

"

!#

"

!

"

!# $"

"

% β

! !

%

"

"

!#

"

β

! !

"

"

!#

"

!

"

# 0

3

0

2 )

' -//. "

F

*, -. -//.

5 #

#* #

* 3 3

)

) 8( 2

( 2 :

; *

# #

#*

, ,

– {temperature, 50, ‘F’} – {alarm, on} – {speed, 30, ‘km/h’}

3

#

0

2

#

0

#

' -//. "

*, -. -//.

I

-module (sample). check (Engine, {temperature, X, 'C'}, {alarm, off } = F) when X > 30 - > eresye:retract (Engine, F), eresye:assert (Engine, {alarm, on}), ...;

start () - > eresye:start (sample_engine), eresye:add_rule (sample_engine, {sample, convert}), ...

& &' '

( (

& &' '

!!

0

0

' -//. "

5 #

# ) #

#

)

"

) )

*

0

#

*

)

3") 31

J

*, -. -//.

) )

' ' ""

0

' -//. "

5 #

*

*, -. -//.

5 #

C/

) )

*

# ) #

)

3")

* ) &+

3") &+

#

#

# !#

*

) #

0

0

CC

*, -. -//.

)

!

# ) #

*

2

) 2 # 6 # *

) 0

#

*

)

3

!

) # ' -//. "

)

5 #

+

# +

2)

5 #

) #) )

2) 5

* #

# !

, 0

' -//. "

*, -. -//.

C-

" sample_rule(Engine, sample_rule(Engine, {a, {a, X}, X}, {b, X, {b, X, Y}, Y}, {c, {c, Y}) Y}) -> ->

α

α

% β

α

α

,-.

!

"

, - .5 3 * 3 < #= % 3 ") < # = β# ! ,-.

) ) ! K

;! ) #"

α

,#- - .

β

α

,#- - .

,- .

,#- - .

,- .

,#- -$.

) *

)

) #%

)

! !

"

"

,#- - .

,- .

# 0

0

' -//. "

C7

*, -. -//.

" sample_rule(Engine, sample_rule(Engine, {a, {a, X}, X}, {b, {b, X, X, Y}, Y}, {c, Y}) {c, Y}) -> ->

α

,-.

!

"

β

!

α

,-.

α

α

,#- - .

,- .

,#- - .

,- .

,#- -$.

,-.

B% α

α

α

α

% β

α

# fun ({a, X}) -> true end. % " fun ({b, X, Y}) -> true end.

,#- - .

! fun ({c, Y}) β -> true end. !

"

,#- - .

" ,- .

# 0

0

' -//. "

*, -. -//.

C?

" sample_rule(Engine, sample_rule(Engine, {a, {a, X}, X}, {b, X, {b, X, Y}, Y}, {c, {c, Y}) Y}) -> ->

% β

!

"

α

B % %

α

α

α

α

fun ([], {a, X}) -> true end. !#

"

"

!

fun ([{a, X}, {b, X, Y}], {c, Y}) -> true end.

%

%

"

,-.

"

fun ([{a, !# X}]," {b, X, -> ! Y}) " true end. !# $"

% !

#

!

,-.

β

α

,#- - .

β

!

"

,-.

,#- - .

,- .

# 0

0

1 3

C.

*, -. -//.

!&

2 * class ( wine ) -> {{ name / name == [[ string string ,, mandatory mandatory ,, nodefault], nodefault], color = [ string , mandatory , nodefault], color = [ string , mandatory ' , nodefault],& ' wine.onto flavor flavor == [[ string string ,, mandatory mandatory ,, nodefault], nodefault], grape grape == [[ set_of set_of (wine_grape), (wine_grape), mandatory mandatory ,, nodefault], nodefault], sugar = [ string , mandatory , nodefault]}; sugar = [ string , mandatory , nodefault]}; '

31 3 *

class class ('red-wine ('red-wine ') ') -> -> is_a( is_a( wine wine ), ), {{ color = [ string , mandatory , 2 > ( color = [ string , mandatory , default default (( red red )] )] }; };

#

81'$

:

>

class ('white-wine ('white-wine ') ') -> -> is_a( is_a( wine wine ), ), = class {{ color = [ string , mandatory , default color = [ string , mandatory , default (( white white )] )] }; }; ... ... 0

0

' -//. "

*, -. -//.

CI

1

!& &

'

( '

'

*

' '

*

wine.hrl

/ '

wine.onto

&

'

wine.erl

3") 1

! 2 .hrl

.erl # # :

*

8*

2)

) ) *

( ) ! *

0

1

) .onto

:*

8 0

)

)

' -//. "

)!

8< M =

) ** : CJ

*, -. -//.

!& &

'

( '

'

*

' '

*

wine.hrl

/ '

wine.onto

&

'

wine.erl

3 ") * 3 #

;

!#

)

!# 0

0

' -//. "

*, -. -//.

-/

$ 6

*

3% 2

*

+ $ 3 !; 3 * 3 1;@ 2 ))

)

+ 3 !; 3 3 1;@

8*

;! : 2 ) #* 8* ) ) 8 #** ! * :

0

0

' -//. "

$ 6 3

#

;! ;! )

:

-C

*, -. -//.

*

5 *

+ $ 3 > 3 # 3 #

* 2) 2 );# >

2) 8 # >

*#

*

2)

; ; :

#

+ 3 # ; 3 # 3 # )!

0

) #** # 4 !

2 ;# # # > ! N1 4 # O:

0

' -//. "

*, -. -//.

*#

#

;

8

--

$ 6 3

* 2) )

!

+ $ 3 3

>;

* * 2 )) 3 ") * #

;! !

! ( 2!

$ !

+ 3 #

!

3 1) 2

!#

0

) !# *

0

3

*

3

)

* 2 ;* 3 4# 2 ( + + + + +

# * ;

)* )
; )

* K ) ! 5 =8 ) ! 5 5 * ) %4 # ; # ! !) # N 0

' -//. "

*, -. -//.

,

8

) ) : *

-?

") (! #O

( & &

0

P

0

' -//. "

P ,#

>

#

,

,

*, -. -//.

-.