def article(identity, infotype): import wmapiurl import wmapifetch import xmlextract queryURL = wmapiurl.expArtURL(identity) doc = wmapifetch.fetchURL(queryURL) extractresult = xmlextract.extractExplore(doc) infotype = infotype.lower() if infotype == 'l': result = extractresult['labels'] elif infotype == 'p': result = extractresult['parentCategories'] elif infotype == 'i': result = extractresult['inLinks'] elif infotype == 'o': result = extractresult['outLinks'] else: result = False return result
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