-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDictionaryRecordNotesParser.swift
More file actions
146 lines (132 loc) · 11.5 KB
/
DictionaryRecordNotesParser.swift
File metadata and controls
146 lines (132 loc) · 11.5 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
Licensed under the MIT license:
Copyright (c) 2019 Michal Duda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import Foundation
class DictionaryRecordNotesParser {
static let wordClassMapping: [String: String] = ["n:": NSLocalizedString("nouns", comment: "word class: nouns"),
"adj:": NSLocalizedString("adjectives", comment: "word class: adjectives"),
"pron:": NSLocalizedString("pronouns", comment: "word class: pronouns"),
"num:": NSLocalizedString("numerals", comment: "word class: numerals"),
"v:": NSLocalizedString("verbs", comment: "word class: verbs"),
"adv:": NSLocalizedString("adverbs", comment: "word class: adverbs"),
"prep:": NSLocalizedString("prepositions", comment: "word class: prepositions"),
"conj:": NSLocalizedString("conjunctions", comment: "word class: conjunctions"),
"interj:": NSLocalizedString("interjections", comment: "word class: interjections")]
static let categoryMapping = ["[bás.]": NSLocalizedString("poeticism", comment: "word category: poeticism"),
"[dět.]": NSLocalizedString("childish", comment: "word category: childish"),
"[fráz.]": NSLocalizedString("phrase", comment: "word category: phrase"),
"[frsl.]": NSLocalizedString("phrasal verb", comment: "word category: phrasal verb"),
"[hovor.]": NSLocalizedString("colloquially", comment: "word category: colloquially"),
"[id.]": NSLocalizedString("idiom", comment: "word category: idiom"),
"[jmén.]": NSLocalizedString("proper name", comment: "word category: proper name"),
"[kniž.]": NSLocalizedString("literary", comment: "word category: literary"),
"[neobv.]": NSLocalizedString("uncommon", comment: "word category: uncommon"),
"[neprav.]": NSLocalizedString("irregular verb", comment: "word category: irregular verb"),
"[obec.]": NSLocalizedString("generic", comment: "word category: generic"),
"[přen.]": NSLocalizedString("metaphorically", comment: "word category: metaphorically"),
"[slang.]": NSLocalizedString("slangily", comment: "word category: slangily"),
"[vulg.]": NSLocalizedString("vulgarism", comment: "word category: vulgarism"),
"[zast.]": NSLocalizedString("old use, archaic", comment: "word category: old use, archaic"),
"[zkr.]": NSLocalizedString("abbreviation", comment: "word category: abbreviation"),
"[žert.]": NSLocalizedString("jokingly", comment: "word category: jokingly"),
"[amer.]": NSLocalizedString("American", comment: "word category: American"),
"[aus.]": NSLocalizedString("Australian", comment: "word category: Australian"),
"[brit.]": NSLocalizedString("British", comment: "word category: British"),
"[skot.]": NSLocalizedString("Scottish", comment: "word category: Scottish")]
static let areaMapping = ["[fin.]": NSLocalizedString("finance", comment: "word area: finance"),
"[hist.]": NSLocalizedString("historical expression or name", comment: "word area: historical expression or name"),
"[hud.]": NSLocalizedString("musical terminology", comment: "word area: musical terminology"),
"[lingv.]": NSLocalizedString("linguistic", comment: "word area: linguistic"),
"[myt.]": NSLocalizedString("mythological", comment: "word area: mythological"),
"[náb.]": NSLocalizedString("word related to religion", comment: "word area: word related to religion"),
"[polit.]": NSLocalizedString("political expression", comment: "word area: political expression"),
"[práv.]": NSLocalizedString("legal", comment: "word area: legal"),
"[psych.]": NSLocalizedString("psychological", comment: "word area: psychological"),
"[sex.]": NSLocalizedString("sexual expression", comment: "word area: sexual expression"),
"[sport.]": NSLocalizedString("sport related locution", comment: "word area: sport related locution"),
"[astr.]": NSLocalizedString("astronomy", comment: "word area: astronomy"),
"[bio.]": NSLocalizedString("biology", comment: "word area: biology"),
"[bot.]": NSLocalizedString("botany", comment: "word area: botany"),
"[eko.]": NSLocalizedString("ecology", comment: "word area: ecology"),
"[fyz.]": NSLocalizedString("physics", comment: "word area: physics"),
"[geod.]": NSLocalizedString("geodesy", comment: "word area: geodesy"),
"[geol.]": NSLocalizedString("geology", comment: "word area: geology"),
"[chem.]": NSLocalizedString("chemistry", comment: "word area: chemistry"),
"[mat.]": NSLocalizedString("mathematics", comment: "word area: mathematics"),
"[med.]": NSLocalizedString("medical term", comment: "word area: medical term"),
"[meteo.]": NSLocalizedString("meteorology", comment: "word area: meteorology"),
"[opt.]": NSLocalizedString("optics", comment: "word area: optics"),
"[zem.]": NSLocalizedString("geography", comment: "word area: geography"),
"[zoo.]": NSLocalizedString("zoology", comment: "word area: zoology"),
"[cukr.]": NSLocalizedString("sugar industry", comment: "word area: sugar industry"),
"[dřev.]": NSLocalizedString("wood industry", comment: "word area: wood industry"),
"[el.]": NSLocalizedString("electrical engineering", comment: "word area: electrical engineering"),
"[horn.]": NSLocalizedString("mining, mineralogy", comment: "word area: mining, mineralogy"),
"[hut.]": NSLocalizedString("metallurgy", comment: "word area: metallurgy"),
"[it.]": NSLocalizedString("information technology", comment: "word area: information technology"),
"[jad.]": NSLocalizedString("nuclear physics, technology", comment: "word area: nuclear physics, technology"),
"[ker.]": NSLocalizedString("ceramic industry", comment: "word area: ceramic industry"),
"[kož.]": NSLocalizedString("tanning industry", comment: "word area: tanning industry"),
"[lak.]": NSLocalizedString("coating technology", comment: "word area: coating technology"),
"[potr.]": NSLocalizedString("food processing", comment: "word area: food processing"),
"[stav.]": NSLocalizedString("building industry, architecture", comment: "word area: building industry, architecture"),
"[tech.]": NSLocalizedString("technical domain", comment: "word area: technical domain"),
"[text.]": NSLocalizedString("textile industry", comment: "word area: textile industry"),
"[voj.]": NSLocalizedString("military terminology", comment: "word area: military terminology"),
"[zeměděl.]": NSLocalizedString("term from the field of agriculture", comment: "word area: term from the field of agriculture"),
"[aut.]": NSLocalizedString("automotive industry", comment: "word area: automotive industry"),
"[let.]": NSLocalizedString("aviation", comment: "word area: aviation"),
"[lod.]": NSLocalizedString("boats, shipping", comment: "word area: boats, shipping"),
"[žel.]": NSLocalizedString("railway transport", comment: "word area: railway transport")]
let record: DictionaryRecord
let wordClass: String
let category: String
let area: String
let plural: String
init(record: DictionaryRecord) {
self.record = record
let notes: [String] = self.record.notes.lowercased().components(separatedBy: " ")
var internalWordClass: String?
var internalCategory: [String] = [String]()
var internalArea: [String] = [String]()
var internalPlural: String?
for note in notes {
if internalWordClass == nil {
internalWordClass = DictionaryRecordNotesParser.wordClassMapping[note]
}
if let value = DictionaryRecordNotesParser.categoryMapping[note] {
internalCategory.append(value)
}
if let value = DictionaryRecordNotesParser.areaMapping[note] {
internalArea.append(value)
}
if internalPlural == nil && "pl." == note {
internalPlural = NSLocalizedString("yes", comment: "is plural?")
}
}
wordClass = internalWordClass ?? NSLocalizedString("not specified", comment: "word class is not specified")
category = ArrayResolver.resolve(first: internalCategory,
second: NSLocalizedString("generic",
comment: "word category: generic")).joined(separator: ", ")
area = ArrayResolver.resolve(first: internalArea,
second: NSLocalizedString("not specified",
comment: "area is not specified")).joined(separator: ", ")
plural = internalPlural ?? NSLocalizedString("no", comment: "is plural?")
}
}