-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBirthDeathCategories.cs
More file actions
263 lines (232 loc) · 10 KB
/
BirthDeathCategories.cs
File metadata and controls
263 lines (232 loc) · 10 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using WikiAccess;
namespace WikidataBioValidation
{
class BirthDeathCategories
{
public BirthDeathCategoriesErrorLog CategoryErrors { get; set; }
private string WhereDates;
private List<string> Categories;
private Wikidate DOB;
private Wikidate DOD;
private bool BirthYearCat;
private bool BirthDecadeCat;
private bool BirthYearNotKnownCat;
private bool BirthDateNotAccurateCat;
private bool DeathYearNotKnownCat;
private bool DeathDateNotAccurateCat;
private bool DeathYearCat;
private bool DeathDecadeCat;
private bool LivingPeopleCat;
private bool BirthLivingPeopleCat;
public BirthDeathCategories(string wheredates, List<string> categories, Wikidate dob, Wikidate dod)
{
WhereDates = wheredates;
Categories = categories;
DOB = dob;
DOD = dod;
CategoryErrors = new BirthDeathCategoriesErrorLog(WhereDates);
}
public void AnalyseArticle()
{
CategoryScan();
if (!BirthYearCat && !BirthDecadeCat && !BirthYearNotKnownCat && !BirthDateNotAccurateCat)
CategoryErrors.NoBirthCategories();
if (LivingPeopleCat && (DeathYearCat || DeathDecadeCat || DeathYearNotKnownCat || DeathDateNotAccurateCat))
CategoryErrors.LivingandDeathCat();
if (!LivingPeopleCat && !DeathYearCat && !DeathDecadeCat && !DeathYearNotKnownCat && !DeathDateNotAccurateCat)
CategoryErrors.NoLivingorDeathCat();
if (BirthYearCat && BirthYearNotKnownCat)
CategoryErrors.BirthYearButNotKnown();
if (DeathYearCat && DeathYearNotKnownCat)
CategoryErrors.DeathYearButNotKnown();
if (LivingPeopleCat && (BirthYearNotKnownCat || BirthDateNotAccurateCat) && !BirthLivingPeopleCat)
CategoryErrors.LivingNotWithLivingVariation();
if (!LivingPeopleCat && BirthLivingPeopleCat)
CategoryErrors.DeadWithLivingVariation();
}
public void CompareDates()
{
CheckBirthCategory();
CheckDeathCategory();
CheckAges();
}
private void CheckAges()
{
int Age = CalculateAge();
if (Age == 0) CategoryErrors.AgeOfZero();
if (Age >0) CheckCentenarian(Age);
if (Age >0 && Age < 14) CheckChild(Age);
}
private int CalculateAge()
{
if (!Wikidate.isCalculable(DOB.thisPrecision)) return -1;
DateTime EndTime;
if (DOD.thisPrecision == DatePrecision.Null)
EndTime = DateTime.Now;
else
{
if (!Wikidate.isCalculable(DOD.thisPrecision)) return -1;
EndTime = DOD.thisDate;
}
TimeSpan AgeInDays = DOD.thisDate - DOB.thisDate;
int AgeInYears = (int)Math.Ceiling((double)(AgeInDays.Days / 365.25));
return AgeInYears;
}
private void CheckCentenarian(int age)
{
//throw new NotImplementedException();
}
private void CheckChild(int age)
{
//throw new NotImplementedException();
}
private void CheckBirthCategory()
{
string BirthCategory = "";
if (DOB.thisPrecision == DatePrecision.Day || DOB.thisPrecision == DatePrecision.Month || DOB.thisPrecision == DatePrecision.Year)
{
BirthCategory = DOB.Year.ToString() + " births";
if (DOB.thisPrecision == DatePrecision.Day && BirthDateNotAccurateCat == true)
CategoryErrors.BirthDateKnownDateMissingCategory(WhereDates);
else if (DOB.thisPrecision != DatePrecision.Day && BirthDateNotAccurateCat == false)
CategoryErrors.BirthDateNotKnownNotDateMissingCategory(WhereDates);
}
else if (DOB.thisPrecision == DatePrecision.Decade)
{
BirthCategory = DOB.Year.ToString() + "s births";
}
else
{
if (BirthYearCat == true || BirthDecadeCat == true)
CategoryErrors.NoBirthDateCategoryExists(WhereDates);
else
if (BirthYearNotKnownCat == false)
CategoryErrors.BirthDateNotKnownNoExplanation(WhereDates);
return;
}
if (Categories.IndexOf(BirthCategory) == -1)
{
if (BirthYearCat == true || BirthDecadeCat == true)
CategoryErrors.BirthDateNotMatchBirthCat(WhereDates);
else
CategoryErrors.BirthDateKnownNoCategory(WhereDates);
}
}
private void CheckDeathCategory()
{
string DeathCategory = "";
if (DOD.thisPrecision == DatePrecision.Day || DOD.thisPrecision == DatePrecision.Month || DOD.thisPrecision == DatePrecision.Year)
{
DeathCategory = DOD.Year.ToString() + " deaths";
if (DOD.thisPrecision == DatePrecision.Day && DeathDateNotAccurateCat == true)
CategoryErrors.DeathDateKnownDateMissingCategory(WhereDates);
else if (DOD.thisPrecision != DatePrecision.Day && DeathDateNotAccurateCat == false)
CategoryErrors.DeathDateNotKnownNotDateMissingCategory(WhereDates);
}
else if (DOD.thisPrecision == DatePrecision.Decade)
{
DeathCategory = DOD.Year.ToString() + "s deaths";
}
else
{
if (DeathYearCat == true || DeathDecadeCat == true)
CategoryErrors.NoDeathDateCategoryExists(WhereDates);
else
if (LivingPeopleCat == false)
{
if (DeathYearNotKnownCat == false)
CategoryErrors.DeathDateNotKnownNoExplanation(WhereDates);
}
return;
}
if (Categories.IndexOf(DeathCategory) == -1)
{
if (DeathYearCat == true || DeathDecadeCat == true)
CategoryErrors.DeathDateNotMatchDeathCat(WhereDates);
else
CategoryErrors.DeathDateKnownNoCategory(WhereDates);
}
}
private void CategoryScan()
{
foreach (string Category in Categories)
{
if (BirthYear(Category)) BirthYearCat = true;
if (BirthDecade(Category)) BirthDecadeCat = true;
if (BirthYearNotKnown(Category)) BirthYearNotKnownCat = true;
if (BirthDateNotAccurate(Category)) BirthDateNotAccurateCat = true;
if (DeathYearNotKnown(Category)) DeathYearNotKnownCat = true;
if (DeathDateNotAccurate(Category)) DeathDateNotAccurateCat = true;
if (DeathYear(Category)) DeathYearCat = true;
if (DeathDecade(Category)) DeathDecadeCat = true;
if (LivingPeople(Category)) LivingPeopleCat = true;
if (BirthLivingPeople(Category)) BirthLivingPeopleCat = true;
}
}
private bool BirthYear(string Category)
{
if (Regex.IsMatch(Category, "[0-9]{1,4} births")) return true;
return false;
}
private bool BirthDecade(string Category)
{
if (Regex.IsMatch(Category, "[0-9]{1,3}0s births")) return true;
return false;
}
private bool BirthYearNotKnown(string Category)
{
if (Category.ToLower() == "year of birth missing") return true;
if (Category.ToLower() == "year of birth missing (living people)") return true;
if (Category.ToLower() == "year of birth uncertain") return true;
if (Category.ToLower() == "year of birth unknown") return true;
return false;
}
private bool BirthDateNotAccurate(string Category)
{
if (Category.ToLower() == "date of birth missing") return true;
if (Category.ToLower() == "date of birth missing (living people)") return true;
if (Category.ToLower() == "date of birth uncertain") return true;
if (Category.ToLower() == "date of birth unknown") return true;
return false;
}
private bool BirthLivingPeople(string Category)
{
if (Category.ToLower() == "year of birth missing (living people)") return true;
if (Category.ToLower() == "date of birth missing (living people)") return true;
return false;
}
private bool DeathYearNotKnown(string Category)
{
if (Category.ToLower() == "year of death missing") return true;
if (Category.ToLower() == "year of death uncertain") return true;
if (Category.ToLower() == "year of death unknown") return true;
return false;
}
private bool DeathDateNotAccurate(string Category)
{
if (Category.ToLower() == "date of death missing") return true;
if (Category.ToLower() == "date of death uncertain") return true;
if (Category.ToLower() == "date of death unknown") return true;
return false;
}
private bool DeathYear(string Category)
{
if (Regex.IsMatch(Category, "[0-9]{1,4} deaths")) return true;
return false;
}
private bool DeathDecade(string Category)
{
if (Regex.IsMatch(Category, "[0-9]{1,3}0s deaths")) return true;
return false;
}
private bool LivingPeople(string Category)
{
if (Category.ToLower() == "living people") return true;
if (Category.ToLower() == "possibly living people") return true;
return false;
}
}
}