コード例 #1
0
ファイル: wminterface.py プロジェクト: B-O-P/WikiHack
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
コード例 #2
0
ファイル: wminterface.py プロジェクト: B-O-P/WikiHack
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