Пример #1
0
def importall(recipes_=None):
  """ Call to import everything """
  global graph, degree, recipes, top

  graph = defaultdict(lambda: defaultdict(float))
  degree = defaultdict(float)
  recipes = recipes_ if recipes_ else utils.getrecipes()
  top = utils.gettop()

  for recipe_id in tqdm.tqdm(recipes):
    ingredients = recipes[recipe_id]

    for a in ingredients:
      for b in ingredients:
        if a != b and a in top and b in top:
          graph[a][b] += 1.0

  for a in graph:
    for b in graph[a]:
      degree[a] += graph[a][b]
Пример #2
0
def importall(recipes_=None):
    """ Call to import everything """
    global graph, degree, recipes, top

    graph = defaultdict(lambda: defaultdict(float))
    degree = defaultdict(float)
    recipes = recipes_ if recipes_ else utils.getrecipes()
    top = utils.gettop()

    for recipe_id in tqdm.tqdm(recipes):
        ingredients = recipes[recipe_id]

        for a in ingredients:
            for b in ingredients:
                if a != b and a in top and b in top:
                    graph[a][b] += 1.0

    for a in graph:
        for b in graph[a]:
            degree[a] += graph[a][b]
Пример #3
0
    d = [[0 for i in xrange(n)] for j in xrange(m)]
    for i in range(1, m):
    	d[i][0] = i
    for j in range(1, n):
    	d[0][j] = j


    for j in range(1, n):
    	for i in range(1, m):
    		cost = 0
    		if a[i - 1] != b[j - 1]:
    			cost = 1
    		d[i][j] = min(min(d[i-1][j] + 1, d[i][j-1] + 1), d[i-1][j-1] + cost)
    return d[m-1][n-1]




if __name__ == '__main__':
	top = utils.gettop()
	mat = defaultdict(lambda: defaultdict(int))
	for a in tqdm.tqdm(top):
		for b in top:
			mat[a][b] = distance(a, b)

	with open('edit_dist.txt', 'w') as outfile:
		json.dump(mat, outfile)