Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //First version of Io Markov Chain generator
- //jamis:~/Work/Io rodney$ io Markov2.io
- //proposition. 5 Propositions are truth-functions of atomic facts. 3 The logical picture of //proposition. 7 Whereof one must be silent.
- //!! Exception: nil does not respond to 'pickWord'// ---------
- //nil pickWord Markov2.io 85
- // WordPredictor pickNext Markov2.io 98
- Message do(
- evalLightMethod := method(scope,
- call message arguments slice(1) foreach(i, arg,
- scope setSlot(arguments at(i) name, call sender doMessage(arg, call sender))
- )
- scope doMessage(self arguments last, scope)
- )
- )
- Map update := method(key,
- atPut(key,
- value := if(hasKey(key),
- call argAt(2) evalLightMethod(call sender, at(key))
- ,
- call evalArgAt(1)
- )
- )
- value
- )
- List foreachPair := method(
- msg := call message
- last := first
- slice(1) foreach(v,
- msg evalLightMethod(call sender, last, v)
- last = v
- )
- )
- WordCount := Object clone do(
- newSlot("counts")
- newSlot("total", 0)
- init := method(
- counts = Map clone
- )
- addWord := method(word,
- counts update(word, 1, (c, c + 1))
- total = total + 1
- )
- asString := method(
- r := Sequence clone
- counts foreach(word, count,
- r appendSeq(word, "(", count, ") ")
- )
- r
- )
- pickWord := method(
- words := counts keys
- loop(
- word := words anyOne
- if(counts at(word) >= Random value * total, break)
- )
- word
- )
- )
- WordPredictor := Object clone do(
- newSlot("words")
- init := method(
- words = Map clone
- )
- addWordPair := method(first, second,
- words atIfAbsentPut(first, WordCount clone) addWord(second)
- )
- asString := method(
- r := Sequence clone
- words foreach(word, wordCounts,
- r appendSeq(word, ": ", wordCounts asString, "\n")
- )
- r
- )
- anyWord := method(
- words keys anyOne
- )
- pickNext := method(current,
- words at(current) pickWord
- )
- )
- words := WordPredictor clone
- File clone setPath("thecore1_5.txt") contents splitNoEmpties foreachPair(first, second,
- words addWordPair(first, second)
- )
- word := words anyWord
- 100 repeatTimes(
- write(word, " ")
- word = words pickNext(word)
- )
- writeln
Add Comment
Please, Sign In to add comment