本文整理汇总了Python中py2neo.Graph方法的典型用法代码示例。如果您正苦于以下问题:Python py2neo.Graph方法的具体用法?Python py2neo.Graph怎么用?Python py2neo.Graph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类py2neo
的用法示例。
在下文中一共展示了py2neo.Graph方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import py2neo [as 别名]
# 或者: from py2neo import Graph [as 别名]
def __init__(self, host, port, user, password, threshold=40, secure=False, filepath=None, filename=None, folder_path=None):
"""Connects to neo4j database, loads options and set connectors.
@raise CuckooReportError: if unable to connect.
"""
self.threshold = int(threshold)
self.graph = Graph(host=host, user=user, password=password, secure=secure, port=port)
self.filepath = filepath
self.filename = filename
self.folder_path = folder_path
self.scout = ApiScout()
self.scout.setBaseAddress(0)
self.scout.loadWinApi1024(os.path.abspath(os.path.join(os.path.dirname(__file__))) + os.sep + "data" + os.sep + "winapi1024v1.txt")
self.magictest = magic.Magic(uncompress=True)
CWD = os.path.abspath(os.path.dirname(__file__))
USERDB = os.path.join(CWD, os.path.normpath("data/UserDB.TXT"))
with open(USERDB, 'rt') as f:
sig_data = f.read()
self.signatures = peutils.SignatureDatabase(data=sig_data)
if self.folder_path:
self.files = self.get_files(folder_path)
示例2: get_db_client
# 需要导入模块: import py2neo [as 别名]
# 或者: from py2neo import Graph [as 别名]
def get_db_client(dbhost, dbuser, dbpass, bolt=False):
"""Return a Neo4j DB session. bolt=True uses bolt driver"""
if verbose > 4:
print("DB Creds", dbhost, dbuser, dbpass)
if bolt:
bolt_url = "bolt://" + dbhost
auth_token = basic_auth(dbuser, dbpass)
try:
driver = GraphDatabase.driver(bolt_url, auth=auth_token, max_pool_size=5)
bolt_session = driver.session()
return bolt_session
except Exception as e:
print("Database connection/authentication error:", e)
sys.exit(1)
else:
login = "http://{0}:{1}@{2}:7474/db/data/".format(dbuser, dbpass, dbhost)
py2neo_session = Graph(login)
return py2neo_session
示例3: __init__
# 需要导入模块: import py2neo [as 别名]
# 或者: from py2neo import Graph [as 别名]
def __init__(self, host, port, username=None, password=None, ssl=False, timeout=None, bolt=None):
if timeout is not None:
http.socket_timeout = timeout
host_port = "{host}:{port}".format(host=host, port=port)
uri = "{scheme}://{host_port}/db/data/".format(scheme="https" if ssl else "http", host_port=host_port)
self.graph = Graph(uri, user=username, password=password, bolt=bolt, secure=ssl)
try:
self.neo4j_version = self.graph.dbms.kernel_version
except Unauthorized:
raise AuthError(uri)
except SocketError:
raise ConnectionError(uri)
示例4: __init__
# 需要导入模块: import py2neo [as 别名]
# 或者: from py2neo import Graph [as 别名]
def __init__(self, credentials):
BaseGraph.__init__(self)
self._type = "neo4j"
self.graph = Graph(credentials)
self.path = os.getcwd() + "\\csv"
if not os.path.exists(self.path):
os.mkdir(self.path)
示例5: __init__
# 需要导入模块: import py2neo [as 别名]
# 或者: from py2neo import Graph [as 别名]
def __init__(self):
cur_dir = os.path.abspath(os.path.dirname(__file__))
self.data_path = os.path.join(cur_dir, '../..', 'data/medical_sample.json')
self.g = Graph(
host=host, # neo4j 搭载服务器的ip地址,ifconfig可获取到
http_port=kg_port, # neo4j 服务器监听的端口号
user=user, # 数据库user name,如果没有更改过,应该是neo4j
password=password)
示例6: __init__
# 需要导入模块: import py2neo [as 别名]
# 或者: from py2neo import Graph [as 别名]
def __init__(self):
try:
self.g = Graph(
host=host,
http_port=kg_port,
user=user,
password=password)
except Exception as e:
logger.error('service down. please open neo4j service. %s' % e)
self.num_limit = answer_num_limit
示例7: neo
# 需要导入模块: import py2neo [as 别名]
# 或者: from py2neo import Graph [as 别名]
def neo(graph: BELGraph, connection: str, password: str):
"""Upload to neo4j."""
import py2neo
neo_graph = py2neo.Graph(connection, password=password)
to_neo4j(graph, neo_graph)
示例8: test_neo4j_remote
# 需要导入模块: import py2neo [as 别名]
# 或者: from py2neo import Graph [as 别名]
def test_neo4j_remote(self, mock_get):
from py2neo.database.status import GraphError
from py2neo import Graph
test_context = 'PYBEL_TEST_CTX'
neo_path = os.environ['NEO_PATH']
try:
neo = Graph(neo_path)
neo.data('match (n)-[r]->() where r.{}="{}" detach delete n'.format(PYBEL_CONTEXT_TAG, test_context))
except GraphError:
self.skipTest("Can't query Neo4J ")
except Exception:
self.skipTest("Can't connect to Neo4J server")
else:
with self.runner.isolated_filesystem():
args = [
'convert',
'--path', test_bel_simple,
'--connection', self.connection,
'--neo', neo_path,
'--neo-context', test_context
]
self.runner.invoke(cli.main, args)
q = 'match (n)-[r]->() where r.{}="{}" return count(n) as count'.format(PYBEL_CONTEXT_TAG, test_context)
count = neo.data(q)[0]['count']
self.assertEqual(14, count)
示例9: __init__
# 需要导入模块: import py2neo [as 别名]
# 或者: from py2neo import Graph [as 别名]
def __init__(self, username='neo4j', password='admin', bolt=7687):
self.graph = Graph(user=username, password=password, bolt_port=bolt)
示例10: neo4j_query_data
# 需要导入模块: import py2neo [as 别名]
# 或者: from py2neo import Graph [as 别名]
def neo4j_query_data(cypher, parameters=None, **kwparameters):
if type(cypher) != str:
print('Cypher query needs to be a string')
return pd.DataFrame([])
if len(cypher) == 0:
print('Cypher query cannot be empty')
return pd.DataFrame([])
if parameters and type(parameters) != dict:
print('Parameters need to be a dictionary')
return pd.DataFrame([])
neo4j_username = config.get_value('neo4j', 'neo4j_username')
neo4j_password = config.get_value('neo4j', 'neo4j_password')
neo4j_address = config.get_value('neo4j', 'neo4j_address')
secure_graph = Graph("bolt://{}:{}@{}".format(neo4j_username, neo4j_password, neo4j_address))
try:
results = secure_graph.run(cypher, parameters, **kwparameters)
except ClientError as e:
print('There was an issue with the cypher query')
print(e)
return pd.DataFrame([])
except AttributeError as e:
print('There was an authentication issue')
print(e)
return pd.DataFrame([])
results_pandas = pd.DataFrame(results.data())
return results_pandas
示例11: __init__
# 需要导入模块: import py2neo [as 别名]
# 或者: from py2neo import Graph [as 别名]
def __init__(self):
self.g = Graph(
host="127.0.0.1",
http_port=7474,
user="",
password=""
)
示例12: connectDB
# 需要导入模块: import py2neo [as 别名]
# 或者: from py2neo import Graph [as 别名]
def connectDB(self):
self.graph = Graph("http://localhost:7474", username="neo4j", password="8313178")
示例13: connectDB
# 需要导入模块: import py2neo [as 别名]
# 或者: from py2neo import Graph [as 别名]
def connectDB(self):
self.graph = Graph("http://localhost:7474", username="neo4j", password="123456")
示例14: connectDB
# 需要导入模块: import py2neo [as 别名]
# 或者: from py2neo import Graph [as 别名]
def connectDB(self):
self.graph = Graph("http://localhost:7474",username = "neo4j" , password = "8313178")
print("connect neo4j success!")
示例15: connectDB
# 需要导入模块: import py2neo [as 别名]
# 或者: from py2neo import Graph [as 别名]
def connectDB(self):
self.graph = Graph("http://localhost:7474", username="neo4j", password="8313178")
print('connect successed')