Пример #1
0
def test_PR():

    IGgraph1=PageRank.getIGraph("MATCH (n:`andra-user`)<-[r:`andra-from`]-(t1:`andra-tweet`)-[re:`andra-retweet`]->(t2:`andra-tweet`)-[rel:`andra-from`]->(p:`andra-user`) WHERE t2.language="'"fr"'" RETURN n as nodeFrom,p as nodeTo",\
            grapheNeo,"192.168.1.75:7474","neo4j", "pass4dbse")
    IGgraph2=PageRank.getIGraph("MATCH (n:`andra-tweet`)-[re:`andra-retweet`]->(p:`andra-tweet`) RETURN n as nodeFrom,p as nodeTo",\
            grapheNeo,"192.168.1.75:7474","neo4j", "pass4dbse")

    assert type(IGgraph1) == igraph.Graph
    assert len(IGgraph1.vs) != 0
    assert len(IGgraph1.es) != 0

    assert type(IGgraph2) == igraph.Graph
    assert len(IGgraph2.vs) != 0
    assert len(IGgraph2.es) != 0

    PRank1 = PageRank.Rank(IGgraph1, 10)
    PRank2 = PageRank.Rank(IGgraph2, 10)

    assert type(PRank1) == dict
    assert len(PRank1['classement']) == 10
    assert type(PRank1['classement']) == list
    assert type(PRank1['resPR']) == list
    assert len(PRank1['resPR']) != 0
    assert type(PRank2) == dict
    assert len(PRank1['classement']) == 10
    assert type(PRank2['classement']) == list
    assert type(PRank2['resPR']) == list
    assert len(PRank2['resPR']) != 0
    print "PAGERANK OK"
Пример #2
0
def test_influence():

    resIGFG = DetectionCommunautes.DetectionComIG(gTwitter, "FastGreedy")
    resIGIM = DetectionCommunautes.DetectionComIG(gTwitter, "InfoMap")
    resSNAPBC = DetectionCommunautes.DetectionComSNAP(gTwitter, "BigClam",
                                                      path + 'snap/', path,
                                                      'outputGraph.txt',
                                                      'outputAlgo.txt')
    resSNAPIM = DetectionCommunautes.DetectionComSNAP(gTwitter, "InfoMap",
                                                      path + 'snap/', path,
                                                      'outputGraph.txt',
                                                      'outputAlgo.txt')
    resSNAPCPM = DetectionCommunautes.DetectionComSNAP(gTwitter, "CPM",
                                                       path + 'snap/', path,
                                                       'outputGraph.txt',
                                                       'outputAlgo.txt')

    NomComFG = InfluenceCommunautes.NomsCommunautes(resIGFG['membership'],
                                                    gTwitter)
    NomComIM = InfluenceCommunautes.NomsCommunautes(resIGIM['membership'],
                                                    gTwitter)

    assert type(NomComFG['comNoms']) == dict
    assert type(NomComFG['comNode']) == dict
    assert len(NomComFG['comNoms']) != 0
    assert len(NomComFG['comNode']) != 0
    assert type(NomComIM['comNoms']) == dict
    assert type(NomComIM['comNode']) == dict
    assert len(NomComIM['comNoms']) != 0
    assert len(NomComIM['comNode']) != 0

    IGgraph1=PageRank.getIGraph("MATCH (n:`andra-user`)<-[r:`andra-from`]-(t1:`andra-tweet`)-[re:`andra-retweet`]->(t2:`andra-tweet`)-[rel:`andra-from`]->(p:`andra-user`) WHERE t2.language="'"fr"'" RETURN n as nodeFrom,p as nodeTo",\
            grapheNeo,"192.168.1.75:7474","neo4j", "pass4dbse")
    PRank1 = PageRank.Rank(IGgraph1, 10)

    InfluFG = InfluenceCommunautes.InfluenceCommunautes(
        grapheNeo, gTwitter, PRank1['resPR'], NomComFG['comNode'], 0.2, 10)
    InfluIM = InfluenceCommunautes.InfluenceCommunautes(
        grapheNeo, gTwitter, PRank1['resPR'], NomComIM['comNode'], 0.2, 10)
    InfluBC = InfluenceCommunautes.InfluenceCommunautes(
        grapheNeo, gTwitter, PRank1['resPR'], resSNAPBC['comCodes'], 0.2, 10)
    InfluIMS = InfluenceCommunautes.InfluenceCommunautes(
        grapheNeo, gTwitter, PRank1['resPR'], resSNAPIM['comCodes'], 0.2, 10)
    InfluCPM = InfluenceCommunautes.InfluenceCommunautes(
        grapheNeo, gTwitter, PRank1['resPR'], resSNAPCPM['comCodes'], 0.2, 10)

    assert type(InfluFG) == dict
    assert type(InfluIM) == dict
    assert type(InfluBC) == dict
    assert type(InfluIMS) == dict
    assert type(InfluCPM) == dict

    InfluHTFG = InfluenceCommunautes.InfluenceHashtags(grapheNeo,
                                                       NomComFG['comNode'],
                                                       0.2)
    InfluHTIM = InfluenceCommunautes.InfluenceHashtags(grapheNeo,
                                                       NomComIM['comNode'],
                                                       0.2)
    InfluHTBC = InfluenceCommunautes.InfluenceHashtags(grapheNeo,
                                                       resSNAPBC['comCodes'],
                                                       0.2)
    InfluHTIMS = InfluenceCommunautes.InfluenceHashtags(
        grapheNeo, resSNAPIM['comCodes'], 0.2)
    InfluHTCPM = InfluenceCommunautes.InfluenceHashtags(
        grapheNeo, resSNAPCPM['comCodes'], 0.2)

    assert type(InfluHTFG) == dict
    assert type(InfluHTIM) == dict
    assert type(InfluHTBC) == dict
    assert type(InfluHTIMS) == dict
    assert type(InfluHTCPM) == dict
    assert len(InfluHTFG) == len(NomComFG['comNode'])
    assert len(InfluHTIM) == len(NomComIM['comNode'])
    assert len(InfluHTBC) == len(resSNAPBC['comNoms'])
    assert len(InfluHTIMS) == len(resSNAPIM['comNoms'])
    assert len(InfluHTCPM) == len(resSNAPCPM['comNoms'])

    InflueTweeFG = InfluenceCommunautes.InfluenceTweets(NomComFG['comNode'])
    InflueTweeIM = InfluenceCommunautes.InfluenceTweets(NomComIM['comNode'])
    InflueTweeBC = InfluenceCommunautes.InfluenceTweets(resSNAPBC['comCodes'])
    InflueTweeIMS = InfluenceCommunautes.InfluenceTweets(resSNAPIM['comCodes'])
    InflueTweeCPM = InfluenceCommunautes.InfluenceTweets(
        resSNAPCPM['comCodes'])

    assert type(InflueTweeFG) == dict
    assert type(InflueTweeIM) == dict
    assert type(InflueTweeBC) == dict
    assert type(InflueTweeIMS) == dict
    assert type(InflueTweeCPM) == dict
    assert len(InflueTweeFG) == len(NomComFG['comNode'])
    assert len(InflueTweeIM) == len(NomComIM['comNode'])
    assert len(InflueTweeBC) == len(resSNAPBC['comNoms'])
    assert len(InflueTweeIMS) == len(resSNAPIM['comNoms'])
    assert len(InflueTweeCPM) == len(resSNAPCPM['comNoms'])

    print "INFLUENCE OK"