Initial commit

This commit is contained in:
oscarz
2024-08-12 10:49:20 +08:00
parent 3002510aaf
commit 00fd0adf89
331 changed files with 53210 additions and 130 deletions

View File

@ -7,16 +7,127 @@
import Foundation
struct GrammarRes {
var tPlain : String
var tType : String
var tReason : String
var tCorrection : [String]
// GrammarResCodableJSON
struct GrammarRes: Codable {
var plain: String
var type: String
var reason: String
var correction: [String]
}
struct GrammarData {
var tInputText : String
var tCorrectText : String
var tResult : [GrammarRes]
enum GrammarResType : String {
case ok = "ok"
case grammar = "grammar"
case spell = "spell"
}
// tResultGrammarData
class GrammarData {
var inputText: String
var correctText: String
var results: [GrammarRes]
init(inputText: String, correctText: String, tResult: [GrammarRes] = []) {
self.inputText = inputText
self.correctText = correctText
self.results = tResult
}
// tResult
func parseResult(from jsonString: String) -> Bool {
//
let cleanedString = jsonString.trimmingCharacters(in: .whitespacesAndNewlines).replacingOccurrences(of: ", ]", with: "]")
guard let jsonData = cleanedString.data(using: .utf8) else {
print("Error: Cannot create jsonData")
return false
}
do {
// JSON
self.results = try JSONDecoder().decode([GrammarRes].self, from: jsonData)
return true
} catch {
print("Error: \(error)")
return false
}
}
}
extension GrammarData {
// DemoGrammarData
static func demoInstance() -> GrammarData {
//let demoInputText = "This is a demo text with more complex grammar checking algorithm of the pro version. This app have been designed to help you to write correctly and appear more professional. I work really hard to make this app as god as possible. If you are happy with the results, please consider supporting the app by subscribing to the PRO plan. The text writen here is to show you how much the app is capable of with the pro version. is this something you would like to use? "
let demoInputText = "Paris are hosting the Olypmic Games in 2024. Athletes from arround the world comes to compet in many sports, wich makes it an excting event to watch."
let demoCorrectText = demoInputText
// Demo
let demoErrors = [
GrammarRes(plain: "This is a demo text with more complex grammar checking algorithm of the pro version.",
type: "ok",
reason: "",
correction: []),
GrammarRes(
plain: "This app have",
type: "grammar",
reason: "subject-verb agreement",
correction: ["This app has"]
),
GrammarRes(
plain: "been designed to help you to write correctly and appear more professional.",
type: "ok",
reason: "",
correction: []
),
GrammarRes(
plain: "I work really hard",
type: "ok",
reason: "",
correction: []
),
GrammarRes(
plain: "to make this app as god",
type: "spell",
reason: "typo",
correction: ["as good"]
),
GrammarRes(
plain: "as possible.",
type: "ok",
reason: "",
correction: []
),
GrammarRes(
plain: "If you are happy with the results, please consider supporting the app by subscribing to the PRO plan.",
type: "ok",
reason: "",
correction: []
),
GrammarRes(
plain: "The text writen",
type: "spell",
reason: "misspelling",
correction: ["written"]
),
GrammarRes(
plain: "here is to show you how much the app is capable of with the pro version.",
type: "ok",
reason: "",
correction: []
),
GrammarRes(
plain: "is this something you would like to use?",
type: "grammar",
reason: "capitalization",
correction: ["Is this something you would like to use?"]
)
]
return GrammarData(inputText: demoInputText, correctText: demoCorrectText, tResult: demoErrors)
}
}