-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWikipediaBiography.cs
More file actions
95 lines (82 loc) · 3.01 KB
/
WikipediaBiography.cs
File metadata and controls
95 lines (82 loc) · 3.01 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
using System;
using System.Collections.Generic;
using WikiAccess;
namespace WikidataBioValidation
{
/// <summary>
/// This class represents an article on Wikipedia
/// </summary>
class WikipediaBiography
{
private string Article;
public List<string[]> Templates;
public List<string> Categories;
public string DefaultSort;
private List<ErrorLog> IOErrors { get; set; }
public WikipediaBiographyErrorLog WikipediaBioErrors { get; set; }
private ErrorLog TemplateErrors { get; set; }
private ErrorLog CategoryErrors { get; set; }
public Wikidate BirthDate;
public Wikidate DeathDate;
public WikipediaBiography(string wikilink, string language = "enwiki")
{
Templates = new List<string[]>();
Categories = new List<string>();
BirthDate = new Wikidate();
DeathDate = new Wikidate();
WikipediaBioErrors = new WikipediaBiographyErrorLog();
WikipediaIO WIO = new WikipediaIO();
WIO.Action = "query";
WIO.Export = "Yes";
WIO.ExportNoWrap = "Yes";
WIO.Format = "xml";
WIO.Redirects = "yes";
WIO.Titles = wikilink;
bool Result = WIO.GetData();
IOErrors = WIO.GetErrors();
if (!Result) return;
Article = WIO.Article;
Templates = WIO.TemplatesUsed;
Categories = WIO.CategoriesUsed;
DefaultSort = GetDefaultSort();
BirthDeathTemplate DateExtract = new BirthDeathTemplate(Templates);
BirthDate = DateExtract.DOB;
DeathDate = DateExtract.DOD;
TemplateErrors = DateExtract.TemplateErrors;
BirthDeathCategories CatAnalysis = new BirthDeathCategories("Wikipedia", Categories, BirthDate, DeathDate);
CatAnalysis.AnalyseArticle();
CatAnalysis.CompareDates();
CategoryErrors = CatAnalysis.CategoryErrors;
}
private string GetDefaultSort()
{
int startpoint = Article.ToLower().IndexOf("{{defaultsort:", StringComparison.Ordinal);
if (startpoint == -1)
{
WikipediaBioErrors.NoDefaultSort();
return "";
}
else
{
int endpoint = Article.IndexOf("}}", startpoint, StringComparison.Ordinal);
if (endpoint > startpoint)
{
return Article.Substring(startpoint + 14, endpoint - startpoint - 14).Trim();
}
else
{
WikipediaBioErrors.InvalidDefaultSort();
return "";
}
}
}
public List<ErrorLog> GetErrors()
{
List<ErrorLog> Errors = IOErrors;
Errors.Add(WikipediaBioErrors);
Errors.Add(TemplateErrors);
Errors.Add(CategoryErrors);
return Errors;
}
}
}