Skip to content
Snippets Groups Projects
Commit 14a34e61 authored by Andrew Cohen's avatar Andrew Cohen
Browse files

unified server side handling - wikipedia, pubmed or amazon

parent 14e63f51
Branches
No related tags found
No related merge requests found
function f = GetCount(words) function f = GetCount(words)
global nQueryCount nCacheCount global nQueryCount nCacheCount strServer
if isempty(strServer)
strServer='wikipedia'
end
term=[words{1}]; term=[words{1}];
for i=2:length(words) for i=2:length(words)
...@@ -19,12 +23,63 @@ if ~isempty(cc) && any(cc) ...@@ -19,12 +23,63 @@ if ~isempty(cc) && any(cc)
return return
end end
% http://en.wikipedia.org/w/index.php?title=Special%3ASearch&profile=default&search=blue+OR+elephant+&fulltext=Search if strcmp(strServer,'pubmed')
% URL=['http://en.wikipedia.org/w/index.php?title=Special%3ASearch&profile=default&search=' term '+&fulltext=Search']; f=doQueryPubmed(term);
% http://www.ncbi.nlm.nih.gov/gquery/?term=WHSC1%2CNSD1%2CASH1L%2CSETD2%2C elseif strcmp(strServer,'amazon')
f=doQueryAmazon(term);
else
f=doQueryWikipedia(term);
end
nQueryCount=nQueryCount+1;
QueryCache.Queries=[QueryCache.Queries {term}];
QueryCache.Count=[QueryCache.Count f];
end
function f=doQueryWikipedia(term)
URL=['http://en.wikipedia.org/w/index.php?title=Special%3ASearch&profile=default&search=' term '+&fulltext=Search'];
str = urlread(URL);
try
idx=strfind(str,'div class="results-info"');
idx=idx(1);
str2=str(idx:end);
idx2=strfind(str2,'of <b>');
str3=str2(idx2+6:end);
idx3=strfind(str3,'</b>');
idx3=idx3(1);
nx=str3(1:idx3-1);
f=str2double(nx);
catch
f=0;
end
end
function f=doQueryPubmed(term)
URL = [ 'http://www.ncbi.nlm.nih.gov/gquery/?term=' term];
str = urlread(URL);
try
key = '<h2>About ';
idx1=strfind(str,key);
idx1=idx1+length(key);
idx2=strfind(str(idx1:end), 'search results for');
nx=str(idx1:idx1+idx2-2);
f=str2double(nx);
catch
f=0;
end
end
function f=doQueryAmazon(term)
URL=['http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=' term '&rh=i%3Aaps%2Ck%3A' term]; URL=['http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=' term '&rh=i%3Aaps%2Ck%3A' term];
% URL = [ 'http://www.ncbi.nlm.nih.gov/gquery/?term=' term];
% URL = [ 'http://www.ncbi.nlm.nih.gov/protein/?term=' term];
for i=1:5 for i=1:5
str = urlread(URL); str = urlread(URL);
...@@ -59,6 +114,7 @@ catch ...@@ -59,6 +114,7 @@ catch
pause(1); pause(1);
end end
end end
nQueryCount=nQueryCount+1;
QueryCache.Queries=[QueryCache.Queries {term}]; end
QueryCache.Count=[QueryCache.Count f];
...@@ -16,12 +16,14 @@ tic ...@@ -16,12 +16,14 @@ tic
% words2={'Mitt Romney' 'John McCain' 'John Kerry' 'Al Gore' 'Bob Dole' 'Michael Dukakis'} % words2={'Mitt Romney' 'John McCain' 'John Kerry' 'Al Gore' 'Bob Dole' 'Michael Dukakis'}
% %
strServer='wikipedia'
words1={'red','orange','yellow','green','blue','indigo'} words1={'red','orange','yellow','green','blue','indigo'}
words2={'lion', 'tiger', 'bear', 'monkey', 'zebra', 'elephant'} words2={'lion','tiger','bear','monkey','zebra','elephant','aardvark','lamb','fox','ape','dog'}
[d1,d2]=GetDistances(words1,words2); [d1,d2]=GetDistances(words1,words2);
idx=getDistancesPairs(words1,words2); idx=getDistancesPairs(words1,words2);
words1={'red','orange','yellow','green','blue','indigo'} words1={'red','orange','yellow','green','blue','indigo','violet','purple','tan','white'}
words2={'square','circle','rectangle','ellipse','triangle','rhombus'} words2={'square','circle','rectangle','ellipse','triangle','rhombus'}
[d1,d2]=GetDistances(words1,words2); [d1,d2]=GetDistances(words1,words2);
idx=getDistancesPairs(words1,words2); idx=getDistancesPairs(words1,words2);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment