From VisualWorks® NonCommercial, 7.5 of April 16, 2007 on December 29, 2007 at 2:39:45 pm TP - Systemes Experts package comment 'comments' Regle Smalltalk Core.Object false none poids nom condition action sinon activable hasBeenExecuted TP - Systemes Experts TP - Systemes Experts Regle Class permettant d'acceder la base de regles RulesManager Smalltalk UI.ApplicationModel false none model rules ruleDetails TP - Systemes Experts TP - Systemes Experts RulesManager rules RuleEditor Smalltalk UI.ApplicationModel false none model ruleManager poids action nom condition sinon UIApplications-New TP - Systemes Experts RuleEditor "rules editor" Instance Variables: rules <SelectionInList> description of rules LanceurSystemeExpert Smalltalk UI.ApplicationModel false none model UIApplications-New TP - Systemes Experts LanceurSystemeExpert lanceur ReglesCollection Smalltalk Core.Object false none regles XMLLocation sortBlock TP - Systemes Experts TP - Systemes Experts ReglesCollection Collection de regles Moteur Smalltalk Core.Object false none reglesCollection faitsCollection TP - Systemes Experts TP - Systemes Experts Moteur Moteur ! Fait Smalltalk Core.Object false none etat type nom texte TP - Systemes Experts TP - Systemes Experts Fait etat : -1 : INCONNU 0 : FAUX 1 : VRAI FaitsCollection Smalltalk Core.Object false none faits XMLLocation TP - Systemes Experts TP - Systemes Experts FaitsCollection collections de fais FaitsManager Smalltalk UI.ApplicationModel false none model facts UIApplications-New TP - Systemes Experts FaitsManager "a comment" FaitEditor Smalltalk UI.ApplicationModel false none name model texte UIApplications-New TP - Systemes Experts FaitEditor "you didn't put any comment !!" LanceurModel Smalltalk Core.Object false none regles faits moteur TP - Systemes Experts TP - Systemes Experts LanceurModel lanceur ReglesCollection class instance creation new ^super new initialize ReglesCollection initialize-release initialize sortBlock := [:a :b | a poids >= b poids]. ^self ReglesCollection accessing XMLLocation: anObject XMLLocation := anObject allActivableRules ^regles select: [:r | r activable.]. sort regles sort: sortBlock. removeAtIndex: aIndex regles removeAtIndex: aIndex. XMLLocation ^XMLLocation reInitialize regles do: [ :r | r initialize. ]. regles sort: sortBlock. asList self sort. ^ regles asList. instancierNouvelleRegle: aName si: aCondition alors: anAction sinon: anotherAction poids: aPoids | createVariable createInstance | createVariable := 'Smalltalk defineSharedVariable: #',aName, ' private: false', ' constant: false', ' category: ''TP - Systemes Experts''', ' initializer: ''nil'''. createInstance := aName,':= Regle new nom:','''', aName ,''' ; condition:','''', aCondition,''' ; action:','''', anAction,''' ; sinon:','''', anotherAction,''' ; poids:','''', aPoids,''''. Compiler evaluate: createVariable. regles add: (Compiler evaluate: createInstance). ReglesCollection chargement load: aFile | fileName | fileName := aFile asFilename asLogicalFileSpecification. fileName exists ifTrue: [ XMLLocation := fileName. ^self parseAllRules. "^ 'File ok'." ] ifFalse: [ ^ 'File doest not exists'. ]. saveXML |str newDoc regle nom condition action sinon elements attributes writer | newDoc := XML.Document new. newDoc addNode: (XML.PI name: 'xml' text: 'version="1.0" encoding="UTF-8" '). newDoc addNode: (XML.Element tag: 'regles'). regles do: [:it | nom := XML.Element tag: 'nom'. nom addNode: (XML.Text text: it nom). condition := XML.Element tag: 'si'. condition addNode: (XML.Text text: it condition). action := XML.Element tag: 'alors'. action addNode: (XML.Text text: it action). sinon := XML.Element tag: 'sinon'. sinon addNode: (XML.Text text: it sinon). elements := OrderedCollection new. elements add: nom;add: condition;add: action;add: sinon. attributes := OrderedCollection new. attributes add: (XML.Attribute name: 'poids' value: it poids printString). regle := XML.Element tag: 'regle' attributes: attributes elements: elements. newDoc root addNode: regle. ]. str := XMLLocation asFilename writeStream. writer := XML.SAXWriter new output: str. [newDoc saxDo: writer] ensure: [str close]. parseAllRules | parser xmlDocument root reglesCollection nom condition action sinon poids | regles := OrderedCollection new. "charge le parser xml" parser := XML.XMLParser new. "parse le fichier" parser validate: false. xmlDocument := parser parse: XMLLocation. "recupere la racine" root := xmlDocument root. "recupere toutes les regles" reglesCollection := (root elementsNamed: 'regle') select: [ :el | el isElement ]. "instancie les regles" reglesCollection do: [ :r | nom := ((r elementNamed: 'nom') elements at: 1) characterData. condition := ((r elementNamed: 'si')elements at: 1) characterData. action := ((r elementNamed: 'alors')elements at: 1) characterData. sinon := ((r elementNamed: 'sinon')elements at: 1) characterData. poids := (((r attributes) detect:[ :attr | attr tag type = 'poids' ]) value). self instancierNouvelleRegle: nom si: condition alors: action sinon: sinon poids: poids. ]. Regle class instance creation new "Answer a newly created and initialized instance." ^super new initialize Regle initialize-release initialize activable := true. hasBeenExecuted := false. ^self Regle accessing sinon: anObject sinon := anObject condition: anObject condition := anObject poids ^poids sinon ^sinon activer hasBeenExecuted = false ifTrue: [activable := true]. poids: anObject poids := anObject asNumber. activable ^activable. action ^action nom ^nom action: anObject action := anObject desactiver activable := false. nom: anObject nom := anObject condition ^condition Regle actions execute "execute la regle" (Compiler evaluate: condition) ifTrue: [Compiler evaluate: action.] ; ifFalse: [Compiler evaluate: sinon.]. "desactive la regle" activable := false. hasBeenExecuted := true. Regle printing printString ^nom. printDetails ^'@', poids printString, ' : ', nom, '\si (' ,condition , ')\alors [' , action , '] \sinon [', sinon, ']' . LanceurSystemeExpert class interface specs windowSpec "Tools.UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #label: 'Systeme expert' #min: #(#{Core.Point} 285 180 ) #max: #(#{Core.Point} 285 180 ) #bounds: #(#{Graphics.Rectangle} 640 400 925 580 ) ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.Rectangle} 16 26 135 53 ) #name: #ActionButton1 #model: #chargerFaits #label: 'Recharger les faits' #defaultable: true ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.Rectangle} 146 28 273 51 ) #name: #ActionButton2 #model: #managerFaits #label: 'Manager les faits' #defaultable: true ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.Rectangle} 11 85 140 108 ) #name: #ActionButton3 #model: #chargerRegles #label: 'Recharger les regles' #defaultable: true ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.Rectangle} 148 85 274 108 ) #name: #ActionButton4 #model: #managerRegles #label: 'Manager les regles' #defaultable: true ) #(#{UI.GroupBoxSpec} #layout: #(#{Graphics.Rectangle} 3 3 283 59 ) #name: #GroupBox1 #label: 'Base de faits' ) #(#{UI.GroupBoxSpec} #layout: #(#{Graphics.Rectangle} 4 60 283 116 ) #name: #GroupBox2 #label: 'Base de regles' ) #(#{UI.GroupBoxSpec} #layout: #(#{Graphics.Rectangle} 4 117 283 175 ) #name: #GroupBox3 #label: 'Moteur d''inference' ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.Rectangle} 81 144 198 168 ) #name: #ActionButton5 #model: #lancerMoteur #label: 'Lancer le moteur' #defaultable: true ) ) ) ) LanceurSystemeExpert class initialize-release openWithModel: m | x | x := self new. x model: m. m addDependent: x. x open. ^x LanceurSystemeExpert actions managerFaits FaitsManager openWithModel: model faits. ^self managerRegles RulesManager openWithModel: model regles. ^self lancerMoteur model moteur runWithRegles: model regles withFaits: model faits. ^self chargerRegles model regles parseAllRules. ^self chargerFaits model faits parseAllFacts. ^self LanceurSystemeExpert accessing model ^model model: anObject model := anObject RulesManager class interface specs windowSpec "Tools.UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #properties: #(#{UI.PropertyListDictionary} #sizeAutoSave true #sizeType #lastSavedSize #openType #advanced #positionType #screenCenter ) #label: 'Editeur de regles' #min: #(#{Core.Point} 410 440 ) #max: #(#{Core.Point} 410 440 ) #bounds: #(#{Graphics.Rectangle} 643 227 1053 667 ) ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.GroupBoxSpec} #layout: #(#{Graphics.Rectangle} 0 1 409 399 ) #name: #GroupBox1 #label: 'Regles' ) #(#{UI.SequenceViewSpec} #layout: #(#{Graphics.Rectangle} 3 20 407 211 ) #name: #List1 #model: #rules #callbacksSpec: #(#{UI.UIEventCallbackSubSpec} #valueChangeSelector: #rulesSelectionWidgetChanged ) #menu: #rightClicMenu #useModifierKeys: true #selectionType: #highlight ) #(#{UI.TextEditorSpec} #layout: #(#{Graphics.Rectangle} 3 215 406 395 ) #name: #TextEditor1 #flags: 46 #model: #ruleDetails #tabRequiresControl: true #isWrapped: false ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.Rectangle} 179 405 232 425 ) #name: #saveRules #model: #saveRules #label: 'Valider' #defaultable: true ) ) ) ) RulesManager class initialize-release openWithModel: m | x | x := self new. x model: m. x myInitialize. m addDependent: x. x open. ^x RulesManager class resources rightClicMenu "Tools.MenuEditor new openOnClass: self andSelector: #rightClicMenu" <resource: #menu> ^#(#{UI.Menu} #( #(#{UI.MenuItem} #rawLabel: 'Add new rule' #value: #createNewRule ) #(#{UI.MenuItem} #rawLabel: 'Remove rule' #enabled: false #value: #removeRule ) #(#{UI.MenuItem} #rawLabel: 'Edit' #enabled: false #value: #editRule ) ) #(2 1 ) nil ) decodeAsLiteralArray RulesManager aspects ruleDetails "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined. The initialization provided below may have been preempted by an initialize method." ^ruleDetails isNil ifTrue: [ruleDetails := String new asValue] ifFalse: [ruleDetails] rules "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined. The initialization provided below may have been preempted by an initialize method." ^rules isNil ifTrue: [rules := SelectionInList new] ifFalse: [rules] RulesManager initialize-release myInitialize rules := SelectionInList with: model asList. RulesManager accessing model: anObject model := anObject model ^model RulesManager actions createNewRule "create a new rule" model instancierNouvelleRegle: 'UN_NOM' si: '' alors: '' sinon: '' poids: '0'. "refresh the list" self rules list: model asList. "select the last rule (just created)" self rules selection: self rules list last. "edit the selection" RuleEditor openWithModel: (rules selection) fromRuleManager: self. saveRules model saveXML. self closeRequest. refreshList self rules list: model asList. editRule RuleEditor openWithModel: (rules selection) fromRuleManager: self. rulesSelectionWidgetChanged | menu editItem removeItem | menu := self builder menuAt: #rightClicMenu. editItem := (menu menuItemLabeled: 'Edit'). removeItem := (menu menuItemLabeled: 'Remove rule'). self rules selection isNil ifTrue: [ editItem disable. removeItem disable. ] ifFalse: [ editItem enable. removeItem enable. "ruleDetails := self rules selection printString asValue." ruleDetails value: self rules selection printDetails withCRs asComposedText. ]. removeRule model removeAtIndex: (rules selectionIndex). self rules list: model asList. self rulesSelectionWidgetChanged. FaitsManager class interface specs windowSpec "Tools.UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #label: 'Editeur de faits' #min: #(#{Core.Point} 407 310 ) #max: #(#{Core.Point} 407 310 ) #bounds: #(#{Graphics.Rectangle} 640 400 1047 710 ) ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.GroupBoxSpec} #layout: #(#{Graphics.Rectangle} 0 1 405 276 ) #name: #GroupBox1 #label: 'Faits' ) #(#{UI.SequenceViewSpec} #layout: #(#{Graphics.Rectangle} 4 16 403 273 ) #name: #List1 #model: #facts #callbacksSpec: #(#{UI.UIEventCallbackSubSpec} #valueChangeSelector: #factsSelectionWidgetChanged ) #menu: #rightClicMenu #useModifierKeys: true #selectionType: #highlight ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.Rectangle} 175 283 228 303 ) #name: #ActionButton1 #model: #saveFaits #label: 'Valider' #defaultable: true ) ) ) ) FaitsManager class initialize-release openWithModel: m | x | x := self new. x model: m. x myInitialize. m addDependent: x. x open. ^x FaitsManager class resources rightClicMenu "Tools.MenuEditor new openOnClass: self andSelector: #rightClicMenu" <resource: #menu> ^#(#{UI.Menu} #( #(#{UI.MenuItem} #rawLabel: 'Add new fact' #value: #createNewFact ) #(#{UI.MenuItem} #rawLabel: 'Remove fact' #enabled: false #value: #removeFact ) #(#{UI.MenuItem} #rawLabel: 'Edit' #enabled: false #value: #editFact ) ) #(2 1 ) nil ) decodeAsLiteralArray FaitsManager aspects facts "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined. The initialization provided below may have been preempted by an initialize method." ^facts isNil ifTrue: [facts := SelectionInList new] ifFalse: [facts] FaitsManager accessing model: anObject model := anObject model ^model FaitsManager initialize-release myInitialize facts := SelectionInList with: model asList. FaitsManager actions editFact FaitEditor openWithModel: (facts selection). createNewFact "create a new fact" model instancierNouveauFait: 'NOM_DU_FAIT' details: 'EXPLICATION'. "refresh the list" self facts list: model asList. "select the last fact (just created" self facts selection: self facts list last. "edit the selection" FaitEditor openWithModel: (facts selection). factsSelectionWidgetChanged | menu editItem removeItem | menu := self builder menuAt: #rightClicMenu. editItem := (menu menuItemLabeled: 'Edit'). removeItem := (menu menuItemLabeled: 'Remove fact'). self facts selection isNil ifTrue: [ editItem disable. removeItem disable. ] ifFalse: [ editItem enable. removeItem enable. ] removeFact model removeAtIndex: (facts selectionIndex). self facts list: model asList. self factsSelectionWidgetChanged. saveFaits model saveXML. self closeRequest. FaitsManager updating update: aValue self facts list: model asList. Moteur class instance creation new "Answer a newly created and initialized instance." ^super new initialize Moteur accessing runWithRegles: regles withFaits: faits | allActivablesRules | faits reInitialize. regles reInitialize. allActivablesRules := regles allActivableRules. [((faits problemeTrouve size < 1) & (allActivablesRules size > 0))] whileTrue: [ (allActivablesRules at: 1) execute. allActivablesRules := regles allActivableRules. faits changed. ]. (faits problemeTrouve size > 0) ifTrue: [ "Transcript show: (faits problemeTrouve at: 1)." Dialog warn: (faits problemeTrouve at: 1) texte withCRs. ]. Moteur initialize-release initialize "Initialize a newly created instance. This method must answer the receiver." " *** Replace this comment with the appropriate initialization code *** " ^self FaitEditor class interface specs windowSpec "Tools.UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #label: 'Editeur de faits' #min: #(#{Core.Point} 200 300 ) #max: #(#{Core.Point} 200 300 ) #bounds: #(#{Graphics.Rectangle} 640 400 840 700 ) ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.GroupBoxSpec} #layout: #(#{Graphics.Rectangle} 1 8 195 267 ) #name: #GroupBox1 #label: 'Faits' ) #(#{UI.LabelSpec} #layout: #(#{Core.Point} 11 37 ) #name: #Label1 #label: 'Nom :' ) #(#{UI.LabelSpec} #layout: #(#{Core.Point} 74 71 ) #name: #Label2 #label: 'Details' ) #(#{UI.InputFieldSpec} #layout: #(#{Graphics.Rectangle} 54 35 188 58 ) #name: #InputField1 #model: #name ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.Rectangle} 70 274 123 294 ) #name: #ActionButton1 #model: #valider #label: 'Valider' #defaultable: true ) #(#{UI.TextEditorSpec} #layout: #(#{Graphics.Rectangle} 6 88 193 264 ) #name: #TextEditor1 #model: #texte #tabRequiresControl: true ) ) ) ) FaitEditor class initialize-release openWithModel: m | x | x := self new. x model: m. x myInitialize. m addDependent: x. x open. ^x FaitEditor aspects texte "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined. The initialization provided below may have been preempted by an initialize method." ^texte isNil ifTrue: [texte := String new asValue] ifFalse: [texte] name "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined. The initialization provided below may have been preempted by an initialize method." ^name isNil ifTrue: [name := String new asValue] ifFalse: [name] FaitEditor initialize-release myInitialize name := model nom asValue. texte := model texte asValue. FaitEditor accessing model ^model model: anObject model := anObject FaitEditor actions valider model nom: (name value copyReplaceAll: ' ' with: '_'). model texte: (texte value copyReplaceAll: '''' with: ''''''). self closeRequest. ^self RuleEditor class interface specs windowSpec "Tools.UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #label: 'Editeur de regles' #min: #(#{Core.Point} 650 230 ) #max: #(#{Core.Point} 650 230 ) #bounds: #(#{Graphics.Rectangle} 627 400 1277 630 ) ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.GroupBoxSpec} #layout: #(#{Graphics.Rectangle} 1 2 647 184 ) #name: #GroupBox1 #label: 'Regles' ) #(#{UI.LabelSpec} #layout: #(#{Core.Point} 9 32 ) #name: #Label1 #label: 'Nom :' ) #(#{UI.LabelSpec} #layout: #(#{Core.Point} 9 62 ) #name: #Label2 #label: 'Si : ' ) #(#{UI.LabelSpec} #layout: #(#{Core.Point} 9 92 ) #name: #Label3 #label: 'Alors : ' ) #(#{UI.InputFieldSpec} #layout: #(#{Graphics.Rectangle} 57 29 642 54 ) #name: #InputField1 #model: #nom ) #(#{UI.InputFieldSpec} #layout: #(#{Graphics.Rectangle} 57 59 641 82 ) #name: #InputField2 #model: #condition ) #(#{UI.InputFieldSpec} #layout: #(#{Graphics.Rectangle} 57 89 642 113 ) #name: #InputField3 #model: #action ) #(#{UI.LabelSpec} #layout: #(#{Core.Point} 8 151 ) #name: #Label4 #label: 'Poids :' ) #(#{UI.SpinButtonSpec} #layout: #(#{Graphics.Rectangle} 58 149 158 171 ) #name: #SpinButton1 #model: #poids #type: #number #formatString: '0' #low: 0 #high: 1000 #interval: 1 ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.Rectangle} 263 198 383 219 ) #name: #ActionButton1 #model: #valideRule #label: 'Valider' #defaultable: true ) #(#{UI.LabelSpec} #layout: #(#{Core.Point} 9 122 ) #name: #Label5 #label: 'Sinon : ' ) #(#{UI.InputFieldSpec} #layout: #(#{Graphics.Rectangle} 57 119 642 143 ) #name: #InputField4 #model: #sinon ) ) ) ) RuleEditor class initialize-release openWithModel: m fromRuleManager: rm | x | x := self new. x model: m. x ruleManager: rm. x myInitialize. m addDependent: x. x open. ^x RuleEditor aspects poids "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined. The initialization provided below may have been preempted by an initialize method." ^poids isNil ifTrue: [poids := 0 asValue] ifFalse: [poids] sinon "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined. The initialization provided below may have been preempted by an initialize method." ^sinon isNil ifTrue: [sinon := String new asValue] ifFalse: [sinon] nom "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined. The initialization provided below may have been preempted by an initialize method." ^nom isNil ifTrue: [nom := String new asValue] ifFalse: [nom] action "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined. The initialization provided below may have been preempted by an initialize method." ^action isNil ifTrue: [action := String new asValue] ifFalse: [action] condition "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined. The initialization provided below may have been preempted by an initialize method." ^condition isNil ifTrue: [condition := String new asValue] ifFalse: [condition] RuleEditor initialize-release myInitialize nom := model nom asValue. action := model action asValue. condition := model condition asValue. sinon := model sinon asValue. poids := model poids asNumber asValue. RuleEditor accessing model ^model ruleManager: anObject ruleManager := anObject ruleManager ^ruleManager model: anObject model := anObject RuleEditor actions valideRule model poids: (poids value) printString. (action value) = '' ifTrue: [ model action: ' '] ; ifFalse: [ model action: action value ]. (condition value) = '' ifTrue: [ model condition: '51 = 69'] ; ifFalse: [ model condition: condition value ]. (nom value) = '' ifTrue: [ model nom: 'GIMME_A_NAME'] ; ifFalse: [ model nom: (nom value copyReplaceAll: ' ' with: '_') ]. (sinon value) = '' ifTrue: [ model sinon: ' '] ; ifFalse: [ model sinon: sinon value ]. ruleManager refreshList. self closeRequest. ^self FaitsCollection class instance creation new ^super new initialize FaitsCollection initialize-release initialize ^self FaitsCollection accessing problemeTrouve ^(faits select: [ :f | (f estUnProbleme) ]) select: [ :f | f estVrai ]. reInitialize faits do: [ :f | f Inconnu. ]. removeAtIndex: anIndex faits removeAtIndex: anIndex. asList ^faits asList. FaitsCollection chargement load: aFile | fileName | fileName := aFile asFilename asLogicalFileSpecification. fileName exists ifTrue: [ XMLLocation := fileName. ^self parseAllFacts. "^ 'File ok'." ] ifFalse: [ ^ 'File doest not exists'. ]. saveXML |str newDoc nom etat elements fact writer | newDoc := XML.Document new. newDoc addNode: (XML.PI name: 'xml' text: 'version="1.0" encoding="UTF-8" '). newDoc addNode: (XML.Element tag: 'facts'). faits do: [:it | nom := XML.Element tag: 'nom'. nom addNode: (XML.Text text: it nom). etat := XML.Element tag: 'texte'. etat addNode: (XML.Text text: it texte). elements := OrderedCollection new. elements add: nom;add: etat. fact := XML.Element tag: 'fact' elements: elements. newDoc root addNode: fact. ]. str := XMLLocation asFilename writeStream. writer := XML.SAXWriter new output: str. [newDoc saxDo: writer] ensure: [str close]. parseAllFacts | parser xmlDocument root factsCollection nom texte nomElement texteElement | faits := OrderedCollection new. "charge le parser xml" parser := XML.XMLParser new. "parse le fichier" parser validate: false. xmlDocument := parser parse: XMLLocation. "recupere la racine" root := xmlDocument root. "recupere tous les faits" factsCollection := (root elementsNamed: 'fact') select: [ :el | el isElement ]. "initialise les faits" factsCollection do: [:f | nom := 'UNDEFINED'. texte := ' '. nomElement := (f elementNamed: 'nom') elements. texteElement := (f elementNamed: 'texte') elements. (nomElement size > 0) ifTrue: [nom := (nomElement at: 1) characterData ]. (texteElement size > 0) ifTrue: [texte := (texteElement at: 1) characterData ]. self instancierNouveauFait: nom details: texte. ]. instancierNouveauFait: nom details: texte | createVariable createInstance type pos | type := ''. pos := (nom indexOf: $_)-1. pos > 1 ifTrue: [ type := nom copyFrom: 1 to: pos. ]. createVariable := 'Smalltalk defineSharedVariable: #',nom, ' private: false', ' constant: false', ' category: ''TP - Systemes Experts''', ' initializer: ''nil'''. createInstance := nom,':= Fait new type:','''', type ,''' ; nom:','''',nom,''' ; texte:', '''', texte, ''''. Compiler evaluate: createVariable. faits add: (Compiler evaluate: createInstance). Fait class instance creation new ^super new initialize Fait testing estUnProbleme ^ (type = 'PROBLEME'). estVrai "si le fait est inconnu" (self estInconnu & self estUnProbleme not) ifTrue: [ (Dialog confirm: nom, ' est valide ?' withCRs) ifTrue: [etat := 1] ; ifFalse: [etat := 0]. ]. ^(etat = 1) estFaux "si le fait est inconnu" (self estInconnu & self estUnProbleme not) ifTrue: [ (Dialog confirm: nom, ' est invalide ?' withCRs) ifTrue: [etat := 0] ; ifFalse: [etat := 1]. ]. ^(etat = 0) estInconnu ^(etat = -1). Fait printing printString ^self asString. printEtat (etat = -1) ifTrue: [^'Inconnu']. (etat = 0) ifTrue: [^'Faux']. (etat =1) ifTrue: [^'Vrai']. ^'?'. asString ^nom, ' -> ', (self printEtat). Fait accessing nom: aNom nom := aNom. type: aString type := aString. nom ^nom. etat ^etat. Faux etat := 0. texte ^texte. texte: unTexte texte := unTexte. Vrai etat := 1. Inconnu etat := -1. Fait initialize-release initialize self Inconnu. ^self LanceurModel class initialize-release new ^super new initialize. LanceurModel initialize-release initialize " *** Replace this comment with the appropriate initialization code *** " ^self LanceurModel accessing moteur: anObject moteur := anObject regles ^regles moteur ^moteur faits ^faits faits: anObject faits := anObject regles: anObject regles := anObject