Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
rtol authored Aug 23, 2022
1 parent 166a9cf commit 5b97e79
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 0 deletions.
41 changes: 41 additions & 0 deletions addgraph.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function G = addgraph(G,pidi)
%G = addgraph(G,pidi)
%
%addgraph is a recursive function
%input pidi is a cell array, identifying academic parents
%parents and child are added to family tree G
%addgraph then moves on to the parents' parents
%
%21 February 2018, Richard S.J. Tol

count = strcat(num2str(size(G.Nodes,1)),' members of the family tree.');
disp(count)
np = size(pidi,2);
for i=1:np
[cid, cn, pid, pn] = getparents(char(pidi(i)));
nq =size(pid,2);
j=0;
for i=1:nq
testp = findnode(G, pn{i}); % 0 if parent not already in graph
if testp > 0
teste = findedge(G, pn{i}, cn{i});
else
teste = 0;
end
if teste==0
j=j+1;
pnh{j}=pn{i};
cnh{j}=cn{i};
pidh{j}=pid{i};
end
end
if exist('pnh')
G=addedge(G,pnh,cnh);
end
if exist('pidh')
G=addgraph(G,pidh);
end
clear cid cn pin pn pnh cnh pidh
end

end
42 changes: 42 additions & 0 deletions addgraphdesc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function G = addgraphdesc(G,cidi)
%G = addgraphdesc(G,cidi)
%
%addgraph is a recursive function
%input cidi is a cell array, identifying academic children
%parent and children are added to family tree G
%addgraph then moves on to the children's children
%
%22 March 2018, Richard S.J. Tol

count = strcat(num2str(size(G.Nodes,1)),' members of the family tree.');
disp(count)
nc = size(cidi,2);
for i=1:nc
[cid, cn, pid, pn] = getchildren(char(cidi(i)));
nq =size(cid,2);
j=0;
for i=1:nq
testp = findnode(G, cn{i}); % 0 if child not already in graph
if testp > 0
teste = findedge(G, pn{i}, cn{i});
else
teste = 0;
end
if teste==0
j=j+1;
pnh{j}=pn{i};
cnh{j}=cn{i};
pidh{j}=pid{i};
cidh{j} = cid{j};
end
end
if exist('cnh')
G=addedge(G,pnh,cnh);
end
if exist('cidh')
G=addgraphdesc(G,cidh);
end
clear cid cn pin pn pnh cnh pidh
end

end
15 changes: 15 additions & 0 deletions getacdesc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function G = getacdesc(startid)
%function G = getacdesc(startid)
%
%This function downloads academic mentees from https://academictree.org/
%and return them as the directed graph G. To do this for your favourite
%academic, go to the site and search for the name.
%Startid is the person id (pid) in the URL. It is a string.
%
%22 March 2018, Richard S.J. Tol

[cid, cn, pid, pn] = getchildren(startid);
G=digraph(pn,cn);
G=addgraphdesc(G,cid);

end
15 changes: 15 additions & 0 deletions getactree.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function G = getactree(startid)
%function G = getactree(startid)
%
%This function downloads academic mentors from https://academictree.org/
%and return them as the directed graph G. To do this for your favourite
%academic, go to the site and search for the name.
%Startid is the person id (pid) in the URL. It is a string.
%
%21 February 2018, Richard S.J. Tol

[cid, cn, pid, pn] = getparents(startid);
G=digraph(pn,cn);
G=addgraph(G,pid);

end
79 changes: 79 additions & 0 deletions getchildren.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
function [cid, cn, pid, pn] = getchildren(c)
%function [cid, cn, pid, pn] = getchildren(c)
%
%getparents downloads the parent ids and parents names of scholar c
%output is organized as two pairs of cell arrays, for names and ids
%
%22 March, Richard S.J. Tol

site = strcat('https://academictree.org/econ/peopleinfo.php?pid=',c);
s = webread(site);
if length(s) > 0

%get name
sep0 = findstr(s,'<TITLE>');
sep1 = findstr(s,'</TITLE>');
s1 = s(sep0+7:sep1-1);
sep0 = findstr(s1,'-');
pname = s1(sep0+2:length(s1));
pname = strrep(pname,' ',' ');

%get children
sep0 = findstr(s,'Construct Child Connection Container');
sep1 = findstr(s,'Construct Collaborator Connection Container');
s1 = s(sep0:sep1);
sep0 = findstr(s1,'pid=');
np = length(sep0);
pidh = cell(1,np);
cidh = cell(1,np);
pnh = cell(1,np);
cnh = cell(1,np);
for i = 1:np
j=0;
while s1(sep0(i)+4+j)~='"'
s2(j+1) = s1(sep0(i)+4+j);
j=j+1;
end
j=j+2;
l = 1;
while s1(sep0(i)+4+j)~='<'
s3(l) = s1(sep0(i)+4+j);
j=j+1;
l=l+1;
end
cidh{i} = s2;
pidh{i} = c;
cnh{i} = strrep(strrep(s3,'&nbsp;',' '),' ',' ');
pnh{i} = strrep(pname,' ',' ');
clear s2 s3
end
end

%remove duplicate children
if size(pidh,2) > 2
cid{1} = cidh{1};
cn{1} = cnh{1};
pid{1} = pidh{1};
pn{1} = pnh{1};
for i=2:size(cidh,2)
j=size(cid,2);
copy = true;
for l=1:j
copy = copy & ~strcmp(cidh{i},cid{l});
end
if copy
j=j+1;
cid{j} = cidh{i};
cn{j} = cnh{i};
pid{j} = pidh{i};
pn{j} = pnh{i};
end
end
else
cid = cidh;
cn = cnh;
pid = pidh;
pn = pnh;
end

end
79 changes: 79 additions & 0 deletions getparents.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
function [cid, cn, pid, pn] = getparents(c)
%function [cid, cn, pid, pn] = getparents(c)
%
%getparents downloads the parent ids and parents names of scholar c
%output is organized as two pairs of cell arrays, for names and ids
%
%21 February 2018, Richard S.J. Tol

site = strcat('https://academictree.org/econ/peopleinfo.php?pid=',c);
s = webread(site);
if length(s) > 0

%get name
sep0 = findstr(s,'<TITLE>');
sep1 = findstr(s,'</TITLE>');
s1 = s(sep0+7:sep1-1);
sep0 = findstr(s1,'-');
cname = s1(sep0+2:length(s1));
cname = strrep(cname,' ',' ');

%get parents
sep0 = findstr(s,'Construct Parent Connection UL');
sep1 = findstr(s,'Construct Child Connection Container');
s1 = s(sep0:sep1);
sep0 = findstr(s1,'pid=');
np = length(sep0);
pidh = cell(1,np);
cidh = cell(1,np);
pnh = cell(1,np);
cnh = cell(1,np);
for i = 1:np
j=0;
while s1(sep0(i)+4+j)~='"'
s2(j+1) = s1(sep0(i)+4+j);
j=j+1;
end
j=j+2;
l = 1;
while s1(sep0(i)+4+j)~='<'
s3(l) = s1(sep0(i)+4+j);
j=j+1;
l=l+1;
end
pidh{i} = s2;
cidh{i} = c;
pnh{i} = strrep(strrep(s3,'&nbsp;',' '),' ',' ');
cnh{i} = strrep(cname,' ',' ');
clear s2 s3
end
end

%remove duplicate parents
if size(pidh,2) > 2
cid{1} = cidh{1};
cn{1} = cnh{1};
pid{1} = pidh{1};
pn{1} = pnh{1};
for i=2:size(pidh,2)
j=size(pid,2);
copy = true;
for l=1:j
copy = copy & ~strcmp(pidh{i},pid{l});
end
if copy
j=j+1;
cid{j} = cidh{i};
cn{j} = cnh{i};
pid{j} = pidh{i};
pn{j} = pnh{i};
end
end
else
cid = cidh;
cn = cnh;
pid = pidh;
pn = pnh;
end

end
11 changes: 11 additions & 0 deletions mergedigraphs.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function G = mergedigraphs2(G1,G2)
%function G = mergedigraphs(G1,G2)
%
%This function takes two digraphs, G1 and G2, and makes them into one, G.
%
%23 January 2021, Richard S.J. Tol

G = digraph([G1.Edges; G2.Edges]);
G = simplify(G);

end

0 comments on commit 5b97e79

Please sign in to comment.