-
Notifications
You must be signed in to change notification settings - Fork 0
/
plygrd.m
86 lines (74 loc) · 2.26 KB
/
plygrd.m
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
%PLYGRD History Playground interface for MATLAB.
%
% Search the History Playground for n-gram trends (up to a length of 3)
% in historical newspaper datasets. For more details, please visit
% http://playground.enm.bris.ac.uk or direct enquiries to
% tom.welfare@gmail.com
%
% Currently available datasets:
% bna - British Newspaper Archive (1800-1950)
% caa - Chronicling America Archive (1836-1922)
%
% See also PLYGRDLOGIN, PLYGRDQUERY, PLYGRDPLOT
disp('Welcome to the History Playground.');
% Request login details if they haven't logged in already
if ~exist('authToken','var')
try
authToken = requestLogin();
catch
fprintf('Email and/or password are incorrect.\n');
return
end
end
%Request query and dataset options
queries = getQueries();
datasets = getDatasets();
ok = checkDatasets(datasets);
if ok
data = plygrdQuery(queries,datasets,authToken);
plygrdPlot(data);
else
clear ok datasets queries;
return;
end
clear ok ans queries datasets;
return;
function authToken = requestLogin()
[email password] = logindlg('Login to History Playground','Email');
if isempty(email) || isempty(password)
clear email password;
return
end
authToken = plygrdLogin(email,password);
clear email password;
disp('Thank you, you have successfully logged in!');
end
function queries = getQueries()
prompt = 'Please enter your query terms (comma-separated): ';
queryStr = input(prompt,'s');
if isempty(queryStr)
disp('No queries specified!');
return
end
queries = strsplit(queryStr,{', ',','});
end
function datasets = getDatasets()
prompt = 'Please enter your chosen datasets [bna, caa] (comma-separated): ';
datasetStr = input(prompt,'s');
if isempty(datasetStr)
disp('No datasets specified!');
return
end
datasets = strsplit(datasetStr,{', ',','});
end
function ok = checkDatasets(datasets)
ok = 1;
acceptable = {'bna', 'caa'};
for i = 1 : length(datasets)
accept(i) = sum(strcmp(acceptable,datasets{i}));
end
if sum(accept) < size(datasets,2)
disp('Invalid dataset selected');
ok = 0;
end
end