• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python neo4j.GraphDatabase类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中neo4j.GraphDatabase的典型用法代码示例。如果您正苦于以下问题:Python GraphDatabase类的具体用法?Python GraphDatabase怎么用?Python GraphDatabase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了GraphDatabase类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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" 
开发者ID:amergin,项目名称:neo4j-import,代码行数:34,代码来源:create_info_nodes.py


示例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
开发者ID:chiffa,项目名称:neo4j-python-driver,代码行数:7,代码来源:session_test.py


示例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()
开发者ID:silvia6200,项目名称:humeanhackers,代码行数:10,代码来源:NeoCreate.py


示例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()
开发者ID:OpenTreeOfLife,项目名称:gcmdr,代码行数:10,代码来源:general_utils.py


示例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()
开发者ID:OpenTreeOfLife,项目名称:gcmdr,代码行数:12,代码来源:general_utils.py


示例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()
开发者ID:silvia6200,项目名称:humeanhackers,代码行数:13,代码来源:NeoCreate.py


示例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)
开发者ID:Brackets,项目名称:neo4j,代码行数:15,代码来源:core.py


示例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
开发者ID:chiffa,项目名称:neo4j-python-driver,代码行数:30,代码来源:session_test.py


示例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)
开发者ID:Brackets,项目名称:neo4j,代码行数:16,代码来源:core.py


示例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)
开发者ID:sim51,项目名称:neo4j-fdw,代码行数:33,代码来源:neo4jfdw.py


示例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
开发者ID:chiffa,项目名称:neo4j-python-driver,代码行数:8,代码来源:session_test.py


示例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
开发者ID:chiffa,项目名称:neo4j-python-driver,代码行数:8,代码来源:session_test.py


示例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
开发者ID:chiffa,项目名称:neo4j-python-driver,代码行数:8,代码来源:session_test.py


示例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
开发者ID:chiffa,项目名称:neo4j-python-driver,代码行数:8,代码来源:session_test.py


示例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
开发者ID:chiffa,项目名称:neo4j-python-driver,代码行数:8,代码来源:session_test.py


示例16: get_db

 def get_db(self, data_dir=None):
     from neo4j import GraphDatabase
     if self._db is None:
         if data_dir is None:
             data_dir = settings.GRAPH_DATABASE_PATH
         self._db = GraphDatabase(data_dir)
     db = self._db
     return self._db
开发者ID:tgpatel,项目名称:vcweb,代码行数:8,代码来源:graph.py


示例17: showAllNodes

def showAllNodes():

	# open the db
	db = GraphDatabase(workingdb)

	number_of_nodes = len(db.nodes)
	query = "START n=node(*) RETURN n"

	print "This db has " + str(number_of_nodes) +"nodes" 
	
	if(number_of_nodes>0):

		print db.query(query)
	else: 
		print "no nodes"
	
	db.shutdown()
开发者ID:silvia6200,项目名称:humeanhackers,代码行数:17,代码来源:NeoCreate.py


示例18: get_nodeinfo_for_name

def get_nodeinfo_for_name(dbname,name):
    from neo4j import GraphDatabase
    from neo4j import OUTGOING, INCOMING, ANY
    db = GraphDatabase(dbname)
    with db.transaction:
        node_idx = db.node.indexes.get('graphNamedNodes')
        hits = node_idx['name'][name]
        for i in hits:
            print i
            for key,value in i.items():
                print "\t"+key,value
                #printing after, prints mrcas which are usually too long
                #comment to let it go, but don't commit
                if "uniqname" in str(key):
                    break
        hits.close()
    db.shutdown()
开发者ID:OpenTreeOfLife,项目名称:gcmdr,代码行数:17,代码来源:general_utils.py


示例19: __init__

 def __init__(self, config, graphtype, minoccs=1, maxcoocs=1, maxcables=None, year=None):
     self.mongodb = CablegateDatabase(config['general']['mongodb'])["cablegate"]
     self.graphdb = GraphDatabase(config['general']['neo4j'])
     self.config = config
     if graphtype is None or graphtype=="occurrences":
         self.update_occurrences_network(minoccs, maxcoocs, maxcables, year, documents=False)
     elif graphtype == "cooccurrences":
         (nodecache, ngramcache) = self.update_occurrences_network(minoccs, maxcoocs, maxcables, year, documents=False)
         self.update_cooccurrences_network(nodecache, ngramcache, minoccs, maxcoocs)
开发者ID:YupeekDev,项目名称:cablegate_semnet,代码行数:9,代码来源:cablenetwork.py


示例20: test_can_return_node

 def test_can_return_node(self):
     with GraphDatabase.driver("bolt://localhost").session() as session:
         result = session.run("MERGE (a:Person {name:'Alice'}) RETURN a")
         assert len(result) == 1
         for record in result:
             alice = record[0]
             assert isinstance(alice, Node)
             assert alice.labels == {"Person"}
             assert alice.properties == {"name": "Alice"}
开发者ID:chiffa,项目名称:neo4j-python-driver,代码行数:9,代码来源:session_test.py



注:本文中的neo4j.GraphDatabase类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python v1.basic_auth函数代码示例发布时间:2022-05-27
下一篇:
Python tests.Person类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap