Esempio n. 1
0
sys.path.append("../utils")
sys.path.append("../ringo-engine-python")
import ringo
import snap
import testutils

if __name__ == '__main__':
    if len(sys.argv) < 3:
        print "Usage: " + sys.argv[0] + " <srcfile1> <srcfile2>"
        sys.exit(1)
    srcfile1 = sys.argv[1]
    srcfile2 = sys.argv[2]
  
    ringo = ringo.Ringo()

    t = testutils.Timer()
    r = testutils.Resource()

    t1 = ringo.Load(srcfile1)
    t.show("load bin")
    r.show("__loadbin__")

    S = [("Index", "int")]
    t2 = ringo.LoadTableTSV(S, srcfile2)
    t.show("load text")
    r.show("__loadtext__")

    t3 = ringo.Join(t1, t2, "Src", "Index")
    t.show("join")
    r.show("__join__")
Esempio n. 2
0
    dstfile = sys.argv[2]

    ringo = ringo.Ringo()
    t = testutils.Timer()
    r = testutils.Resource()

    S = [("Id", "int"), ("OwnerUserId", "int"), ("AcceptedAnswerId", "int"), ("CreationDate", "string"), ("Score", "int"), ("Tag", "string")]
    table = ringo.LoadTableTSV(S, srcfile)
    t.show("load posts text")
    .show("__loadpoststext__")

    questions = ringo.Select(table, "Tag = 'python'", False)
    t.show("selected tag = 'python'")
    r.show("__selectedtagpython__")
  
    qa = ringo.Join(questions, table, "AcceptedAnswerId", "Id")
    graph = ringo.ToGraph(qa, "OwnerUserId-2", "OwnerUserId-1")

    t.show("join")
    r.show("__join__")

    t.show("graph")
    r.show("__graph__")

    prtable = ringo.PageRank(graph, 'PageRank', False, 0.85, 1e-4, 100)
    t.show("pagerank")
    r.show("__pagerank__")

    ringo.SaveTableBinary(prtable)
    t.show("save bin")
    r.show("__savebin__")
Esempio n. 3
0
    tagsfile = sys.argv[2]

    ringo = ringo.Ringo()
    t = testutils.Timer()
    r = testutils.Resource()

    S = [("Id", "int"), ("OwnerUserId", "int"), ("AcceptedAnswerId", "int"),
         ("CreationDate", "int"), ("Score", "int")]
    posts = ringo.LoadTableTSV(S, postsfile)
    t.show("load posts text")
    r.show("__loadpoststext__")

    S = [("PostId", "int"), ("Tag", "string")]
    tags = ringo.LoadTableTSV(S, tagsfile)
    t.show("load tags text")
    r.show("__loadtagstext__")

    table = ringo.Join(posts, tags, "Id", "PostId")
    t.show("join")
    r.show("__join__")

    table2 = ringo.Join(table, posts, "AcceptedAnswerId", "Id")
    t.show("join")
    r.show("__join__")

    table2.SetSrcCol("OwnerUserId-1")
    table2.SetDstCol("OwnerUserId-2")
    gseq = table2.ToGraphPerGroup("Tag", snap.aaFirst)
    t.show("graphseq", gseq)
    r.show("__graphseq__")
S = [('PostId', 'int'), ('UserId', 'int'), ('AnswerId', 'int'),
     ('CreationDate', 'string')]
t1 = ringo.LoadTableTSV(S, os.path.join(srcdir, POSTS_FILE))
t.show("load posts", t1)

# Load tags
S = [('PostId', 'int'), ('Tag', 'string')]
t2 = ringo.LoadTableTSV(S, os.path.join(srcdir, TAGS_FILE))
t.show("load tags", t2)

# Select
ringo.Select(t2, 'Tag = python', CompConstant=True)
t.show("select", t2)

# Join
t3 = ringo.Join(t1, t2, 'PostId', 'PostId')
t.show("join", t3)

# 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)
Esempio n. 5
0
t = testutils.Timer(ENABLE_TIMER)

# Load posts
S = [('PostId', 'int'), ('UserId', 'int'), ('AnswerId', 'int'),
     ('CreationDate', 'string')]
POSTS = ringo.LoadTableTSV(S, os.path.join(srcdir, POSTS_FILE))
t.show("load posts", POSTS)

# Load tags
S = [('PostId', 'int'), ('Tag', 'string')]
T = ringo.LoadTableTSV(S, os.path.join(srcdir, TAGS_FILE))
t.show("load tags", T)

# Join
P = ringo.Join(POSTS, T, "PostId", "PostId")
t.show("join", P)

# Select Java posts
print ringo.GetSchema(P)
ringo.Select(P, '2.Tag = java', CompConstant=True)
t.show("select", P)

# Select Questions
Q = ringo.Select(P, '1.AnswerId != 0', InPlace=False, CompConstant=True)
t.show("select", Q)

# Select Answers
A = ringo.Select(P, '1.AnswerId = 0', InPlace=False, CompConstant=True)
t.show("select", A)
Esempio n. 6
0
dstdir = sys.argv[2] if len(sys.argv) >= 3 else None
if not dstdir is None:
    try:
        os.makedirs(dstdir)
    except OSError:
        pass

ringo = ringo.Ringo()

t = testutils.Timer(ENABLE_TIMER)

t1 = ringo.LoadTableBinary('t1')
t3 = ringo.LoadTableBinary('t3')

# Join
t4 = ringo.Join(t3, t1, "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)
Esempio n. 7
0
import sys
import ringo

posts_file = sys.argv[1]
tags_file = sys.argv[2]
ringo = ringo.Ringo()
S_posts = [('Id','int'), ('PostTypeId','int'), ('AcceptedAnswerId','int'), ('OwnerUserId','int'), ('Body','string')]
S_tags = [('Id','int'), ('Tag','string')]

posts = ringo.LoadTableTSV(S_posts, posts_file)
ringo.Select(posts, 'OwnerUserId > 0')
#print ringo.ringo.DumpTableContent(posts) # buggy...
q_tags = ringo.LoadTableTSV(S_tags, tags_file)
QT = ringo.Join(posts, q_tags, "Id", "Id")
QT = ringo.Project(QT, ['Id', 'PostTypeId', 'AcceptedAnswerId', 'OwnerUserId', 'Body', 'Tag'])
a_tags = ringo.Project(QT, ['AcceptedAnswerId', 'Tag'], False)
AT = ringo.Join(posts, a_tags, 'Id', 'AcceptedAnswerId')
AT = ringo.Project(AT, ['Id', 'PostTypeId', 'AcceptedAnswerId', 'OwnerUserId', 'Body', 'Tag'])
T = ringo.UnionAll(QT, AT)
ringo.SaveTableTSV(T, 'so_posts.tsv')
Esempio n. 8
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')
Esempio n. 9
0
import testutils

WINDOW_SIZE = 2592000 # 1 month

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print """Usage: """ + sys.argv[0] + """ <srcfile>
        srcfile: posts.tsv file from StackOverflow dataset"""
        sys.exit(1)

    srcfile = sys.argv[1]
    ringo = ringo.Ringo()
  
    t = testutils.Timer()
    r = testutils.Resource()

    S = [("Id", "int"), ("OwnerUserId", "int"), ("AcceptedAnswerId", "int"), ("CreationDate", "int"), ("Score", "int")]
    table = ringo.LoadTableTSV(S, srcfile)
    t.show("load text")
    r.show("__loadtext__")

    table2 = ringo.Join(table, table, "AcceptedAnswerId", "Id")
    t.show("join")
    r.show("__join__")

    table2.SetSrcCol("OwnerUserId-1")
    table2.SetDstCol("OwnerUserId-2")
    gseq = table2.ToGraphSequence("CreationDate", snap.aaFirst, WINDOW_SIZE, WINDOW_SIZE)
    t.show("graphseq", gseq)
    r.show("__graphseq__")