-
Notifications
You must be signed in to change notification settings - Fork 0
/
Markov.swift
43 lines (32 loc) · 1.07 KB
/
Markov.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// Markov.swift
// Markov Chains
//
import Foundation
class Markov {
var display : displayStrategy //usage message
private var generator : MarkovGenerator //does the generation itself
// accessor
func setGenerationStrategy(newStrat : MarkovGenerator) -> Void{
self.generator = newStrat
}
// the arguements expected from the user in their position inthe CLI too
enum Arguments : Int {
case FileName = 1
case SentenceNumber
case Final
}
var numArgs : Int {
get{
return Arguments.Final.rawValue
}
}
init(display: displayStrategy, generationStrategy: MarkovGenerator){
self.display = display
self.generator = generationStrategy
}
// does the text generation
func generateFromText(sourceText: String, numSentences: Int) -> String{
return generator.generate(generator.createMapFromText(sourceText), sentences: numSentences, endOfSentenceCharacterSet: NSCharacterSet(charactersInString: ".?!"))
}
}