本文整理汇总了Python中neo4j.GraphDatabase类的典型用法代码示例。如果您正苦于以下问题:Python GraphDatabase类的具体用法?Python GraphDatabase怎么用?Python GraphDatabase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GraphDatabase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MetaInfoCreator
class MetaInfoCreator( object ):
def __init__( self, databasePath, datasetDict):
#increment to existing db
self.db = GraphDatabase( databasePath )
self.datasetDict = datasetDict
def start(self):
self._createInfoNodes()
self._finish()
def _createInfoNodes( self ):
print "Creating info nodes"
# do all insertions within one transaction: complete failure or success!
with self.db.transaction:
metaVertex = self.db.node() #self.db.reference_node
print "Meta node created, id %i" %( metaVertex.id )
index = self.db.node.indexes.create('meta')
index['meta']['meta'] = metaVertex
for num, (label, patientFile) in enumerate( self.datasetDict.items() ):
patientFile = open( patientFile, 'r')
patientFile.readline() #header
datasetVertex = self.db.node()
datasetVertex['datalabel'] = label
datasetVertex['barcode'] = patientFile.readline().strip("\n")
metaVertex.relationships.create('DATASET', datasetVertex, label=label)
patientFile.close()
def _finish(self):
self.db.shutdown()
print "Infonodes created"
示例2: test_must_use_valid_url_scheme
def test_must_use_valid_url_scheme(self):
try:
GraphDatabase.driver("x://xxx")
except ValueError:
assert True
else:
assert False
示例3: showAllDB
def showAllDB():
db = GraphDatabase(workingdb)
query = """START n=node(*)
MATCH (n) - [r] -> (m)
RETURN n.name, r, m.name"""
print db.query(query)
db.shutdown()
示例4: get_rel_info
def get_rel_info(dbname,relid):
from neo4j import GraphDatabase
from neo4j import OUTGOING, INCOMING, ANY
db = GraphDatabase(dbname)
relid = int(relid) #make sure it is an int
rel = db.relationship[relid]
print rel
for key,value in rel.items():
print "\t"+key,value
db.shutdown()
示例5: get_node_info
def get_node_info(dbname,nodeid):
from neo4j import GraphDatabase
from neo4j import OUTGOING, INCOMING, ANY
db = GraphDatabase(dbname)
nodeid = int(nodeid) #make sure it is an int
nd = db.node[nodeid]
print nd
for key,value in nd.items():
print "\t"+key,value
if "uniqname" in str(key):
break
db.shutdown()
示例6: showAllRelations
def showAllRelations(qname):
db = GraphDatabase(workingdb)
query = """START n=node(*)
MATCH (n) - [r] -> (m)
WHERE HAS(n.name) AND n.name = {name}
RETURN n.name, r, m.name"""
print db.query(query, name=qname)
db.shutdown()
示例7: test_create_configured_db
def test_create_configured_db(self):
folder_to_put_db_in = tempfile.mkdtemp()
try:
# START SNIPPET: creatingConfiguredDatabase
from neo4j import GraphDatabase
# Example configuration parameters
db = GraphDatabase(folder_to_put_db_in, string_block_size=200, array_block_size=240)
db.shutdown()
# END SNIPPET: creatingConfiguredDatabase
finally:
if os.path.exists(folder_to_put_db_in):
import shutil
shutil.rmtree(folder_to_put_db_in)
示例8: test_can_run_simple_statement
def test_can_run_simple_statement(self):
session = GraphDatabase.driver("bolt://localhost").session()
count = 0
for record in session.run("RETURN 1 AS n"):
assert record[0] == 1
assert record["n"] == 1
try:
record["x"]
except AttributeError:
assert True
else:
assert False
assert record.n == 1
try:
record.x
except AttributeError:
assert True
else:
assert False
try:
record[object()]
except TypeError:
assert True
else:
assert False
assert repr(record)
assert len(record) == 1
count += 1
session.close()
assert count == 1
示例9: test_create_db
def test_create_db(self):
folder_to_put_db_in = tempfile.mkdtemp()
try:
# START SNIPPET: creatingDatabase
from neo4j import GraphDatabase
# Create db
db = GraphDatabase(folder_to_put_db_in)
# Always shut down your database
db.shutdown()
# END SNIPPET: creatingDatabase
finally:
if os.path.exists(folder_to_put_db_in):
import shutil
shutil.rmtree(folder_to_put_db_in)
示例10: __init__
def __init__(self, options, columns):
# Calling super constructor
super(Neo4jForeignDataWrapper, self).__init__(options, columns)
# Managed server option
if 'url' not in options:
log_to_postgres('The Bolt url parameter is required and the default is "bolt://localhost:7687"', WARNING)
self.url = options.get("url", "bolt://localhost:7687")
if 'user' not in options:
log_to_postgres('The user parameter is required and the default is "neo4j"', ERROR)
self.user = options.get("user", "neo4j")
if 'password' not in options:
log_to_postgres('The password parameter is required for Neo4j', ERROR)
self.password = options.get("password", "")
if 'cypher' not in options:
log_to_postgres('The cypher parameter is required', ERROR)
self.cypher = options.get("cypher", "MATCH (n) RETURN n LIMIT 100")
# Setting table columns
self.columns = columns
# Create a neo4j driver instance
self.driver = GraphDatabase.driver( self.url, auth=basic_auth(self.user, self.password))
self.columns_stat = self.compute_columns_stat()
self.table_stat = int(options.get("estimated_rows", -1))
if(self.table_stat < 0):
self.table_stat = self.compute_table_stat()
log_to_postgres('Table estimated rows : ' + unicode(self.table_stat), DEBUG)
示例11: test_fails_on_missing_parameter
def test_fails_on_missing_parameter(self):
session = GraphDatabase.driver("bolt://localhost").session()
try:
session.run("RETURN {x}").consume()
except CypherError:
assert True
else:
assert False
示例12: test_fails_on_bad_syntax
def test_fails_on_bad_syntax(self):
session = GraphDatabase.driver("bolt://localhost").session()
try:
session.run("X").consume()
except CypherError:
assert True
else:
assert False
示例13: test_can_obtain_summary_info
def test_can_obtain_summary_info(self):
with GraphDatabase.driver("bolt://localhost").session() as session:
result = session.run("CREATE (n) RETURN n")
summary = result.summarize()
assert summary.statement == "CREATE (n) RETURN n"
assert summary.parameters == {}
assert summary.statement_type == "rw"
assert summary.statistics.nodes_created == 1
示例14: test_can_handle_cypher_error
def test_can_handle_cypher_error(self):
with GraphDatabase.driver("bolt://localhost").session() as session:
try:
session.run("X")
except CypherError:
assert True
else:
assert False
示例15: test_can_run_statement_that_returns_multiple_records
def test_can_run_statement_that_returns_multiple_records(self):
session = GraphDatabase.driver("bolt://localhost").session()
count = 0
for record in session.run("unwind(range(1, 10)) AS z RETURN z"):
assert 1 <= record[0] <= 10
count += 1
session.close()
assert count == 10