Пример #1
0
def runFootball():
   """run pagerank on NCAA_football.csv"""

   f = open('NCAA_football.csv')
   graph = PageRank()

   for line in f:
      columns = line.split(',')
      team1 = columns[0].strip()
      value1 = int(columns[1])
      team2 = columns[2].strip()
      value2 = int(columns[3])

      if value1 > value2:
         graph.addEdge(team2, team1)

      elif value1 < value2:
         graph.addEdge(team1, team2)

      else:
         graph.addEdge(team2, team1)
         graph.addEdge(team1, team2)

   graph.printGraph()
   iterations, ranks = graph.getPageRank()
   print "Number of iterations:", iterations
   print returnSorted(ranks)
Пример #2
0
def runStates():
   """run pagerank on stateborders.csv"""
   f = open('stateborders.csv')

   graph = PageRank()
   for line in f:
      columns = line.split(',')
      left = columns[0].strip('"')
      right = columns[2].strip('"')
      graph.addEdge(left, right)

   graph.printGraph()
   iterations, ranks = graph.getPageRank()
   print "Number of iterations:", iterations
   print returnSorted(ranks)