1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/env python3 import fileinput if __name__ == '__main__': scores = dict() for line in fileinput.input(): query, dbpediaid, relevance, field, nvalues, nmatches = line.split('\t') if field not in scores: scores[field] = 0 scores[field] += float(relevance) * int(nmatches) / int(nvalues) for field, score in scores.items(): print('{}\t{}'.format(field, score))