示例#1
0
        print(get_usage())
        sys.exit(1)

if not dstDir is None:
    try:
        os.makedirs(dstDir)
    except OSError:
        pass

t = testutils.Timer(ENABLE_TIMER)
ringo = ringo.Ringo()

# Load data
# >>> authors = ringo.load('authors.tsv')
S1 = [("userid1", "string"), ("userid2", "string"), ("created_at", "int")]
Tfollow = ringo.LoadTableTSV(S1, file_cache[TFOLLOW])
t.show("load follow")

# UserId, Owner of Repo, Name of repo, created_at => (owner, name) uniquely identies a repo
S2 = [("userid", "string"), ("owner", "string"), ("name", "string"),
      ("created_at", "int")]
Tcollab = ringo.LoadTableTSV(S2, file_cache[TCOLLAB])
t.show("load collab")

S3 = [("userid", "string"), ("owner", "string"), ("name", "string"),
      ("pullid", "int"), ("status", "string"), ("created_at", "int")]
Tpull = ringo.LoadTableTSV(S3, file_cache[TPULL])
t.show("load pull")

Tfork = ringo.LoadTableTSV(S2, file_cache[TFORK])
t.show("load fork")
示例#2
0
sys.path.append("../utils")
sys.path.append("../ringo-engine-python")
import ringo
import snap
import testutils

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", "string"), ("Score", "int")]
    table = ringo.LoadTableTSV(S, srcfile)
    t.show("load text")
    r.show("__loadtext__")

    table = table.IsNextK("CreationDate", 1, "OwnerUserId")

    t.show("isnextk")
    r.show("__isnextk__")

示例#3
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__")
srcdir = sys.argv[1]
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)

# Load posts
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)
示例#5
0
    if len(sys.argv) < 2:
        print """Usage: """ + sys.argv[0] + """ <postsfile> <tagsfile>
        postsfile: posts.tsv file from StackOverflow dataset
        tagsfile: tags.tsv file from StackOverflow dataset"""
        sys.exit(1)

    postsfile = sys.argv[1]
    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__")
示例#6
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')
示例#7
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')