# Join
t4 = ringo.Join(t3, t1, "1.AnswerId", "PostId")
t.show("join", t4)

# Graph
graph = ringo.ToGraph(t4, "1_2.1.UserId", "1.UserId")
t.show("graph", graph)
ringo.ShowMetadata(graph)

# Get authority scores
(HTHub, HTAuth) = ringo.GetHits(graph)
t.show("hits", graph)
ringo.ShowMetadata(HTAuth)

t5 = ringo.TableFromHashMap(HTAuth, "UserId", "Authority")
t.show("authority score", t5)

# Select top entries
#ringo.Select(t5, 'Authority > 0.0', CompConstant = True)
#t.show("select", t5)

# Order by final score (in descending order)
ringo.Order(t5, ['Authority'], Asc=False)
t.show("order", t5)

# Save
if not dstdir is None:
    ringo.SaveTableTSV(t5, os.path.join(dstdir, OUTPUT_TABLE_FILENAME))
    t.show("save", t5)
Exemplo n.º 2
0
import ringo
import sys

src_file = sys.argv[1]
Schema = [('Id', 'int'), ('PostTypeId', 'int'), ('AcceptedAnswerId', 'int'),
          ('OwnerUserId', 'int'), ('Body', 'string'), ('Tag', 'string')]
ringo = ringo.Ringo()
P = ringo.LoadTableTSV(Schema, src_file, '\t', True)
ringo.Project(P,
              ['Id', 'PostTypeId', 'AcceptedAnswerId', 'OwnerUserId', 'Tag'])

JP = ringo.Select(P, "Tag = 'java'", False)
Q = ringo.Select(JP, 'PostTypeId = 1', False)
A = ringo.Select(JP, 'PostTypeId = 2', False)

QA = ringo.Join(Q, A, 'AcceptedAnswerId', 'Id')
G = ringo.ToGraph(QA, 'OwnerUserId-1', 'OwnerUserId-2')
PR_MAP = ringo.PageRank(G)  # a hash map object: node/user id -> PageRank score
PR = ringo.TableFromHashMap(PR_MAP, 'user', 'score')
PR = ringo.Order(PR, ['score'])
ringo.SaveTableTSV(PR, 'scores.tsv')
#ringo.SaveTableBinary(PR, 'scores')
ringo.GenerateProvenance(G, 'G.py')