def processResults(resultsdict, searchresults):
    try:
        if isinstance(resultsdict["IdList"]["Id"], basestring):
            resultsdict["IdList"]["Id"] = [resultsdict["IdList"]["Id"]]
        for res in resultsdict["IdList"]["Id"]:
            if res not in searchresults.keys():
                searchresults[res] = {}
            searchresults[res]["id"] = res
            searchresults[res]["grade"] = 0.0
            searchresults[res]["strength"] = 0.0
            searchresults[res]["meshdistance"] = 0.0
            title, abstract, date, meshterms, pubtypes = articledata.getData(
                res)
            searchresults[res]["title"] = title
            searchresults[res]["abstract"] = abstract
            searchresults[res]["date"] = date
            searchresults[res]["pubtypes"] = pubtypes
            searchresults[res]["meshterms"] = meshterms
            searchresults[res]["keywords"] = []
    except TypeError:
        print "TypeError"
        print "Likely cause: no query results"
        print "Number of results: " + resultsdict["Count"]
    except KeyError:
        print "Keyerror"
        print "Likely cause: only one result"

    return searchresults
def processResults(resultsdict, searchresults):
	try:
		if isinstance(resultsdict["IdList"]["Id"], basestring):
			resultsdict["IdList"]["Id"] = [resultsdict["IdList"]["Id"]]
		for res in resultsdict["IdList"]["Id"]:
			if res not in searchresults.keys():
				searchresults[res] = {}
			searchresults[res]["id"] = res
			searchresults[res]["grade"] = 0.0
			searchresults[res]["strength"] = 0.0
			searchresults[res]["meshdistance"] = 0.0
			title, abstract, date, meshterms, pubtypes = articledata.getData(res)
			searchresults[res]["title"] = title
			searchresults[res]["abstract"] = abstract
			searchresults[res]["date"] = date
			searchresults[res]["pubtypes"] = pubtypes
			searchresults[res]["meshterms"] = meshterms
			searchresults[res]["keywords"] = []	
	except TypeError:
		print "TypeError"
		print "Likely cause: no query results"
		print "Number of results: " + resultsdict["Count"]
	except KeyError:
		print "Keyerror"
		print "Likely cause: only one result"

	return searchresults
Example #3
0
# If there is only one result, PubMed will return it as a string
# rather than a list. In this case, convert it to a list with one element
try:
	if isinstance(resultsdict["IdList"]["Id"], basestring):
		resultsdict["IdList"]["Id"] = [resultsdict["IdList"]["Id"]]


	# initialize results dictionary and look up article data
	for res in resultsdict["IdList"]["Id"]:
		if res not in searchresults.keys():
			searchresults[res] = {}
		searchresults[res]["id"] = res
		searchresults[res]["grade"] = 0.0
		searchresults[res]["strength"] = 0.0
		searchresults[res]["meshdistance"] = 0.0
		title, abstract, date, meshterms, pubtypes = articledata.getData(res)
		searchresults[res]["title"] = title
		searchresults[res]["abstract"] = abstract
		searchresults[res]["date"] = date
		searchresults[res]["pubtypes"] = pubtypes
		searchresults[res]["meshterms"] = meshterms
		searchresults[res]["keywords"] = []
except TypeError:
	print "Query 1 TypeError"
	print "Likely cause: no query results"
	print "Number of results: " + resultsdict["Count"]

# QUERY 2
# perform query
resp, content = h.request(baseURL + "esearch.fcgi?db=pubmed&retmode=xml&sort=relevance&retmax=100&term=" + query2.replace(" ", "+"))