本文整理汇总了Python中py2neo.Graph.find_one方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.find_one方法的具体用法?Python Graph.find_one怎么用?Python Graph.find_one使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类py2neo.Graph
的用法示例。
在下文中一共展示了Graph.find_one方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createRelationships
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import find_one [as 别名]
def createRelationships():
global relationships
graph = Graph('http://localhost:7474/db/data')
for r in relationships:
NodeA = graph.find_one(r["start"]["collection"],property_key = "_id", property_value = str(r["start"]["_id"]))
NodeB = graph.find_one(r["end"]["collection"],property_key = "_id", property_value = str(r["end"]["_id"]))
graph.create(rel(NodeA,r["name"],NodeB))
示例2: Neo4j
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import find_one [as 别名]
class Neo4j():
graph = None
def __init__(self):
print("create neo4j class ...")
def connectDB(self):
self.graph = Graph("http://localhost:7474", username="neo4j", password="8313178")
print('connect successed')
def matchItembyTitle(self,value):
answer = self.graph.find_one(label="Item",property_key="title",property_value=value)
return answer
# 根据title值返回互动百科item
def matchHudongItembyTitle(self,value):
answer = self.graph.find_one(label="HudongItem",property_key="title",property_value=value)
return answer
# 返回限定个数的互动百科item
def getAllHudongItem(self, limitnum):
List = []
ge = self.graph.find(label="HudongItem", limit=limitnum)
for g in ge:
List.append(HudongItem(g))
print('load AllHudongItem over ...')
return List
#test = Neo4j()
#test.connectDB()
#a = test.getLabeledHudongItem('labels.txt')
#print(a[10].openTypeList)
示例3: Achievement
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import find_one [as 别名]
class Achievement(object):
def __init__(self, graph_db):
self.name = None
self.id = None
self.description = None
self.title = None
self.is_visible = True
self.date = None
self._graph_db = Graph(settings.DATABASE_URL)
@property
def achievement_node(self):
return self._graph_db.find_one(GraphLabel.ACHIEVEMENT,
property_key='id',
property_value=self.id)
@property
def achievement_interests(self):
"""
get list of interests linked to this achievement
:return:
"""
# ach_interests = self.graph_db.match(start_node=self.achievement_node,
# rel_type=Relationship.)
return None
示例4: Graph
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import find_one [as 别名]
class Graph(object):
def __init__(self, neo4j_uri):
self.graph = NeoGraph(neo4j_uri)
def find_node(self, label, node_id):
args = dict(property_key="node_id", property_value=node_id)
return self.graph.find_one(label, **args)
def create_user(self, args):
node = self.find_node("User", args["username"])
if not node:
properties = dict(
node_id=args["username"],
name=args["name"],
city=args["city"]
)
node = Node("User", **properties)
self.graph.create(node)
return node, True
return node, False
def delete_user(self, user):
node = self.find_node("User", user)
if node:
self.graph.delete(node)
return True
return False
示例5: Neo4j
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import find_one [as 别名]
class Neo4j():
graph = None
def __init__(self):
print("create neo4j class ...")
def connectDB(self):
self.graph = Graph("http://localhost:7474", username="neo4j", password="8313178")
def matchItembyTitle(self,value):
answer = self.graph.find_one(label="Item",property_key="title",property_value=value)
return answer
# 根据title值返回互动百科item
def matchHudongItembyTitle(self,value):
answer = self.graph.find_one(label="HudongItem",property_key="title",property_value=value)
return answer
示例6: NeoProvider
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import find_one [as 别名]
class NeoProvider(object):
def __init__(self):
# TODO read this from a config file
uri = "http://neo4j:[email protected]:7474/db/data"
self.graph = Graph(uri)
self.store = Store(self.graph)
def get_start_screen(self):
# Fetch the start node
start_node = self.graph.find_one("screen", "start", True)
# Find all the navigations from the start node
nav_rels = self.graph.match(start_node, "nav")
# Find all the assets for the start node
asset_rels = self.graph.match(start_node, "hasAsset")
# Construct the DTOs
assets = [Asset(asset_rel.end_node) for asset_rel in asset_rels]
navs = [Navigation(nav_rel) for nav_rel in nav_rels]
start_screen = Screen(start_node, navs, assets)
return start_screen
def get_next_screen(self, current_screen_key, option):
# Fetch the current node
current_node = self.graph.find_one("screen", "id", current_screen_key)
# Navigate to the next node via option
current_rels = self.graph.match(current_node, "nav")
selected_rel = [rel for rel in current_rels if rel.properties['opt'] == int(option)][0]
next_node = selected_rel.end_node
# Grab new navigations and assets for the next node
next_nav_rels = self.graph.match(next_node, "nav")
asset_rels = self.graph.match(next_node, "hasAsset")
# Construct the DTOs
assets = [Asset(asset_rel.end_node) for asset_rel in asset_rels]
navs = [Navigation(nav_rel) for nav_rel in next_nav_rels]
next_screen = Screen(next_node, navs, assets)
return next_screen
示例7: Neo4j
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import find_one [as 别名]
class Neo4j():
graph = None
def __init__(self):
print("create neo4j class ...")
def connectDB(self):
self.graph = Graph("http://localhost:7474", username="neo4j", password="8313178")
def matchItembyTitle(self,value):
answer = self.graph.find_one(label="Item",property_key="title",property_value=value)
return answer
# 根据title值返回互动百科item
def matchHudongItembyTitle(self,value):
answer = self.graph.find_one(label="HudongItem",property_key="title",property_value=value)
return answer
# 根据entity的名称返回关系
def getEntityRelationbyEntity(self,value):
answer = self.graph.data("MATCH (entity1) - [rel] -> (entity2) WHERE entity1.title = \"" +value +"\" RETURN rel,entity2")
return answer
示例8: before_all
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import find_one [as 别名]
def before_all(context):
# import falcon_test
# context.attachment_dir = os.path.join(os.path.dirname(falcon_test.__file__), 'tests/data')
# context.sms_path = os.path.join(os.path.dirname(falcon_test.__file__), '../../var/sms/')
# context.mail_path = os.path.join(os.path.dirname(falcon_test.__file__), '../../var/mail/')
# clear database
graph_db = Graph(settings.DATABASE_URL)
# graph_db.delete_all()
new_user_node = graph_db.find_one('USER',
property_key='email',
property_value='[email protected]')
graph_db.delete(new_user_node)
interest_node = graph_db.find_one('INTEREST', property_key='name',
property_value=PERSONAS['interest']['name'])
interest_relationships = graph_db.match(start_node=None,
rel_type='INTERESTED_IN',
end_node=interest_node)
for relationship in interest_relationships:
graph_db.delete(relationship)
graph_db.delete(interest_node)
context.base_url = "http://localhost:8000"
benv.before_all(context)
示例9: AgoraOrganization
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import find_one [as 别名]
class AgoraOrganization(object):
def __init__(self):
self.name = None
self.unique_id = None
self.mission_statement = None
self.email = None
self.is_open = False
self.is_invite_only = False
self.website = None
self.graph_db = Graph()
@property
def org_node(self):
return self.graph_db.find_one(AgoraLabel.ORGANIZATION,
property_key='name',
property_value=self.name)
@property
def org_members(self):
"""
list of the members of the organization
:return: list of tuple of member name, email
"""
org_members_nodes = self.graph_db.match(start_node=self.org_node,
rel_type=AgoraRelationship.MEMBER_OF,
end_node=None)
org_members_list = []
for item in org_members_nodes:
org_members_list.append((item.end_node["name"], item.end_node["email"]))
return org_members_list
def create_organization(self):
"""
create a new organization
:return: py2neo Node
"""
self.unique_id = str(uuid.uuid4())
new_org_properties = {
"name": self.name,
"mission_statement": self.mission_statement,
"unique_id": self.unique_id,
"email": self.email,
"is_open": self.is_open,
"is_invite_only": self.is_invite_only,
"website": self.website}
new_org_node = Node.cast(AgoraLabel.ORGANIZATION, new_org_properties)
self.graph_db.create(new_org_node)
return new_org_node
示例10: __init__
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import find_one [as 别名]
class Build_Configuration:
def __init__(self):
self.graph = Graph()
self.graph.delete_all()
self.namespace = ["Start"]
self.parent_node = []
def check_duplicates(self, label, name):
# print "label",label,name
if self.graph.find_one(label, property_key="name", property_value=name) != None:
raise ValueError("Duplicate Node", label, name)
def get_namespace(self, name):
print self.namespace, name
temp = copy.deepcopy(self.namespace)
temp.append(name)
return_value = "/".join(temp)
return return_value
def get_parent_node(self):
return self.parent_node[-1]
def pop_namespace(self):
del self.namespace[-1]
del self.parent_node[-1]
# concept of namespace name is a string which ensures unique name
# the name is essentially the directory structure of the tree
def construct_node(self, push_namespace, relationship, label, name, properties):
namespace = self.get_namespace(name)
self.check_duplicates(label, name=namespace)
node = Node(label)
node.properties["namespace"] = namespace
node.properties["name"] = name
for i in properties.keys():
node.properties[i] = properties[i]
self.graph.create(node)
if len(self.parent_node) != 0:
relation_enity = Relationship(self.get_parent_node(), relationship, node)
self.graph.create(relation_enity)
if push_namespace == True:
self.namespace.append(name)
self.parent_node.append(node)
示例11: AgoraAchievement
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import find_one [as 别名]
class AgoraAchievement(object):
def __init__(self, graph_db):
self.name = None
self.unique_id = None
self.description = None
self.title = None
self.is_visible = True
self.date = None
self.graph_db = Graph()
@property
def achievement_node(self):
return self.graph_db.find_one(AgoraLabel.ACHIEVEMENT,
property_key='unique_id',
property_value=self.unique_id)
@property
def achievement_interests(self):
"""
示例12: __init__
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import find_one [as 别名]
class Neo4JClient:
"""Client for Neo4J"""
def __init__(self):
authenticate("localhost:7474", secrets.NEO4J_USERNAME , secrets.NEO4J_PASSWORD)
self.graph = Graph("http://localhost:7474/db/data/")
def create_user_node(self, user_dict):
mykeys = ['name', 'id_str', 'description', 'screen_name']
user_dict = {k: v for (k, v) in user_dict.items() if k in mykeys}
user_node = Node('Person', user_dict['name'], **user_dict)
self.graph.create(user_node)
return user_node
def find_user_node(self, key, value):
return self.graph.find_one('Person', property_key=key, property_value=value)
def create_rel(self, start_node, end_node, rel_type):
return self.graph.create((start_node, rel_type, end_node))
def update_user_node(id, user_dict):
pass
示例13: authenticate
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import find_one [as 别名]
pw=open('neo4j_pw').readline().strip()
authenticate("localhost:7474", "neo4j", pw)
# connect to authenticated graph database
graph = Graph()
tx = graph.cypher.begin()
conceptnodes={}
tasknodes={}
contrastnodes={}
# Create concept nodes
for i in range(len(concept_ids)):
tx.append('CREATE (%s:concept {name: "%s", id:"%s"}) RETURN %s'%(concept_ids[i],
concept_names[i],concept_ids[i],concept_ids[i]))
if graph.find_one('concept',property_key='id', property_value=concept_ids[i]) == None:
conceptnode= Node("concept",name=concept_names[i],id=concept_ids[i])
graph.create(conceptnode)
# Create task nodes
for i in range(len(task_ids)):
tx.append('CREATE (%s:task {name: "%s", id:"%s"}) RETURN %s'%(task_ids[i],
task_names[i],task_ids[i],task_ids[i]))
if graph.find_one('task',property_key='id', property_value=task_ids[i]) == None:
tasknode= Node("task", name=task_names[i],id=task_ids[i])
graph.create(tasknode)
# Create contrast nodes, associate with task
for i in range(len(contrast_tasks)):
tasknode=graph.find_one('task',property_key='id', property_value=contrast_tasks[i])
path = Path(tasknode,Rel("HASCONTRAST"),Node("contrast", name=contrast_names[i],id=contrast_ids[i]))
示例14: len
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import find_one [as 别名]
from py2neo import Node, Relationship, Graph
import requests, json, sys
print "Performing pathfinding search with", sys.argv
if len(sys.argv) != 4:
print "You failed to enter the correct arguments."
print "article one, article two, depth"
else:
graph = Graph("http://neo4j:[email protected]:7474/db/data/")
a = graph.find_one("Article", "lowerTitle", sys.argv[1].lower())
b = graph.find_one("Article", "lowerTitle", sys.argv[2].lower())
#print a, b
if a and b:
ENDPOINT = "http://neo4j:[email protected]:7474/db/data/"
request = {
"to":ENDPOINT+"node/"+str(b._id),
"max_depth": int(sys.argv[3]),
"relationships": {
"type":"LINKS",
"direction":"out"
},
"algorithm":"allSimplePaths"
}
r = requests.post(ENDPOINT+"node/"+str(a._id)+"/paths", data=json.dumps(request))
# print r.json()
if r.status_code == 200:
for path in r.json():
print "Path:"
for node in path['nodes']:
示例15: Cursor
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import find_one [as 别名]
f.write(user);
f.write('\n');
f.close();
'''
for i in Cursor(api.followers, id=user).items():
print "adding " + i.screen_name;
f.write("\t"+i.screen_name+"\n");
to_be_networked.append(i.screen_name);
'''
while True:
try:
temp_user = api.get_user(user);
temp_ratio = float(temp_user.followers_count) / float(temp_user.friends_count);
base_node = graph.find_one("regular", "screen_name", user);
if not base_node:
base_node = graph.find_one("verified", "screen_name", user);
if not base_node:
base_node = graph.find_one("cautious", "screen_name", user);
if not base_node:
if temp_user.verified:
base_node = Node("verified", screen_name=user, ratio=temp_ratio, tweets=temp_user.statuses_count, created=temp_user.created_at, followers=temp_user.followers_count, following=temp_user.friends_count, location=temp_user.location);
else:
if temp_ratio < 0.01:
base_node = Node("cautious", screen_name=user, ratio=temp_ratio, tweets=temp_user.statuses_count, created=temp_user.created_at, followers=temp_user.followers_count, following=temp_user.friends_count, location=temp_user.location);
else:
base_node = Node("regular", screen_name=user, ratio=temp_ratio, tweets=temp_user.statuses_count, created=temp_user.created_at, followers=temp_user.followers_count, following=temp_user.friends_count, location=temp_user.location);