示例#1
0
def comparePolicies(query):
  results = {}
  print('Working on {}'.format(query))
  arg = getArg(query)
  entities = crosswikis.getEntityDistribution(arg)
  entities = entities[:10]
  topEntities1 = getTopEntities(entities, minCprob=0, limit=3)
  topEntities2 = getTopEntities(entities, minCprob=0.2, limit=None)
  topEntities3 = getTopEntities(entities, minCprob=0.15, limit=5)
  results = (topEntities1, topEntities2, topEntities3)
  return results
示例#2
0
def crosswikis():
  """Crosswikis page. Performs a search if given the arg 'arg', otherwise, just
  shows a search box."""
  if 'arg' in request.args:
    arg = request.args['arg']
    entities = cw.getEntityDistribution(app.config['CROSSWIKIS_DB_PATH'], arg)
    return render_template(
      'crosswikis.html',
      title='Crosswikis lookup',
      scripts=['jquery-1.9.0.min.js', 'crosswikis.js'],
      entities=entities
    )
  else:
    return render_template(
      'crosswikis.html',
      title='Crosswikis lookup',
      scripts=['jqeury-1.9.0.min.js'],
      entities=None
    )
def linkStringToEntity(string,
                       cprobThreshold=0.9,
                       countThreshold=1000,
                       tupleThreshold=500):
    """Gets the entity most likely to be referred to by the given string.

  Args: string: The string to get the entity link for.
    cprobThreshold: The minimum probability of the entity given the string we
      want.
    countThreshold: The minimum count of the entity we want.

  Returns: The most likely entity given the string, or None if no entity was
    found with high enough threshold.
  """
    entityDistribution = cw.getEntityDistribution(string,
                                                  table='crosswikis_subset')
    entityDistribution = [(ent, num, denom, cprob)
                          for (ent, num, denom, cprob) in entityDistribution
                          if cprob > cprobThreshold and num > countThreshold]

    return entityDistribution[0] if len(entityDistribution) > 0 else None
def linkStringToEntity(string, cprobThreshold=0.9, countThreshold=1000,
    tupleThreshold=500):
  """Gets the entity most likely to be referred to by the given string.

  Args: string: The string to get the entity link for.
    cprobThreshold: The minimum probability of the entity given the string we
      want.
    countThreshold: The minimum count of the entity we want.

  Returns: The most likely entity given the string, or None if no entity was
    found with high enough threshold.
  """
  entityDistribution = cw.getEntityDistribution(
    string,
    table='crosswikis_subset'
  )
  entityDistribution = [
    (ent, num, denom, cprob) for (ent, num, denom, cprob) in entityDistribution
    if cprob > cprobThreshold and num > countThreshold
  ]

  return entityDistribution[0] if len(entityDistribution) > 0 else None