def searchWiki(query): import wmapiurl#Denpending modules import wmapifetch import xmlextract queryURL = wmapiurl.searchURL(query) sourcexml = wmapifetch.fetchURL(queryURL) searchResult = xmlextract.extractSearch(sourcexml) labelList = {}#Create a dict to store the label-id pairs for labels in searchResult: if len(labels['labelSenses']) != 0: labelName = labels['labelName'] labelSense = labels['labelSenses'][0] artID = labelSense['artID'] labelList[labelName] = artID else: labelName = labels['labelName'] labelList[labelName] = 'no_matched_article' return labelList
def exploreArticle(query): import xmlextract import wmapiurl import wmapifetch queryURL1 = wmapiurl.searchURL(query) sourcexml = wmapifetch.fetchURL(queryURL1) searchResult = xmlextract.extractSearch(sourcexml) labelList = {}#Create a dict to store the label-id pairs for labels in searchResult: if len(labels['labelSenses']) != 0: labelName = labels['labelName'] labelSense = labels['labelSenses'][0] artID = labelSense['artID'] labelList[labelName] = artID else: labelName = labels['labelName'] labelList[labelName] = 'no_matched_article' idlist = [] for pair in labelList: idlist.append(labelList[pair]) identity = idlist[0] queryURL2 = wmapiurl.expArtURL(identity) xmlfile = wmapifetch.fetchURL(identity) return xmlfile