def get_commits_graph(path):
        context = snap.TTableContext()
        e_schema = snap.Schema()
        e_schema.Add(snap.TStrTAttrPr("source", snap.atStr))
        e_schema.Add(snap.TStrTAttrPr("target", snap.atStr))
        e_schema.Add(snap.TStrTAttrPr("weight", snap.atStr))
        n_schema = snap.Schema()
        n_schema.Add(snap.TStrTAttrPr("id", snap.atStr))
        n_schema.Add(snap.TStrTAttrPr("username", snap.atStr))
        n_schema.Add(snap.TStrTAttrPr("size", snap.atStr))

        edgetable = snap.TTable.LoadSS(e_schema, path + '{}_edges.csv'.format(pname), context, ",", snap.TBool(True))
        nodetable = snap.TTable.LoadSS(n_schema, path + '{}_nodes.csv'.format(pname), context, ",", snap.TBool(True))


        edgeattrv = snap.TStrV()
        nodeattrv = snap.TStrV()

        net = snap.ToNetwork(snap.PNEANet, edgetable, "source", "target", edgeattrv, nodetable, "id", nodeattrv, snap.aaFirst)
        snap.DelSelfEdges(net)
        snap.SaveEdgeList(net, 'temp/commits_temp_edgelist.csv')
        
        Data = open('temp/commits_temp_edgelist.csv', 'r')
        Graphtype = nx.Graph()
        G = nx.parse_edgelist(Data, delimiter='\t', create_using=Graphtype, nodetype=int, data=(('weight', float),), comments='#')
        
        return G
def main(args):
    if len(args) < 3:
        print(get_usage())
        sys.exit(1)

    votes = sys.argv[1]
    outFile = sys.argv[2]

    t = testutils.Timer(ENABLE_TIMER)
    context = snap.TTableContext()

    VoteS = snap.Schema()
    VoteS.Add(snap.TStrTAttrPr("UserId", snap.atInt))
    VoteS.Add(snap.TStrTAttrPr("AdminId", snap.atInt))
    TVotes = snap.TTable.LoadSS("WikiVotes", VoteS, votes, context, '\t',
                                snap.TBool(False))
    t.show("load Votes", TVotes)

    GroupBy = snap.TStrV()
    GroupBy.Add("UserId")
    JointTable = TVotes.SelfSimJoinPerGroup(GroupBy, "AdminId",
                                            DISTANCE_ATTRIBUTE, snap.Jaccard,
                                            0.5)
    t.show("SimJoinPerGroup complete", JointTable)

    JointTable.SelectAtomic("WikiVotes_1.UserId", "WikiVotes_2.UserId",
                            snap.NEQ)
    t.show("Select complete", JointTable)

    testutils.dump(JointTable, 20)
    JointTable.SaveSS(outFile)
Exemple #3
0
def parseGraph(filename="./GG-NE/test.tsv"):
    edgefilename = filename  # A file containing the graph, where each row contains an edge
    # and each edge is represented with the source and dest node ids,
    # the edge attributes, and the source and destination node attributes
    # separated by a tab.

    context = snap.TTableContext(
    )  # When loading strings from different files, it is important to use the same context
    # so that SNAP knows that the same string has been seen before in another table.

    schema = snap.Schema()
    schema.Add(snap.TStrTAttrPr("srcID", snap.atInt))
    schema.Add(snap.TStrTAttrPr("dstID", snap.atInt))
    schema.Add(snap.TStrTAttrPr("weight", snap.atFlt))

    table = snap.TTable.LoadSS(schema, edgefilename, context, "\t",
                               snap.TBool(False))

    # In this example, we add both edge attributes to the network,
    # but only one src node attribute, and no dst node attributes.
    edgeattrv = snap.TStrV()
    edgeattrv.Add("weight")

    srcnodeattrv = snap.TStrV()

    dstnodeattrv = snap.TStrV()

    # net will be an object of type snap.PNEANet
    G = snap.ToNetwork(snap.PNEANet, table, "srcID", "dstID", srcnodeattrv,
                       dstnodeattrv, edgeattrv, snap.aaFirst)
    labels = pd.read_table("SS-Butterfly_labels.tsv")
    G.AddIntAttrN("label")
    for index, row in labels.iterrows():
        G.AddIntAttrDatN(row["# Node_ID"], row["Species"], "label")
    return G
    def getLblGraph(self, fileName):
        context = snap.TTableContext()

        schema = snap.Schema()
        schema.Add(snap.TStrTAttrPr("srcLabel", snap.atStr))
        schema.Add(snap.TStrTAttrPr("srcId", snap.atInt))
        schema.Add(snap.TStrTAttrPr("dstLabel", snap.atStr))
        schema.Add(snap.TStrTAttrPr("dstId", snap.atInt))

        table = snap.TTable.LoadSS(schema, fileName, context, " ",
                                   snap.TBool(False))
        #print table

        edgeattrv = snap.TStrV()
        edgeattrv.Add("srcLabel")
        edgeattrv.Add("dstLabel")
        # edgeattrv.Add("edgeattr2")

        srcnodeattrv = snap.TStrV()
        # srcnodeattrv.Add("srcLabel")

        dstnodeattrv = snap.TStrV()
        # srcnodeattrv.Add("dstLabel")

        # net will be an object of type snap.PNEANet
        return snap.ToNetwork(snap.PNEANet, table, "srcId", "dstId",
                              srcnodeattrv, dstnodeattrv, edgeattrv,
                              snap.aaFirst)
Exemple #5
0
def ttable():
    t0=t()
    context = snap.TTableContext()
    
    schema = snap.Schema()
    schema.Add(snap.TStrTAttrPr("Col1", snap.atInt))
    schema.Add(snap.TStrTAttrPr("Col2", snap.atInt))

    table = snap.TTable.LoadSS(schema, NW.twitter, context, "\t", snap.TBool(False))
    reportTime(t0, "TTABLE")
Exemple #6
0
    def test_table_merge(self):
        context = snap.TTableContext()

        schema = snap.Schema()

        schema.Add(snap.TStrTAttrPr("Col1", snap.atInt))
        schema.Add(snap.TStrTAttrPr("Col2", snap.atInt))
        schema.Add(snap.TStrTAttrPr("Col3", snap.atFlt))

        filename = "data/data-table.txt"
        grade_table = snap.TTable.LoadSS(schema, filename, context, "\t", snap.TBool(False))
        int_vec = snap.TIntV()
Exemple #7
0
def load_physician_referral_data(infilename):
    """
    Load the US physician referral data from specified zipfile

    
    Parameters:
       infilename - path name of zipflie to load from

    Return value:
       SNAP TNGraph object built from the data
    """
    tmpdir = tempfile.mkdtemp()
    try:
        archive = zipfile.ZipFile(infilename, 'r')
        archive.extract('physician-shared-patient-patterns-2014-days30.txt',
                        tmpdir)
        filename = os.path.join(
            tmpdir, "physician-shared-patient-patterns-2014-days30.txt")
        archive.close()
        context = snap.TTableContext()
        schema = snap.Schema()
        ## schema.Add(snap.TStrTAttrPr("NPI_1", snap.atInt))
        ## schema.Add(snap.TStrTAttrPr("NPI_2", snap.atInt))
        # the above 2 lines worked with SNAP 4.0.0 on VLSCI
        # but now using SNAP 4.1.0
        # on hpc.ics.usi.ch find that all ids are -1 so graph wrong.
        # Cannot work out why so changed to string not int to try to fix it:
        schema.Add(snap.TStrTAttrPr("NPI_1", snap.atStr))
        schema.Add(snap.TStrTAttrPr("NPI_2", snap.atStr))
        ## schema.Add(snap.TStrTAttrPr("count", snap.atInt))
        ## schema.Add(snap.TStrTAttrPr("unique_bene", snap.atInt))
        ## schema.Add(snap.TStrTAttrPr("same_day_count", snap.atInt))
        # The above 3 lines also worked fine with SNAP 4.0.0 before but
        # now fail on SNAP 4.1.0 (seems to be due to spaces in CSV fields,
        # not inexplicable like first two which have no spaces) but not using
        # them at the moment anyway so easier to just make (unused) strings:
        schema.Add(snap.TStrTAttrPr("count", snap.atStr))
        schema.Add(snap.TStrTAttrPr("unique_bene", snap.atStr))
        schema.Add(snap.TStrTAttrPr("same_day_count", snap.atStr))
        table = snap.TTable.LoadSS(schema, filename, context, ",",
                                   snap.TBool(False))
        G = snap.ToGraph(snap.PNGraph, table, "NPI_1", "NPI_2", snap.aaFirst)
    finally:
        cleanup_tmpdir(tmpdir)

    return G
Exemple #8
0
    def test_table_getitem(self):
        context = snap.TTableContext()

        schema = snap.Schema()

        schema.Add(snap.TStrTAttrPr("Col1", snap.atInt))
        schema.Add(snap.TStrTAttrPr("Col2", snap.atInt))
        schema.Add(snap.TStrTAttrPr("Col3", snap.atFlt))

        filename = "data/data-table.txt"
        grade_table = snap.TTable.LoadSS(schema, filename, context, "\t", snap.TBool(False))
        int_vec = snap.TIntV()
        int_vec.Add(0)
        int_vec.Add(1)
        int_vec.Add(2)
        int_vec.Add(3)
        int_vec.Add(4)
        # unsure about next line!
        col2_vec = grade_table[]
Exemple #9
0
def main(args):
	if len(args) < 3:
		print(get_usage())
		sys.exit(1)

	yelp = sys.argv[1]
	outFile = sys.argv[2]

	t = testutils.Timer(ENABLE_TIMER)
	context = snap.TTableContext()

	YelpS = snap.Schema()
	YelpS.Add(snap.TStrTAttrPr("Name", snap.atStr))
	YelpS.Add(snap.TStrTAttrPr("City", snap.atStr))
	YelpS.Add(snap.TStrTAttrPr("State", snap.atStr))
	YelpS.Add(snap.TStrTAttrPr("Latitude", snap.atFlt))
	YelpS.Add(snap.TStrTAttrPr("Longitude", snap.atFlt))

	TYelp = snap.TTable.LoadSS("Yelp", YelpS, yelp, context, '\t', snap.TBool(True));
	t.show("load Yelp", TYelp)

	Cols = snap.TStrV()
	Cols.Add("Latitude")
	Cols.Add("Longitude")

	# Get all business within 5 kilometers of each other
	JointTable = TYelp.SelfSimJoin(Cols, DISTANCE_ATTRIBUTE, snap.Haversine, 2)
	t.show("SimJoin complete", JointTable)

	ProjectionV = snap.TStrV()
	ProjectionV.Add("Yelp_1.Name")
	ProjectionV.Add("Yelp_1.City")
	ProjectionV.Add("Yelp_1.State")
	ProjectionV.Add("Yelp_2.Name")
	ProjectionV.Add("Yelp_2.City")
	ProjectionV.Add("Yelp_2.State")
	ProjectionV.Add(DISTANCE_ATTRIBUTE)

	JointTable.ProjectInPlace(ProjectionV)
	t.show("Project complete")

	testutils.dump(JointTable, 100);
	JointTable.SaveSS(outFile)
Exemple #10
0
def main():
    S = snap.Schema()
    context = snap.TTableContext()

    S.Add(snap.TStrTAttrPr("Animal", snap.atStr))
    S.Add(snap.TStrTAttrPr("Size", snap.atStr))
    S.Add(snap.TStrTAttrPr("Location", snap.atStr))
    S.Add(snap.TStrTAttrPr("Number", snap.atInt))
    Animals = snap.TTable.LoadSS("Animals", S,
                                 "/dfs/ilfs2/0/ringo/tests/animals.txt",
                                 context, '\t', snap.TBool(False))

    # Gets animals with size=big
    pred_size = snap.TAtomicPredicate(snap.atStr, snap.TBool(True), snap.EQ,
                                      "Size", "", 0, 0, "big")
    node_size = snap.TPredicateNode(pred_size)

    # Get animals with location=Australia
    pred_location = snap.TAtomicPredicate(snap.atStr, snap.TBool(True),
                                          snap.EQ, "Location", "", 0, 0,
                                          "Australia")
    node_location = snap.TPredicateNode(pred_location)

    # size=big and location=Australia
    node1 = snap.TPredicateNode(snap.AND)
    node1.AddLeftChild(node_size)
    node1.AddRightChild(node_location)

    # Get animals with name==location (fabricated to show a non const case
    pred_animal_location = snap.TAtomicPredicate(snap.atStr, snap.TBool(False),
                                                 snap.EQ, "Animal", "Location")
    node2 = snap.TPredicateNode(pred_animal_location)

    # (size=big and location=Australia) or Animal==Location
    node_root = snap.TPredicateNode(snap.OR)
    node_root.AddLeftChild(node1)
    node_root.AddRightChild(node2)
    pred = snap.TPredicate(node_root)

    Animals.Select(pred)
    testutils.dump(Animals)
def load_chchse(path):

    #load table
    context = snap.TTableContext()
    schema = snap.Schema()
    schema.Add(snap.TStrTAttrPr("STITCH 1", snap.atStr))
    schema.Add(snap.TStrTAttrPr("STITCH 2", snap.atStr))
    schema.Add(snap.TStrTAttrPr("Polypharmacy Side Effect", snap.atStr))
    schema.Add(snap.TStrTAttrPr("Side Effect Name", snap.atStr))
    table = snap.TTable.LoadSS(schema, path, context, ",", snap.TBool(True))

    #reformat CIDs and seIDs as strings
    raw_cid1s = snap.TStrV()
    cid1s = snap.TIntV()
    table.ReadStrCol("STITCH 1", raw_cid1s)
    for raw_cid in raw_cid1s:
        cid = format_cid(raw_cid)
        cid1s.Add(cid)
    table.StoreIntCol("cid1", cid1s)

    raw_cid2s = snap.TStrV()
    cid2s = snap.TIntV()
    table.ReadStrCol("STITCH 2", raw_cid2s)
    for raw_cid in raw_cid2s:
        cid = format_cid(raw_cid)
        cid2s.Add(cid)
    table.StoreIntCol("cid2", cid2s)

    #save table as binary
    #cache_path = "../cache/ChChSe-decagon_table.tsv"
    #table.Save(snap.TFOut(cache_path))

    #TEST: checks the number of side effect types
    seVec = snap.TStrV()
    table.ReadStrCol("Side Effect Name", seVec)
    print len(set(list(seVec)))

    return table
Exemple #12
0
def ttableToTmmnet():

    # load table
    t0 = t()
    context = snap.TTableContext()

    schema = snap.Schema()
    schema.Add(snap.TStrTAttrPr("srcID", snap.atInt))
    schema.Add(snap.TStrTAttrPr("dstID", snap.atInt))

    edge_table = snap.TTable.LoadSS(schema, NW.small, context, "\t",
                                    snap.TBool(False))
    t1 = reportTime(t0, "TTABLE")

    # convert table to TMMNet
    mmnet = snap.TMMNet.New()
    edgeattrv = snap.TStrV()
    edgeattrv.Add("edgeattr1")

    CrossG = snap.LoadCrossNetToNet(mmnet, "Mode1", "Mode2", "Cross1",
                                    edge_table, "srcID", "dstID", edgeattrv)

    reportTime(t1, "convert TTABLE to CrossNet")
Exemple #13
0
sys.path.append("../utils")

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]

    context = snap.TTableContext()

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

    FIn = snap.TFIn(srcfile1)
    t1 = snap.TTable.Load(FIn, context)
    t.show("load bin", t1)
    r.show("__loadbin__")

    schema = snap.Schema()
    schema.Add(snap.TStrTAttrPr("Index", snap.atInt))
    t2 = snap.TTable.LoadSS(schema, srcfile2, context, "\t", snap.TBool(False))
    t.show("load text", t2)
    r.show("__loadtext__")
Exemple #14
0
def main(args):
    if len(args) < 3:
        print(get_usage())
        sys.exit(1)

    root = sys.argv[1]
    mid_date = sys.argv[2]
    mid_ticks = utils.date_to_ticks(mid_date)

    file_cache = {
        TCOLLAB: None,
        TPULL: None,
        TREPO: None,
        TFOLLOW: None,
        TWATCH: None,
        TFORK: None
    }

    for file in os.listdir(root):
        if file.endswith(".tsv"):
            file_cache[file] = os.path.join(root, file)
            print file_cache[file]

    for key, val in file_cache.iteritems():
        if val == None:
            print("One of the required files not found.")
            print(get_usage())
            sys.exit(1)

    t = testutils.Timer(ENABLE_TIMER)
    context = snap.TTableContext()

    S1 = snap.Schema()
    S1.Add(snap.TStrTAttrPr("userid1", snap.atStr))
    S1.Add(snap.TStrTAttrPr("userid2", snap.atStr))
    S1.Add(snap.TStrTAttrPr("created_at", snap.atInt))
    Tfollow = snap.TTable.LoadSS("Tfollow", S1, file_cache[TFOLLOW], context,
                                 '\t', snap.TBool(False))
    t.show("load follow")

    S2 = snap.Schema()
    S2.Add(snap.TStrTAttrPr("userid", snap.atStr))
    S2.Add(snap.TStrTAttrPr("owner", snap.atStr))
    S2.Add(snap.TStrTAttrPr("name", snap.atStr))
    S2.Add(snap.TStrTAttrPr("created_at", snap.atInt))
    Tcollab = snap.TTable.LoadSS("Tcollab", S2, file_cache[TCOLLAB], context,
                                 '\t', snap.TBool(False))
    t.show("load collab")

    S3 = snap.Schema()
    S3.Add(snap.TStrTAttrPr("userid", snap.atStr))
    S3.Add(snap.TStrTAttrPr("owner", snap.atStr))
    S3.Add(snap.TStrTAttrPr("name", snap.atStr))
    S3.Add(snap.TStrTAttrPr("pullid", snap.atInt))
    S3.Add(snap.TStrTAttrPr("status", snap.atStr))
    S3.Add(snap.TStrTAttrPr("created_at", snap.atInt))
    Tpull = snap.TTable.LoadSS("Tpull", S3, file_cache[TPULL], context, '\t',
                               snap.TBool(False))
    t.show("load pull")

    # If (u,v) collaborated on the same repository - determined by the owner, name pair,
    # are added as collaborators.
    #TODO Better column renaming
    V = snap.TStrV()
    V.Add("created_at")
    Tcollab.Order(V, "", snap.TBool(False), snap.TBool(True))

    V.Clr()
    V.Add("owner")
    V.Add("name")
    V.Add("userid")
    Tcollab.Group(V, "UserRepoId")

    V.Clr()
    V.Add("UserRepoId")
    Tcollab.Unique(V)

    Tcollab_merge = Tcollab.SelfJoin("owner")
    Tcollab_merge.SelectAtomic("Tcollab_1.name", "Tcollab_2.name", snap.EQ)
    Tcollab_merge.SelectAtomic("Tcollab_1.userid", "Tcollab_2.userid",
                               snap.NEQ)

    # BUGBUG - Commenting this line will mean created_at is not present in Tcollab_merge.
    # However, the ProjectInPlace will not complain and silently exclude created_at from the
    # result. This leads to the Index:-1 error in SelectAtomicIntConst on created_at later in the code.
    Tcollab_merge.ColMin("Tcollab_1.created_at", "Tcollab_2.created_at",
                         "created_at")

    V = snap.TStrV()
    V.Add("Tcollab_1.userid")
    V.Add("Tcollab_2.userid")
    V.Add("created_at")
    Tcollab_merge.ProjectInPlace(V)

    Tcollab_merge.Rename("Tcollab_1.userid", "userid1")
    Tcollab_merge.Rename("Tcollab_2.userid", "userid2")
    t.show("merge collab", Tcollab_merge)

    #testutils.dump(Tcollab_merge, 50)

    # If (u,v) worked on the same pull request on the same repository, they are added
    # as (soft) collaborators.
    V = snap.TStrV()
    V.Add("created_at")
    Tpull.Order(V, "", snap.TBool(False), snap.TBool(True))

    V.Clr()
    V.Add("owner")
    V.Add("name")
    V.Add("userid")
    Tpull.Group(V, "UserRepoId")

    V.Clr()
    V.Add("UserRepoId")
    Tpull.Unique(V)

    Tpull_merge = Tpull.SelfJoin("owner")

    Tpull_merge.SelectAtomic("Tpull_1.name", "Tpull_2.name", snap.EQ)
    Tpull_merge.SelectAtomic("Tpull_1.pullid", "Tpull_2.pullid", snap.EQ)
    Tpull_merge.SelectAtomic("Tpull_1.userid", "Tpull_2.userid", snap.NEQ)
    Tpull_merge.ColMin("Tpull_1.created_at", "Tpull_2.created_at",
                       "created_at")

    V = snap.TStrV()
    V.Add("Tpull_1.userid")
    V.Add("Tpull_2.userid")
    V.Add("created_at")
    Tpull_merge.ProjectInPlace(V)

    Tpull_merge.Rename("Tpull_1.userid", "userid1")
    Tpull_merge.Rename("Tpull_2.userid", "userid2")
    t.show("merge pull", Tpull_merge)

    # BUGBUG: UnionAll is returning unexpected result at this point
    #Tmerge = Tcollab_merge.UnionAll(Tpull_merge, "Tmerge")
    Tmerge = Tpull_merge

    # Select the base and delta tables from the merged table.
    Tbase = snap.TTable.New(Tmerge, "Base")
    Tdelta = snap.TTable.New(Tmerge, "Delta")

    Tbase.SelectAtomicIntConst("created_at", mid_ticks, snap.LTE)
    Tdelta.SelectAtomicIntConst("created_at", mid_ticks, snap.GTE)

    #TODO: Union Tbase with collab and pull to include (userid, owner) edge
    t.show("collab union")

    # Convert base table to base graph
    Gbase = snap.ToNetwork(snap.PNEANet, Tbase, "userid1", "userid2",
                           snap.aaFirst)
    Gdelta = snap.ToNetwork(snap.PNEANet, Tdelta, "userid1", "userid2",
                            snap.aaFirst)
    t.show("base graph", Gbase)
    t.show("delta graph", Gdelta)

    NITERS = 20
    total_preck = 0

    print("Userid\tPrec@%d\tAverage Index" % (N_TOP_RECOS))

    # Random walk with restarts
    # BUGBUG: Returns the same id everytime
    # userid = Gbase.GetRndNId()
    for i in range(NITERS):
        # Randomly choose a starting node
        userid = random.choice([node.GetId() for node in Gbase.Nodes()])
        user = Gbase.GetNI(userid)

        # Perform random walk with restarts on base graph
        HT = snap.TIntFltH()
        snap.GetRndWalkRestart_PNEANet(Gbase, ALPHA, userid, HT)
        HT.SortByDat(False)

        j = 0
        cnt = 0
        preck = 0
        average_index = -1

        # Calculate precision
        while cnt < N_TOP_RECOS and j < HT.Len():
            recoid = HT.GetKey(j)
            pagerank = HT.GetDat(recoid)

            #print recoid, pagerank

            if recoid != userid:
                # If the edge is not in base graph but is present in delta graph, we made an accurate prediction.
                if not Gbase.IsEdge(userid, recoid) and Gdelta.IsNode(
                        userid) and Gdelta.IsNode(recoid) and (Gdelta.IsEdge(
                            userid, recoid) or Gdelta.IsEdge(recoid, userid)):
                    preck += 1
                cnt += 1
            j += 1

        # Calculate average index
        try:
            node = Gdelta.GetNI(userid)
            edges = [nid for nid in node.GetOutEdges()
                     ] + [nid for nid in node.GetInEdges()]
            #print edges
            #print([HT.GetKeyId(nid) for nid in edges])
            index = 0

            for nid in edges:
                index += HT.GetKeyId(nid)

            average_index = index / len(edges)
        except:
            # Node not present in delta graph implies no new edges formed
            pass

        total_preck += preck
        print("%d\t%d\t%f" % (userid, preck, average_index))

        #rank = snap.TTable.New("Rank", HT, "User", PAGE_RANK_ATTRIBUTE, context, snap.TBool(True))
    print("Average Precision@%d = %f" %
          (N_TOP_RECOS, total_preck / float(NITERS)))
Exemple #15
0
import MultiGraph as MG
import NodeAttribute as NodeA
import EdgeAttribute as EdgeA

import Structure as structure
import Centrality as centrality

# A file containing the graph, where each row contains an edge
# and each edge is represented with the source and dest node ids,
# the edge attributes, and the source and destination node attributes
# separated by a tab.
edgefilename = "../bellydynamic-data/CollegeMsg.txt"
graphName = "CollegeMsg"

if __name__ == '__main__':
    context = snap.TTableContext(
    )  # When loading strings from different files, it is important to use the same context
    # so that SNAP knows that the same string has been seen before in another table.

    schema = snap.Schema()
    schema.Add(snap.TStrTAttrPr("srcID", snap.atStr))
    schema.Add(snap.TStrTAttrPr("dstID", snap.atStr))
    schema.Add(snap.TStrTAttrPr("timestamp", snap.atInt))
    # schema.Add(snap.TStrTAttrPr("edgeattr2", snap.atStr))
    # schema.Add(snap.TStrTAttrPr("srcnodeattr1", snap.atStr))
    # schema.Add(snap.TStrTAttrPr("srcnodeattr2", snap.atStr))
    # schema.Add(snap.TStrTAttrPr("dstnodeattr1", snap.atStr))
    # schema.Add(snap.TStrTAttrPr("dstnodeattr2", snap.atStr))

    table = snap.TTable.LoadSS(schema, edgefilename, context, " ",
                               snap.TBool(False))
Exemple #16
0
def main(args):
    if len(args) < 1:
        print("python github-join.py <path_to_tsv_file>")
        sys.exit(1)

    filename = args[0]

    t = testutils.Timer(ENABLE_TIMER)
    context = snap.TTableContext()

    S = snap.Schema()
    S.Add(snap.TStrTAttrPr("userid", snap.atStr))
    S.Add(snap.TStrTAttrPr("owner", snap.atStr))
    S.Add(snap.TStrTAttrPr("name", snap.atStr))
    S.Add(snap.TStrTAttrPr("pullid", snap.atInt))
    S.Add(snap.TStrTAttrPr("status", snap.atStr))
    S.Add(snap.TStrTAttrPr("created_at", snap.atInt))
    Tpull = snap.TTable.LoadSS("Tpull", S, filename, context, '\t',
                               snap.TBool(False))
    t.show("load pull")

    V = snap.TStrV()
    V.Add("created_at")
    Tpull.Order(V, "", snap.TBool(False), snap.TBool(True))

    V.Clr()
    V.Add("owner")
    V.Add("name")
    V.Add("userid")
    Tpull.Group(V, "TagId")

    V.Clr()
    V.Add("TagId")
    Tpull.Unique(V)

    t.show("Unique", Tpull)

    Tpull_merge = Tpull.SelfJoin("owner")
    t.show("Merge", Tpull_merge)

    # Things work fine till this point
    Tpull_merge.SelectAtomic("Tpull_1.name", "Tpull_2.name", snap.EQ)
    Tpull_merge.SelectAtomic("Tpull_1.pullid", "Tpull_2.pullid", snap.EQ)
    Tpull_merge.SelectAtomic("Tpull_1.userid", "Tpull_2.userid", snap.NEQ)
    Tpull_merge.ColMin("Tpull_1.created_at", "Tpull_2.created_at",
                       "created_at")

    V = snap.TStrV()
    V.Add("Tpull_1.userid")
    V.Add("Tpull_2.userid")
    V.Add("created_at")
    Tpull_merge.ProjectInPlace(V)

    Tpull_merge.Rename("Tpull_1.userid", "userid1")
    Tpull_merge.Rename("Tpull_2.userid", "userid2")

    # Copy the Tpull_merge to form two graphs - base and delta. Select all rows in base for created_at < x and all dates in delta for created_at > x
    Tbase = snap.TTable.New(Tpull_merge, "Base")
    Tdelta = snap.TTable.New(Tpull_merge, "Delta")

    #Tbase.SelectAtomicIntConst("created_at", x, snap.LTE)
    #Tdelta.SelectAtomicIntConst("created_at", x, snap.GTE)

    G = snap.ToNetwork(snap.PNEANet, Tbase, "userid1", "userid2", snap.aaFirst)
    t.show("graph", G)