示例#1
0
def rank(request_pid=None):
    if not isvalidid(request_pid):
        return ''  # these are requests for icons, things like robots.txt, etc
    confs_filter = request.args.get('confs', None)
    papers = papers_similar(request_pid, confs_filter)
    ctx = default_context(papers, render_format='paper')
    return render_template('main.html', **ctx)
示例#2
0
def papers_search(qraw):
  qparts = qraw.lower().strip().split() # split by spaces
  # e.g. if qraw = "localization in space"
  # then qparts = ['localization', 'in', 'space']
  # use reverse index and accumulate scores
  print(qparts)
  scores = []
  if isvalidid(qraw) is not None:
    # now qraw should be like 1611.00675v4
    pid = qraw.split('v')[0]
    # pid is like 1611.00675
    if pid in db.keys():
      scores.append((1, db[pid]))

  qparts = qraw.lower().strip().split() # split by spaces
  for pid,p in db.items():
    score = sum(SEARCH_DICT[pid].get(q,0) for q in qparts)
    #for q in qparts:
    #  print(SEARCH_DICT[pid].get(q,0))
    # for any given paper, get the contribution of each word
    # in qraw to that paper, equivalent to calculating the correlation
    if score == 0:
      continue # no match whatsoever, dont include
    # give a small boost to more recent papers
    score += 0.0001*p['tscore']
    scores.append((score, p))
  scores.sort(reverse=True, key=lambda x: x[0]) # descending
  out = [x[1] for x in scores if x[0] > 0]
  return out
示例#3
0
def rank(request_pid=None):
  if not isvalidid(request_pid):
    return '' # these are requests for icons, things like robots.txt, etc
  papers = papers_similar(request_pid)
  ctx = default_context(papers, render_format='paper')
  print(ctx)
  return render_template('main.html', **ctx)
示例#4
0
def review():
    """ user wants to toggle a paper in his library """

    # make sure user is logged in
    if not g.user:
        print('not g.user')
        return 'NO'  # fail... (not logged in). JS should prevent from us getting here.

    idvv = request.form['pid']  # includes version
    print('idvv=', idvv)
    if not isvalidid(idvv):
        print('not isvalidid(idvv)')
        return 'NO'  # fail, malformed id. weird.
    pid = strip_version(idvv)
    if not pid in db:
        print('not pid in db')
        return 'NO'  # we don't know this paper. wat

    uid = session['user_id']  # id of logged in user

    # check this user already has this paper in library
    record = query_db('''select * from library where
          user_id = ? and paper_id = ?''', [uid, pid],
                      one=True)
    print(record)

    ret = 'NO'
    if record:
        # record exists, erase it.
        g.db.execute(
            '''delete from library where user_id = ? and paper_id = ?''',
            [uid, pid])
        g.db.commit()
        #print('removed %s for %s' % (pid, uid))
        ret = 'OFF'
    else:
        # record does not exist, add it.
        rawpid = strip_version(pid)
        g.db.execute(
            '''insert into library (paper_id, user_id, update_time) values (?, ?, ?)''',
            [rawpid, uid, int(time.time())])
        g.db.commit()
        #print('added %s for %s' % (pid, uid))
        ret = 'ON'

    print(ret)
    return ret
def review():
    """ user wants to toggle a paper in his library """

    # make sure user is logged in
    if not g.user:
        return "NO"  # fail... (not logged in). JS should prevent from us getting here.

    idvv = request.form["pid"]  # includes version
    if not isvalidid(idvv):
        return "NO"  # fail, malformed id. weird.
    pid = strip_version(idvv)
    if not pid in db:
        return "NO"  # we don't know this paper. wat

    uid = session["user_id"]  # id of logged in user

    # check this user already has this paper in library
    record = query_db(
        """select * from library where
          user_id = ? and paper_id = ?""",
        [uid, pid],
        one=True,
    )
    print(record)

    ret = "NO"
    if record:
        # record exists, erase it.
        g.db.execute(
            """delete from library where user_id = ? and paper_id = ?""", [uid, pid]
        )
        g.db.commit()
        # print('removed %s for %s' % (pid, uid))
        ret = "OFF"
    else:
        # record does not exist, add it.
        rawpid = strip_version(pid)
        g.db.execute(
            """insert into library (paper_id, user_id, update_time) values (?, ?, ?)""",
            [rawpid, uid, int(time.time())],
        )
        g.db.commit()
        # print('added %s for %s' % (pid, uid))
        ret = "ON"

    return ret
示例#6
0
def review():
    """ user wants to toggle a paper in his library """

    # make sure user is logged in
    if not g.user:
        return "NO"  # fail... (not logged in). JS should prevent from us getting here.

    idvv = request.form["pid"]  # includes version
    if not isvalidid(idvv):
        return "NO"  # fail, malformed id. weird.
    pid = strip_version(idvv)
    if pid not in paper_db:
        return "NO"  # we don't know this paper. wat

    uid = session["user_id"]  # id of logged in user

    # check this user already has this paper in library
    record = query_db(
        """select * from library where
          user_id = ? and paper_id = ?""",
        [uid, pid],
        one=True,
    )
    print(record)

    ret = "NO"
    if record:
        # record exists, erase it.
        g._database.execute(
            """delete from library where user_id = ? and paper_id = ?""",
            [uid, pid])
        g._database.commit()
        # print('removed %s for %s' % (pid, uid))
        ret = "OFF"
    else:
        # record does not exist, add it.
        rawpid = strip_version(pid)
        g._database.execute(
            """insert into library (paper_id, user_id, update_time) values (?, ?, ?)""",
            [rawpid, uid, int(time.time())],
        )
        g._database.commit()
        # print('added %s for %s' % (pid, uid))
        ret = "ON"

    return ret
示例#7
0
def papers_search(qraw, ret_ids=False):
    # use reverse index and accumulate scores
    scores = []

    if isvalidid(qraw) is not None:
        pid = qraw.split('v')[0]
        if pid in db.keys():
            scores.append((1, db[pid]))

    qparts = qraw.lower().strip().split()  # split by spaces
    for pid, p in db.items():
        score = sum(SEARCH_DICT[pid].get(q, 0) for q in qparts)
        if score == 0:
            continue  # no match whatsoever, dont include
        # give a small boost to more recent papers
        score += 0.0001 * p['tscore']
        scores.append((score, pid if ret_ids else p))
    scores.sort(reverse=True, key=lambda x: x[0])  # descending
    out = [x[1] for x in scores if x[0] > 0]
    return out
def rank(request_pid=None):
    if not isvalidid(request_pid):
        return ""  # these are requests for icons, things like robots.txt, etc
    papers = papers_similar(request_pid)
    ctx = default_context(papers, render_format="paper")
    return render_template("main.html", **ctx)