-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWikidataIO.cs
More file actions
72 lines (66 loc) · 2.13 KB
/
WikidataIO.cs
File metadata and controls
72 lines (66 loc) · 2.13 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WikiAccess
{
/// <summary>
/// General interface to Wikidata
/// </summary>
public class WikidataIO : WikimediaApi
{
protected override string APIurl { get { return @"http://www.Wikidata.org/w/api.php?"; } }
protected override string Parameters
{
get
{
string Param = "action=" + Action;
if (Format != "") Param += "&format=" + Format;
if (Sites != "") Param += "&sites=" + Sites;
if (Ids != 0) Param += "&ids=Q" + Ids.ToString();
if (Props != "") Param += "&props=" + Props;
if (Languages != "") Param += "&languages=" + Languages;
return Param;
}
}
private WikidataIOErrorLog WikidataErrors { get; set; }
private ErrorLog ExternalErrors { get; set; }
public string Action { get; set; }
public string Format { get; set; }
public string Sites { get; set; }
public int Ids { get; set; }
public string Props { get; set; }
public string Languages { get; set; }
public string[] ClaimsRequired { get; set; }
public WikidataIO()
: base()
{
WikidataErrors = new WikidataIOErrorLog();
}
public WikidataFields GetData()
{
if (GrabPage())
{
WikidataExtract Item = new WikidataExtract(Content, ClaimsRequired);
ExternalErrors = Item.WikidataExtractErrors;
if (Item.Success)
return Item.Fields;
else
return null;
}
else
{
WikidataErrors.UnableToRetrieveData();
return null;
}
}
public List<ErrorLog> GetErrors()
{
List<ErrorLog> Logs = new List<ErrorLog>();
Logs.Add(APIErrors);
Logs.Add(WikidataErrors);
Logs.Add(ExternalErrors);
return Logs;
}
}
}