-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.swift
38 lines (24 loc) · 996 Bytes
/
main.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
//
// main.swift
// Markov Chains
//
import Foundation
let m = Markov(display: MarkovDisplayStrategy(), generationStrategy: SecondOrderGenerator())
let con = Console(expectedArgs: m.numArgs, display: m.display)
// ensure all conditions met before trying to do it
guard let numSentencesAsString = con.getArg(Markov.Arguments.SentenceNumber.rawValue),
//convert string user entered into an int
let numSentences = Int(numSentencesAsString),
//get filename
let filename = con.getArg(Markov.Arguments.FileName.rawValue),
// get file contents
let fileContents = try? String(contentsOfFile: filename, encoding: NSUTF8StringEncoding) else{
exit(EXIT_FAILURE)
}
print("-------")
//second order
print(m.generateFromText(fileContents, numSentences: numSentences))
print("-------")
//change to first order for comparison
m.setGenerationStrategy(FirstOrderGenerator())
print(m.generateFromText(fileContents, numSentences: numSentences))