You are on page 1of 25

Rule-based expert systems

Carlo Matteo Scalzo

Dipartimento di Informatica e Sistemistica
Dipartimento di Informatica e Sistemistica
Rule -based expert systems Carlo Matteo Scalzo Dipartimento di Informatica e Sistemistica

Expert systems in the real world

Real-time (knowledge-based, context-sensitive control)

Need to interface with external subsystems

Need to handle non-symbolic information

Efficient, predictable, easy to update

Need to add and discard knowledge quickly

Pagina 2
Pagina 2

Pagina 2

Pagina 2

Architecture (multi hyper graph)

Architecture (multi hyper graph) Pagina 3
Pagina 3
Pagina 3

Pagina 3

Pagina 3

Programming languages

X = C, C++, Java,
X = C, C++, Java,

X / Prolog interface

Prolog

Prolog / X interface

Pagina 4
Pagina 4

Pagina 4

Pagina 4

Expert systems in Prolog

Prolog is the natural choice when developing a rule- based expert system

– Horn rules

– Efficient (depth-first, chronological backtracking)

– Control operators (cut)

– Negation as failure

– Variables, functional terms

– Easy to integrate with C, C++, Java,

Pagina 5
Pagina 5

Pagina 5

Pagina 5

Rules in Prolog

It’s possible to define a rule language in Prolog:

rule([condition(collateral,’>=’,excellent),

condition(finances,’>=’,good),

condition(yield,’>=’,reasonable)],give_credit).

rule([condition(collateral,’=’,good),

condition(finances,’=’,good),

condition(yield,’>=’,reasonable)],consult_superior).

Pagina 6
Pagina 6

Pagina 6

Pagina 6

Rules in Prolog

But it’s much better to use just plain Prolog:

IF (obstacle_density = high) THEN (max_speed = low) ELSE (max_speed = high)

% choose_speed(Obstacle_Density , Max_Speed)

choose_speed(high , low) :- !. choose_speed(_ , high).

Pagina 7
Pagina 7

Pagina 7

Pagina 7

Case Study: Dotto

A mobile platform for tourism

The user walks through the city, and the system gives the users information about the current place, monuments, shops, events in the city,

The system gives information to the user by reading pre-registered paragraphs

The core of the system is a rule-based expert system which must choose, in each situation, the most appropriate paragraph

Pagina 8
Pagina 8

Pagina 8

Pagina 8

Dotto Static KB

Dotto Static KB Pagina 9
Pagina 9
Pagina 9

Pagina 9

Pagina 9

Dotto Static KB

Each area in the map is linked with one or more paragraphs, with a relevance factor in [0.2, 0.4, 0.6, 0.8, 1.0]:

paragraphAreaRelevance(par_11 , area_27, 0.2).

Pagina 10
Pagina 10

Pagina 10

Pagina 10

Dotto Static KB

Each paragraph is tagged with one or more tags:

tagParagraph(tag_24 , par_7).

Tags are used to describe paragraphs (“arts”,

“science”,

),

and are organized as a hierarchy:

subTag(tag_9 , tag_84).

Pagina 11
Pagina 11

Pagina 11

Pagina 11

Dotto Dynamic KB

The user can let the system know that he likes the current paragraph by pushing a button

This kind of information is used to update the user model, which is actually the set of tags associated to the paragraphs the user liked

For each tag in the user model, the system counts the number of preferences expressed by the user

userPreference(tag_11, 2).

Pagina 12
Pagina 12

Pagina 12

Pagina 12

Dotto Dynamic KB

The system also mantains the list of the paragraphs already proposed to the user (the system never reads a paragraph twice)

alreadyProposed(par_23).

Pagina 13
Pagina 13

Pagina 13

Pagina 13

Architecture: Dotto StoryTeller

Global Relevance: Best Relevance User Model Paragraph Dotto Relevance: Overlappin gAreas Combined Relevance:
Global
Relevance:
Best
Relevance
User Model
Paragraph
Dotto
Relevance:
Overlappin
gAreas
Combined
Relevance:
Areas
Relevance:
Linked
Areas
Dotto StoryTeller
Pagina 14
Pagina 14

Pagina 14

Pagina 14

Prolog implementation

addUserPreference(Paragraph):

– Adds +1 to the number of preferences for all the tags linked to Paragraph (i.e., updates the dynamic kb)

addAlreadyProposed(Paragraph):

– Marks Paragraph as already proposed (i.e., updates the dynamic kb)

Pagina 15
Pagina 15

Pagina 15

Pagina 15

Prolog implementation

dottoStoryTeller(+AreaList, -BestPar)

Invokes the expert system

– AreaList is the list of the areas in the current position of the user (with the related overlapping percentage)

• [ [area_1, 23] , [area_3, 48] ]

– BestPar is the paragraph to propose to the user

Pagina 16
Pagina 16

Pagina 16

Pagina 16

Prolog implementation

dottoStoryTeller(AreaList, BestPar) :- dstIn(AreaList), dstOut(BestPar).

dstIn(AreaList) :- cleanKB, extractPar(AreaList, ParList), removeAlreadyProposed(ParList, CorrectList), evalUserModel(CorrectList), evalAreaOverlap(CorrectList, AreaList), evalAreaLink(CorrectList, AreaList).

Pagina 17
Pagina 17

Pagina 17

Pagina 17

Prolog Implementation

evalUserModel([]). evalUserModel([IdPar | Rest]) :- evalParUserModel(IdPar), valutaModUt(Rest).

evalParUserModel(Par) :- computeRelevanceUserModel(Par, Val), assert(relevanceUserModel(Par, Val)).

Val = f( par, user-model, tag-hierarchy )

Val : [very_high, high, medium, low, very_low]

Pagina 18
Pagina 18

Pagina 18

Pagina 18

Prolog Implementation

evalAreaLink([], AreaList). evalAreaLink([IdPar | Rest], AreaList) :- evalParAreaLink(IdPar, AreaList), evalAreaLink(Rest, AreaList).

evalParAreaLink(Par, AreaList) :- computeRelevanceAreaLink(Par, AreaList), assert(relevanceAreaLink(Par, Val)).

Val = f( par, area-list, relevance-links)

Val : [very_high, high, medium, low, very_low]

Pagina 19
Pagina 19

Pagina 19

Pagina 19

Prolog Implementation

evalAreaLink([], AreaList). evalAreaOverlap([IdPar | Rest], AreaList) :- evalParAreaOverlap(IdPar, AreaList), evalAreaOverlap(Rest, AreaList).

evalParAreaOverlap(Par, AreaList) :- computeRelevanceAreaOverlap(Par, AreaList), assert(relevanceAreaOverlap(Par, Val)).

Val = f( par, area-list )

Val : [very_high, high, medium, low, very_low]

Pagina 20
Pagina 20

Pagina 20

Pagina 20

Prolog implementation

dstOut(BestPar) :- findBestPar(BestPar).

findBestPar(BestPar) :- findall([Par,Val], evalParGlobal(Par,Val), ParValList), findBestInClass(ParValList, BestPar).

Pagina 21
Pagina 21

Pagina 21

Pagina 21

Prolog implementation

evalParGlob(Par, Val) :- evalParAreaComb(Par, AreaVal), relevanceUserModel(Par, UserModVal), globalTable(AreaVal, UserModVal, Val).

globalTable(very_low, very_low, very_low).

globalTable(low, medium, low).

Pagina 22
Pagina 22

Pagina 22

Pagina 22

Prolog implementation

evalParAreaComb(Par, Val) :- relevanceAreaOverlap(Par, OverlapVal), relevanceAreaLink(Par, LinkVal), areaCombTable(OverlapVal, LinkVal, Val).

areaCombTable(very_low, very_low, very_low).

areaCombTable(very_high, medium, high).

Pagina 23
Pagina 23

Pagina 23

Pagina 23

Prolog techniques

Dynamic axioms: assert / retract

Rules execution: “backward chaining”

Handling non-symbolic data: arithmetic, lists

Pagina 24
Pagina 24

Pagina 24

Pagina 24

Contacts

scalzo@dis.uniroma1.it

Pagina 25
Pagina 25

Pagina 25

Pagina 25