Object subclass: #Index instanceVariableNames: 'theDict ' classVariableNames: '' poolDictionaries: '' category: 'Serie-4'! !Index methodsFor: 'accessing'! at: word "Returns a set which contains all line numbers where word appears. If word was never defined with at:add: the behaviour is undefined. (Dictionary will raise a Signal)" ^theDict at: word! words "Returns a collection (actually a Set) of all words that have been previously added with at:add:" ^theDict keys! ! !Index methodsFor: 'adding'! at: word add: lineNumber "Adds word to the dictionary and stores it's lineNumber" | lineNumberSet | theDict isNil ifTrue: [ theDict := Dictionary new ]. lineNumberSet := theDict at: word ifAbsent: [ Set new ]. lineNumberSet add: lineNumber. theDict at: word put: lineNumberSet.! ! ApplicationModel subclass: #Indexer instanceVariableNames: 'fileName lines words index ' classVariableNames: '' poolDictionaries: '' category: 'Serie-4'! !Indexer methodsFor: 'actions'! index | reader | reader := TextFileReader on: (self fileName value). index := Index new. [ reader atEnd ] whileFalse: [|word| word := reader nextWord. index at: word add: (reader lineNumber)]. words list: index words asList.! ! !Indexer methodsFor: 'aspects'! fileName "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined." ^fileName! lines "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined." ^lines! words "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined." ^words! ! !Indexer methodsFor: 'change messages'! changedWord | word | word := self words selection. lines list: (word isNil ifTrue: [ List new ] ifFalse: [ (index at: word) asList ])! ! !Indexer methodsFor: 'initialize-release'! initialize words := SelectionInList with: (List new). words selectionIndexHolder onChangeSend: #changedWord to: self. lines := SelectionInList with: (List new). fileName := '/home/schinz/textes/poeme' asValue.! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! Indexer class instanceVariableNames: ''! !Indexer class methodsFor: 'interface specs'! windowSpec "UIPainter new openOnClass: self andSelector: #windowSpec" ^#(#FullSpec #window: #(#WindowSpec #label: 'Utilitaire d''indexation' #bounds: #(#Rectangle 248 247 617 589 ) ) #component: #(#SpecCollection #collection: #( #(#LabelSpec #layout: #(#Point 10 10 ) #label: 'Nom de fichier' ) #(#LabelSpec #layout: #(#Point 10 40 ) #label: 'Mots' ) #(#LabelSpec #layout: #(#LayoutOrigin 5 0.5 40 0 ) #label: 'Lignes' ) #(#InputFieldSpec #layout: #(#LayoutFrame 110 0 10 0 -10 1 30 0 ) #model: #fileName ) #(#SequenceViewSpec #layout: #(#LayoutFrame 10 0 65 0 -5 0.5 -50 1 ) #model: #words ) #(#ActionButtonSpec #layout: #(#LayoutFrame 10 0 -45 1 -5 0.5 -10 1 ) #model: #index #label: 'Indexer' #defaultable: true ) #(#ActionButtonSpec #layout: #(#LayoutFrame 5 0.5 -45 1 -10 1 -10 1 ) #model: #closeRequest #label: 'Quitter' #defaultable: true ) #(#SequenceViewSpec #layout: #(#LayoutFrame 5 0.5 65 0 -10 1 -50 1 ) #model: #lines ) ) ) )! ! Object subclass: #BoundedStack instanceVariableNames: 'anArr nextpos ' classVariableNames: 'StackEmptySignal StackFullSignal ' poolDictionaries: '' category: 'Serie-4'! !BoundedStack methodsFor: 'testing'! isEmpty ^(nextpos=1)! isFull ^(nextpos=((anArr size)+1) )! ! !BoundedStack methodsFor: 'accessing'! pop StackFullSignal isNil ifTrue: [ self class initialize ]. nextpos > 1 ifTrue: [ nextpos := nextpos-1. ^(anArr at: nextpos). ] ifFalse: [ StackEmptySignal raise ]! push: element StackFullSignal isNil ifTrue: [ self class initialize ]. nextpos <= (anArr size) ifTrue: [ anArr at: nextpos put: element. nextpos := nextpos+1. ] ifFalse: [ StackFullSignal raise ] "WANTED: raiseErrorString: ('BoundedStack size only ' & (Array size))"! ! !BoundedStack methodsFor: 'initialize-release'! initialize: size anArr := Array new: size. nextpos := 1.! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! BoundedStack class instanceVariableNames: ''! !BoundedStack class methodsFor: 'signal constants'! stackEmptySignal ^StackEmptySignal! stackFullSignal ^StackFullSignal! ! !BoundedStack class methodsFor: 'initialization'! initialize "Class initialization. Sets StackEmptySignal and StackFullSignal to newly created signals." StackEmptySignal := Object errorSignal newSignal notifierString: 'Stack is Empty '; nameClass: self message: #stackEmptySignal. StackFullSignal := Object errorSignal newSignal notifierString: 'Stack is Full '; nameClass: self message: #stackFullSignal.! ! !BoundedStack class methodsFor: 'instance-creation'! new: size ^super new initialize: size! ! Object subclass: #BoundedQueue instanceVariableNames: 'anArr first last size ' classVariableNames: 'QueueEmptySignal QueueFullSignal ' poolDictionaries: '' category: 'Serie-4'! !BoundedQueue methodsFor: 'initialize-release'! initialize: isize anArr := Array new: isize. first := 1. last := 0. size := 0.! ! !BoundedQueue methodsFor: 'accessing'! dequeue | ret_pos | QueueEmptySignal isNil ifTrue: [ self class initialize_signals ]. size>0 ifTrue: [ ret_pos:=first. first<(anArr size) ifTrue: [ first:=first+1 ] ifFalse: [ first:=1 ]. size:=size-1. ^anArr at: ret_pos. ] ifFalse: [ QueueEmptySignal raise ]! enqueue: element QueueFullSignal isNil ifTrue: [ self class initialize_signals ]. size < (anArr size) ifTrue: [ last < (anArr size) ifTrue: [ last:=last+1 ] ifFalse: [ last:=1 ]. anArr at: last put: element. size:=size+1. ] ifFalse: [ QueueFullSignal raise ]! ! !BoundedQueue methodsFor: 'testing'! isEmpty ^size=0! isFull ^size=(anArr size)! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! BoundedQueue class instanceVariableNames: ''! !BoundedQueue class methodsFor: 'signal constants'! queueEmptySignal ^QueueEmptySignal! queueFullSignal ^QueueFullSignal! ! !BoundedQueue class methodsFor: 'initialization'! initialize self initialize_signals! initialize_signals "Class initialization. Sets StackEmptySignal and StackFullSignal to newly created signals." QueueEmptySignal := Object errorSignal newSignal notifierString: 'Queue is Empty '; nameClass: self message: #queueEmptySignal. QueueFullSignal := Object errorSignal newSignal notifierString: 'Queue is Full '; nameClass: self message: #queueFullSignal.! ! !BoundedQueue class methodsFor: 'instance-creation'! new "Unfortunately, the old new can still be used. This results in chaos, because the object remain uninitialized. -- An alternative would have been to call new: 10 with a default value." Object errorSignal raiseErrorString: 'Use new: instead new!!'! new: isize ^((super new) initialize: isize)! ! Object subclass: #TextFileReader instanceVariableNames: 'stream lineNumber prevLineNumber ' classVariableNames: '' poolDictionaries: '' category: 'Serie-4'! !TextFileReader methodsFor: 'accessing'! lineNumber ^prevLineNumber! nextChar | nextChar | nextChar := stream next. nextChar = (Character cr) ifTrue: [ lineNumber := lineNumber + 1 ]. ^nextChar! nextWord | word nextChar | [ stream atEnd or: [ nextChar := self nextChar. nextChar isLetter ]] whileFalse. prevLineNumber := lineNumber. word := String new. [ stream atEnd or: [ nextChar isLetter not ] ] whileFalse: [word := word, (String with: nextChar). nextChar := self nextChar]. ^word! ! !TextFileReader methodsFor: 'testing'! atEnd ^stream atEnd! ! !TextFileReader methodsFor: 'private initialize'! initializeOn: aFileName stream := aFileName asFilename readStream. prevLineNumber := 1. lineNumber := 1! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! TextFileReader class instanceVariableNames: ''! !TextFileReader class methodsFor: 'instance creation'! on: aFileName ^super new initializeOn: aFileName! ! BoundedStack initialize! BoundedQueue initialize!