def draw_consumer_links(node_start, seller_list, buyer_list, business_model, start_role):
                reader5 = csv.reader([business_model], delimiter=',',skipinitialspace=True)
                for r in reader5:
                    business_model_list = r

                for buyer in seller_list:
                    node_end = neo_dict[buyer]
                    gremlin_script = "g.addEdge(g.v(%s),g.v(%s), 'supplier_of', [name: '%s'])" % (node_start, node_end, buyer)
                    print gremlin_script
                    gremlin.execute(gremlin_script, db)

                for seller in buyer_list:
                    strategy_table = csv.reader(open('graph_strategy.txt'), delimiter='\t',  quotechar='"', quoting=csv.QUOTE_MINIMAL)
                    for item in strategy_table:
                        node_end = item[0]
                        b_c = db.get_node(node_end)
                        b_c_dict = b_c.get_properties()
                        b2b_b2c = b_c_dict['b2b_b2c']
                        role = b_c_dict['roles']
                        for business_model1 in business_model_list:
                            if((item[1]== business_model1) and (node_start != node_end) and (b2b_b2c =='B' or b2b_b2c=='B, C') and (role !='network')):
                                node_start = str(node_start)
                                gremlin_script2 = "g.addEdge(g.v(%s), g.v(%s), 'buyer_of', ['name': '%s') " % (node_start, node_end, seller)
                                print gremlin_script2
                                gremlin.execute(gremlin_script2, db)
                        else:
                            continue
                return
Exemplo n.º 2
0
def graph_query(language, data_payload):
    if language == "cypher":
        headers = {'Content-type': 'application/json'}
        response = requests.post('http://localhost:7474/db/data/cypher', data=data_payload, headers=headers)
        return response.text
    elif language == "gremlin":
        response = gremlin.execute(data_payload, graph_db)
        return {"response" : response}
Exemplo n.º 3
0
def graph_query(language, data_payload):
    if language == "cypher":
        headers = {'Content-type': 'application/json'}
        response = requests.post('http://localhost:7474/db/data/cypher',
                                 data=data_payload,
                                 headers=headers)
        return response.text
    elif language == "gremlin":
        response = gremlin.execute(data_payload, graph_db)
        return {"response": response}
Exemplo n.º 4
0
__license__   = "See LICENSE"

import os

from urlparse import urlparse
from py2neo import neo4j
from py2neo import gremlin

if os.environ.get('NEO4J_REST_URL'):
  graph_db_url = urlparse(os.environ.get('NEO4J_REST_URL'))
  graph_db = neo4j.GraphDatabaseService('http://{host}:{port}{path}'.format(host=graph_db_url.hostname, port=graph_db_url.port, path=graph_db_url.path), user_name=graph_db_url.username, password=graph_db_url.password)
else:
  graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data")


#
# Note that the URL for the GraphML file here does not exist, you would need to create it first.
#
script = """
g.clear();
g.startTransaction();
g.createAutomaticIndex('Users', Vertex.class, ['userId'] as Set);
g.createAutomaticIndex('Posts', Vertex.class, ['postId'] as Set);
g.createAutomaticIndex('Tags', Vertex.class, ['tagName'] as Set);
g.createAutomaticIndex('Bookmarks', Vertex.class, ['bookmarkId'] as Set);
g.loadGraphML('http://neo4jdata.s3.amazonaws.com/neo4j/programming.graph.xml');
g.stopTransaction(TransactionalGraph.Conclusion.SUCCESS);
"""

gremlin.execute(script, graph_db)
#change to present working directory
os.chdir('C:\Documents and Settings\Luke\Desktop\supplier_buyer_graph')

#database connection
db = neo4j.GraphDatabaseService("http://ec2-23-23-59-121.compute-1.amazonaws.com:7474/db/data/")

table = csv.reader(open('relationships.csv'), delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)

next(table)

for row in table:
    try:
        #subject
        user = row[0]
        node_start = row[1]

        #objects
        risk_group = row[7]

        gremlin_script = "g.v(%s)._().sideEffect{it.risk_group='%s';}" % (node_start, risk_group)

        gremlin.execute(gremlin_script, db)
        #print gremlin_script
    except:
        print "error" + user
        continue


if __name__ == '__main__':
    main()
        gremlin_script7 = "g.v(%s)._().sideEffect{it.survival_years=%d;}" % (node_start, survival_years)
        gremlin_script8 = "g.v(%s)._().sideEffect{it.b2b_b2c='%s';}" % (node_start, b2b_b2c)
        gremlin_script9 = "g.v(%s)._().sideEffect{it.roles='%s';}" % (node_start, roles)

##        print gremlin_script
##        print gremlin_script2
##        print gremlin_script3
##        print gremlin_script4
        print gremlin_script5
        print gremlin_script6
        print gremlin_script7
        print gremlin_script8
        print gremlin_script9

##        gremlin.execute(gremlin_script, db)
##        gremlin.execute(gremlin_script2, db)
##        gremlin.execute(gremlin_script3, db)
##        gremlin.execute(gremlin_script4, db)
        gremlin.execute(gremlin_script5, db)
        gremlin.execute(gremlin_script6, db)
        gremlin.execute(gremlin_script7, db)
        gremlin.execute(gremlin_script8, db)
        gremlin.execute(gremlin_script9, db)
    except:
        print "error" + user
        continue


if __name__ == '__main__':
    main()