Beispiel #1
0
def query(q_text='',q_fieldtext='',q_databasematch='',q_maxresults=''):
  delimiter = "\t"
  # idol server parameters
  query_action = "Query"
  query_params = ""
  query_valid = False
  if q_text != '':
    query_params = query_params + "&text=" + q_text
    query_valid = True
  if q_fieldtext != '':
    query_params = query_params + "&fieldtext=" + q_fieldtext
    query_valid = True
  if q_text != '':
    query_params = query_params + "&databasematch=" + q_databasematch
  if q_text != '':
    query_params = query_params + "&maxresults=" + str(q_maxresults)
  if query_valid == False:
    print "Missing query parameter: text or fieldtext are required."
    return
  autnresponse = aci.action(query_action+query_params)
  response = autnresponse.find("./response").text
  if response == "SUCCESS":
    numhits = int(autnresponse.find(
      "./responsedata/{http://schemas.autonomy.com/aci/}numhits").text)
    if numhits > 0:
      print "Hits: "+str(numhits)
      for hit in autnresponse.findall(
        "./responsedata/{http://schemas.autonomy.com/aci/}hit"):
        doc = hit.find("{http://schemas.autonomy.com/aci/}content/DOCUMENT")
        print ElementTree.tostring(doc)
    else:
        print "Query succeeded, but returned no hits: "+ElementTree.tostring(autnresponse)
  else:
    print "ACI exception: "+response+"|"+ElementTree.tostring(autnresponse)
  return autnresponse
Beispiel #2
0
def csvquery(min_date='',max_date='',database=''):
  delimiter = "\t"
  # idol server parameters
  query_action = "Query&Text=DREALL&MinDate="+\
    min_date+"&MaxDate="+max_date+"&MaxResults=1000000&DocumentCount=true&"+\
	"databasematch="+database+"&print=none&printfields="
  # iterate over <autn:hit>
  keys = ['GSM_NO','DREDATE','DREDBNAME','CATEGORYTAG','EMPCATEGORYTAG','SENTIMENT']
  for key in keys:
    query_action = query_action+key+"%2C"
  autnresponse = aci.action(query_action)
  response = autnresponse.find("./response").text
  if response == "SUCCESS":
    numhits = int(autnresponse.find(
      "./responsedata/{http://schemas.autonomy.com/aci/}numhits").text)
    if numhits > 0:
      header = ""
      for col in keys:
        header = header+col+delimiter
      print header
      for hit in autnresponse.findall(
        "./responsedata/{http://schemas.autonomy.com/aci/}hit"):
        row = ""
        doc = hit.find("{http://schemas.autonomy.com/aci/}content/DOCUMENT")
        for col in keys:
          cell = doc.find(col)
          if cell != None:
            row = row+(cell.text).encode('utf-8')
          row = row+delimiter
        print row
Beispiel #3
0
def query(querytext=''):

    # add "suffix" query
    # idol server parameters
    suffixes_action = "query&text=" + querytext + "&matchallterms=true&databaseMatch=&systemquery=true&maxresults=10&print=none&printfields=DRECONTENT"
    getsuffix = re.compile('(' + querytext + '[ \w][^ ,.%*")(]*) ')

    autnresponse = aci.action(suffixes_action)
    # iterate over <autn:hit>
    suffixes = []
    for hit in autnresponse.findall(
            "./responsedata/{http://schemas.autonomy.com/aci/}hit"):
        drecontent = hit.find(
            "{http://schemas.autonomy.com/aci/}content/DOCUMENT/DRECONTENT"
        ).text
        for suffix in getsuffix.findall(drecontent):
            if suffix not in suffixes:
                suffixes.append(suffix)

    # truncate the list to maxresults
    rhs = []
    i = 0
    j = len(suffixes)
    while i < j and i < maxresults:
        rhs.append(suffixes[i])
        i = i + 1

    # prepare results
    if len(rhs):
        results = ['<hr/><strong>Phrase Match</strong>'] + rhs
    else:
        results = []

    return results
Beispiel #4
0
def query(querytext=''):

    # idol server parameters
    tx_action = "termexpand&text=" + querytext + "&databaseMatch=&expansion=wild&maxterms=" + str(
        maxresults
    ) + "&mindococcs=10&stemming=false&type=dococcs&systemquery=true"
    autnresponse = aci.action(tx_action)

    # iterate over <autn:term>
    tx = []
    for term in autnresponse.findall(
            "./responsedata/{http://schemas.autonomy.com/aci/}term"):
        tx.append(term.text)

    # truncate the list to maxresults
    rhs = []
    i = 0
    j = len(tx)
    while i < j and i < maxresults:
        rhs.append(tx[i])
        i = i + 1

    # prepare results
    if len(rhs):
        results = ['<hr/><strong>Suggested Terms</strong>'] + rhs
    else:
        results = []

    return results
Beispiel #5
0
def query(querytext=''):

    # idol server parameters
    spell_action = "query&text=" + querytext + "&spellcheck=true&print=nospell&singleresult=true&systemquery=true"
    autnresponse = aci.action(spell_action)

    # iterate over <autn:term>
    spell = []
    for term in autnresponse.findall(
            "./responsedata/{http://schemas.autonomy.com/aci/}spellingquery"):
        spell.append(term.text)

    # truncate the list to maxresults
    rhs = []
    i = 0
    j = len(spell)
    while i < j and i < maxresults:
        rhs.append(spell[i])
        i = i + 1

    # prepare results
    if len(rhs):
        results = ['<hr/><strong>Spellcheck</strong>'] + rhs
    else:
        results = []

    return results
Beispiel #6
0
def query(querytext=''):

    # add "IQL"
    # idol server parameters
    iql_action = "query&text=*" + querytext + "*&databaseMatch=IQLRules&maxresults=" + str(
        maxresults) + "&print=all"
    autnresponse = aci.action(iql_action)
    # iterate over <autn:hit>
    iql = []
    for hit in autnresponse.findall(
            "./responsedata/{http://schemas.autonomy.com/aci/}hit"):
        url_href = hit.find(
            "{http://schemas.autonomy.com/aci/}content/DOCUMENT/DOCREF0").text
        title = hit.find(
            "{http://schemas.autonomy.com/aci/}content/DOCUMENT/DRETITLE0"
        ).text
        iql.append('<a href="' + url_href + '">' + title + '</a>')

    # truncate the list to maxresults
    rhs = []
    i = 0
    j = len(iql)
    while i < j and i < maxresults:
        rhs.append(iql[i])
        i = i + 1

    # prepare results
    if len(rhs):
        results = ['<hr/><strong>ABC/IQL</strong>'] + rhs
    else:
        results = []

    return results
Beispiel #7
0
def render(querytext):
    print """\
<table width="800px" class="results">
  <tr>
    <td><h2>results for %s</h2></td>
  </tr>""" % querytext

    # idol server parameters
    query_action = "query&text=" + querytext + "&databaseMatch=particulars+empresas&systemquery=false&maxresults=10&fieldtext=EXISTS{}:TITLE&summary=context&outputencoding=ASCII"
    autnresponse = aci.action(query_action)

    # iterator over <autn:hits>
    hits = autnresponse.findall(
        "./responsedata/{http://schemas.autonomy.com/aci/}hit")

    # look for hits that have seats in use and print detail
    for hit in hits:
        ref = hit.find("{http://schemas.autonomy.com/aci/}reference").text
        lref = string.replace(ref, "/var/Webroot/DEMO/www", "http://127.0.0.1")
        dref = string.replace(ref, "/var/Webroot/DEMO/www", "http://")
        tit = hit.find("{http://schemas.autonomy.com/aci/}title").text
        #print "<tr><td><a href=\"+lref+"\">"+dref+"<a/><br/>"+tit+"<br/><br/></td></tr>"
        print "<tr><td><a href=\"" + lref + "\">" + dref + "<a/><br/>" + tit.encode(
            'utf-8') + "<br/><br/></td></tr>"
    print """\
Beispiel #8
0
def query(q_text='', q_fieldtext='', q_databasematch='', q_maxresults=''):
    delimiter = "\t"
    # idol server parameters
    query_action = "Query"
    query_params = ""
    query_valid = False
    if q_text != '':
        query_params = query_params + "&text=" + q_text
        query_valid = True
    if q_fieldtext != '':
        query_params = query_params + "&fieldtext=" + q_fieldtext
        query_valid = True
    if q_text != '':
        query_params = query_params + "&databasematch=" + q_databasematch
    if q_text != '':
        query_params = query_params + "&maxresults=" + str(q_maxresults)
    if query_valid == False:
        print "Missing query parameter: text or fieldtext are required."
        return
    autnresponse = aci.action(query_action + query_params)
    response = autnresponse.find("./response").text
    if response == "SUCCESS":
        numhits = int(
            autnresponse.find(
                "./responsedata/{http://schemas.autonomy.com/aci/}numhits").
            text)
        if numhits > 0:
            print "Hits: " + str(numhits)
            for hit in autnresponse.findall(
                    "./responsedata/{http://schemas.autonomy.com/aci/}hit"):
                doc = hit.find(
                    "{http://schemas.autonomy.com/aci/}content/DOCUMENT")
                print ElementTree.tostring(doc)
        else:
            print "Query succeeded, but returned no hits: " + ElementTree.tostring(
                autnresponse)
    else:
        print "ACI exception: " + response + "|" + ElementTree.tostring(
            autnresponse)
    return autnresponse
Beispiel #9
0
def csvquery(min_date='', max_date='', database=''):
    delimiter = "\t"
    # idol server parameters
    query_action = "Query&Text=DREALL&MinDate="+\
      min_date+"&MaxDate="+max_date+"&MaxResults=1000000&DocumentCount=true&"+\
   "databasematch="+database+"&print=none&printfields="
    # iterate over <autn:hit>
    keys = [
        'GSM_NO', 'DREDATE', 'DREDBNAME', 'CATEGORYTAG', 'EMPCATEGORYTAG',
        'SENTIMENT'
    ]
    for key in keys:
        query_action = query_action + key + "%2C"
    autnresponse = aci.action(query_action)
    response = autnresponse.find("./response").text
    if response == "SUCCESS":
        numhits = int(
            autnresponse.find(
                "./responsedata/{http://schemas.autonomy.com/aci/}numhits").
            text)
        if numhits > 0:
            header = ""
            for col in keys:
                header = header + col + delimiter
            print header
            for hit in autnresponse.findall(
                    "./responsedata/{http://schemas.autonomy.com/aci/}hit"):
                row = ""
                doc = hit.find(
                    "{http://schemas.autonomy.com/aci/}content/DOCUMENT")
                for col in keys:
                    cell = doc.find(col)
                    if cell != None:
                        row = row + (cell.text).encode('utf-8')
                    row = row + delimiter
                print row