示例#1
0
def setup_neo(exe, store, *classpath):
    import os.path
    if classpath:
        dirs = set()
        for file in classpath:
            dirs.add(os.path.dirname(file))
        return neo4j.GraphDatabase(store,
                                   classpath=classpath,
                                   ext_dirs=list(dirs),
                                   log=Log())
    else:
        return neo4j.GraphDatabase(store, log=Log())
示例#2
0
 def setUp(self):
     testcase = type(self)
     for case in dir(testcase):
         if case.startswith('test_'): break
     else:
         return
     dirname, join = os.path.dirname, os.path.join
     path = dirname(dirname(dirname(dirname(os.path.abspath(__file__)))))
     path = join(path,'target','testdata',testcase.__module__)
     
     if os.path.exists(path):
       import shutil
       shutil.rmtree(path)
     path = join(path,testcase.__name__)
     
     self.graphdb = neo4j.GraphDatabase(path)
 def start(self, resource_uri, params):
     if resource_uri is None:
         resource_uri = self.resource_uri
         if not resource_uri:
             resource_uri = os.path.join(self.env.path, 'neodb')
     if resource_uri.startswith('file://'):
         resource_uri = 'file://' + normalize_path(
             self.env.path, resource_uri[7:])
     elif '://' not in resource_uri:
         resource_uri = normalize_path(self.env.path, resource_uri)
     for option, filter in self.options:
         if option not in params:
             value = getattr(self, option)
             if value is not None:
                 params[option] = filter(value)
     return resource_uri, neo4j.GraphDatabase(resource_uri, **params)
示例#4
0
 def __init__(self, pathname):
     # Code for the Java-deficient (like me)
     if not os.environ.has_key('JAVA_HOME'):
         altjava = '/etc/alternatives/java'
         if os.path.islink(altjava):
             javahome = os.path.dirname(
                 os.path.dirname(os.readlink(altjava)))
             os.environ['JAVA_HOME'] = javahome
     import neo4j
     self.db = neo4j.GraphDatabase(pathname)
     indexes = {
         'ringindex': 'exact',
         'droneindex': 'exact',
         'ipindex': 'exact',
         'macindex': 'exact'
     }
     for idx in indexes.keys():
         if not self.db.node.indexes.exists(idx):
             self.db.node.indexes.create(idx, type=indexes[idx])
     self.ringindex = self.db.node.indexes.get('ringindex')  # Rings
     self.droneindex = self.db.node.indexes.get('droneindex')  # Drones
     self.ipindex = self.db.node.indexes.get('ipindex')  # IP addresses
     self.macindex = self.db.node.indexes.get('macindex')  # MAC addresses
示例#5
0
import neo4j

driver = neo4j.GraphDatabase().driver('bolt://0.0.0.0:7687',
                                      auth=('neo4j', 'dupablada'))


def get_stops(tx):
    q = "MATCH (n:STOP) RETURN n;"
    return tx.run(q)


def get_connections(tx, f, t):
    q = "MATCH (f:STOP{name:'%s'}), (t:STOP{name:'%s'})" %(f,t) \
        + " WITH f,t" \
        + " MATCH path = allShortestPaths((f)-[:STOPS_AT*..20]-(t))" \
        + " RETURN path;"
    return tx.run(q)


with driver.session() as session:
    stops = session.read_transaction(get_stops)
    stops = list(stops)
stops = [s['n']['name'] for s in list(stops)]
with driver.session() as session:
    for f in stops:
        for t in stops:
            if f == t: continue
            connections = session.read_transaction(get_connections, f, t)
            connections = list(connections)
            print "============"
            print connections
示例#6
0
 def __init__(self, storedir, storename="Products"):
     self.__graphdb = neo4j.GraphDatabase(storedir)
     self.__name = storename
示例#7
0
文件: __main__.py 项目: wayward/neo4j
            banner="Neo4j Python bindings interactive console")

    try:
        if len(sys.argv) > 2:
            main = scripts(sys.argv[2:])
        elif len(sys.argv) < 2:
            raise TypeError("No database path specified")
        elif not sys.stdin.isatty():
            main = script(sys.stdin)
        else:
            main = interactive

        if os.path.isfile(sys.argv[1]):
            raise TypeError("Database path is a file")
        elif not os.path.exists(sys.argv[1]):
            sys.stderr.write("WARNING: Database path <%s> does not exist, a "
                             "Neo4j database will be created.\n" %
                             (sys.argv[1], ))
    except:
        sys.stderr.write(str(sys.exc_info()[1]) + '\n\n')
        sys.stderr.write(USAGE)
        sys.exit(-1)

    graphdb = neo4j.GraphDatabase(sys.argv[1])
    try:
        main({
            'graphdb': graphdb,
        })
    finally:
        graphdb.shutdown()
示例#8
0
    bus_no = line_data[0]

    split_idx = line_data.index('-----')
    route = line_data[1:split_idx]
    route = [l.split(' : ') for l in route]

    time_table = line_data[split_idx + 1:]
    time_table = [l.split(' : ') for l in time_table]

    if len(data) == 0: break

    sep_idx = data.index('=====')

    transp_data[bus_no] = (time_table, route)

driver = neo4j.GraphDatabase().driver('bolt://localhost:7687',
                                      auth=('neo4j', 'dupablada'))
#%%

stops = set()
connected_stops = {}
for bus_no, (time_table, route) in transp_data.iteritems():
    for time, stop in route:
        stops.add(stop)

    for stop_from, stop_to in zip(route[1:], route[:-1]):
        sf, st = min(stop_from[1], stop_to[1]), max(stop_from[1], stop_to[1])
        connected_stops[sf, st] = int(stop_from[0]) - int(stop_to[0])

#%%

示例#9
0
 def reconnect(self):
     """Closes the existing database connection and re-opens it."""
     self.shutdown()
     self.graph = neo4j.GraphDatabase(self.path)
     self.index = self.graph.index('objects', create=True)
#Sample node to demonstrate neo4j embedded using python 
import neo4j 	
DB_PATH="/var/lib/neo4j/data/graph.db.test"
db_obj =  neo4j.GraphDatabase(DB_PATH)
# All write operations on graph database happens in transaction
with db_obj.transaction:
	node = db_obj.node(name="A")
db_obj.shutdown()