当前位置: 首页>>代码示例>>Python>>正文


Python Graph.delete_all方法代码示例

本文整理汇总了Python中py2neo.Graph.delete_all方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.delete_all方法的具体用法?Python Graph.delete_all怎么用?Python Graph.delete_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在py2neo.Graph的用法示例。


在下文中一共展示了Graph.delete_all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createGraph

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import delete_all [as 别名]
	def createGraph(self):
		""" 
		form: 
		(self) --> print

		description: 
		function that creates the neo4j graph

		exemple:
		>>> graphWN..createGraph()
		creating graph...
		graph created

		"""
		print "creating graph..."
		graph = Graph()
		graph.delete_all()
		for synset in self.synset2synonym:
		  word_node = Node("word", literal=self.synset2word[synset])
		  #print synset, self.synset2synonym[synset]
		  #if graph.find(self.synset2word[synset])!=None:
		    #print "Exist"
		    #word_node=graph.find_one("word", 'literal', self.synset2word[synset])
		    #print word_node
		  synset_node = Node("synset", name=synset)
		  word_has_synset = Relationship(word_node, "has_synset", synset_node)
		  if self.synset2synonym[synset][0]!='_EMPTY_':
		    for synonym in self.synset2synonym[synset]:
		      word_syn = Node("word", literal=synonym)
		      synset_has_synonym = Relationship(synset_node, "has_synonym", word_syn)
		      graph.create(synset_has_synonym)
		  graph.create(word_has_synset)
		print "graph created"
开发者ID:muvikt,项目名称:BaseDeDonnees,代码行数:35,代码来源:script.py

示例2: GraphImporter

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import delete_all [as 别名]
class GraphImporter(object):
  def __init__(self, graphurl, commitEvery=100):
    self.graph = Graph(graphurl)
    self.commitEvery = commitEvery
    self._act = None
    self._actC = commitEvery

  def delete_all(self):
    self.graph.delete_all()
    self.graph.cypher.run('CREATE INDEX ON :_Network_Node(id)')
    self.graph.cypher.run('CREATE INDEX ON :_Set_Node(id)')

  def _tx(self):
    if self._act is not None:
      return self._act
    self._act = self.graph.cypher.begin()
    self._actC = self.commitEvery
    return self._act

  def _done(self):
    self._actC -= 1
    if self._actC == 0:  # commit
      self._act.process()
      self._act.commit()
      sys.stdout.write('.')
      self._act = None

  def _close(self):
    if self._act is not None:  # commit last tx
      self._actC = 1
      self._done()

  def add_node(self, labels, node_id, properties):
    tx = self._tx()
    add_node(tx, labels, node_id, properties)
    self._done()

  def done_nodes(self):
    self._done()

  def append(self, query):
    tx = self._tx()
    tx.append(query)
    self._done()


  def add_edge(self, label, source_node_id, target_node_id, properties, source_type=u'_Network_Node', update_only=False):
    tx = self._tx()
    add_edge(tx, label, source_node_id, target_node_id, properties, source_type, update_only)
    self._done()

  def __call__(self, query):
    tx = self._tx()
    tx.append(query)
    self._done()

  def finish(self):
    self._close()
开发者ID:Caleydo,项目名称:pathfinder_graph,代码行数:60,代码来源:import_utils.py

示例3: Friends

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import delete_all [as 别名]
class Friends(object):
	def __init__(self, uri, username, password):
		self.neo = Graph(uri)
		self.uri = uri
		self.username = username
		self.password = password
	
	def create_person(self, name):
		node = Node("Person", name=name)
		self.neo.create(node)
		return node

	def make_mutual_friends(self, node1, node2):
		relationship = Relationship(node1, "FRIENDS_WITH", node2)
		relationship2 = Relationship(node2, "FRIENDS_WITH", node1)
		self.neo.create(relationship)
		self.neo.create(relationship2)

	def suggestions_for(self, node):
		returnType = "node"

		payload = {
			"order": "breadth_first",
			"uniqueness": "node_global",
			"relationships": {
				"type": "FRIENDS_WITH",
				"direction": "in"
			},
			"return_filter" : {
				"body" : "position.length() == 2;",
				"language" : "javascript"
			},
			"max_depth": 2
		}

		payload = json.dumps(payload)

		headers = {
			"Accept": "application/json; charset=UTF-8",
			"Authorization": "Basic bmVvNGo6cGFzc3dvcmQ=",
			"Content-Type": "application/json"
		}
		
		uri = self.uri + "node/" + str(node._id) + "/traverse/" + returnType
		res = requests.post(uri, data=payload, headers=headers).json()

		recommendations_list = []
		for el in res:
			recommendations_list.append(el["data"]["name"])
		recommendations = ', '.join(recommendations_list)

		return recommendations

	def reset(self):
		self.neo.delete_all()
开发者ID:csharpie,项目名称:neo4fun,代码行数:57,代码来源:friends.py

示例4: main1

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import delete_all [as 别名]
def main1():
    authenticate("localhost:7474", "neo4j", "1234")
    graph = Graph(GRAPH_CONNECTION_STRNIG)

    graph.delete_all()

    banana = Node("Fruit", name="banana", colour="yellow", tasty=True)
    graph.create(banana)

    t = graph.merge_one("Fruit", 'name', 'apple')
    t['colour'] = 'green'
    t['tasty'] = True
    t.push()
开发者ID:vovacooper,项目名称:FreeTv,代码行数:15,代码来源:update_tv_data_new.py

示例5: main

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import delete_all [as 别名]
def main():
    if not has_py2neo:
        sys.exit("[!] py2neo must be installed for this script.")

    if not has_evtx:
        sys.exit("[!] python-evtx must be installed for this script.")

    if not has_lxml:
        sys.exit("[!] lxml must be installed for this script.")

    if not has_lxml:
        sys.exit("[!] numpy must be installed for this script.")

    if not has_changefinder:
        sys.exit("[!] changefinder must be installed for this script.")

    try:
        graph_http = "http://" + NEO4J_USER + ":" + NEO4J_PASSWORD +"@" + NEO4J_SERVER + ":" + NEO4J_PORT + "/db/data/"
        GRAPH = Graph(graph_http)
    except:
        sys.exit("[!] Can't connect Neo4j Database.")

    print("[*] Script start. %s" % datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S"))

    if args.run:
        try:
            app.run(threaded=True, host="0.0.0.0", port=WEB_PORT)
        except:
            sys.exit("[!] Can't runnning web application.")

    # Delete database data
    if args.delete:
        GRAPH.delete_all()
        print("[*] Delete all nodes and relationships from this Neo4j database.")

    if args.evtx:
        for evtx_file in args.evtx:
            if not os.path.isfile(evtx_file):
                sys.exit("[!] Can't open file {0}.".format(evtx_file))
        parse_evtx(args.evtx, GRAPH)

    if args.xmls:
        for xml_file in args.xmls:
            if not os.path.isfile(xml_file):
                sys.exit("[!] Can't open file {0}.".format(xml_file))
        parse_evtx(args.xmls, GRAPH)

    print("[*] Script end. %s" % datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S"))
开发者ID:Puujee0238,项目名称:LogonTracer,代码行数:50,代码来源:logontracer.py

示例6: __init__

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import delete_all [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)
开发者ID:glenn-edgar,项目名称:cloud_scada,代码行数:49,代码来源:graph_functions.py

示例7: Neo4j

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import delete_all [as 别名]
class Neo4j():

    def __init__(self, host='localhost:7474', username='neo4j', password='neo4j'):
        if not has_py2neo:
            raise Exception('py2neo is required, please install: pip install py2neo')
        authenticate(host, username, password)
        self.graph = Graph("http://{}/db/data/".format(host))

    def load_events_directory(self, directory):
        self.events = []
        for path in glob.glob(os.path.join(directory, '*.json')):
            e = MISPEvent()
            e.load(path)
            self.import_event(e)

    def del_all(self):
        self.graph.delete_all()

    def import_event(self, event):
        tx = self.graph.begin()
        event_node = Node('Event', uuid=event.uuid, name=event.info)
        # event_node['distribution'] = event.distribution
        # event_node['threat_level_id'] = event.threat_level_id
        # event_node['analysis'] = event.analysis
        # event_node['published'] = event.published
        # event_node['date'] = event.date.isoformat()
        tx.create(event_node)
        for a in event.attributes:
            attr_node = Node('Attribute', a.type, uuid=a.uuid)
            attr_node['category'] = a.category
            attr_node['name'] = a.value
            # attr_node['to_ids'] = a.to_ids
            # attr_node['comment'] = a.comment
            # attr_node['distribution'] = a.distribution
            tx.create(attr_node)
            member_rel = Relationship(event_node, "is member", attr_node)
            tx.create(member_rel)
            val = Node('Value', name=a.value)
            ev = Relationship(event_node, "has", val)
            av = Relationship(attr_node, "is", val)
            s = val | ev | av
            tx.merge(s)
            #tx.graph.push(s)
        tx.commit()
开发者ID:CIRCL,项目名称:PyMISP,代码行数:46,代码来源:neo4j.py

示例8: main2

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import delete_all [as 别名]
def main2():
    authenticate("localhost:7474", "neo4j", "1234")
    graph = Graph(GRAPH_CONNECTION_STRNIG)

    graph.delete_all()

    banana = Node("Fruit", name="banana", colour="yellow", tasty=True)
    graph.create(banana)

    t = graph.merge_one("Fruit", 'name', 'apple')
    t['colour'] = 'green'
    t['tasty'] = True
    t.push()

    alice = Node("Person", name="Alice")
    bob = Node("Person", name="Bob")
    alice_knows_bob = Relationship(alice, "KNOWS", bob, since=1999)
    graph.create(alice)
    graph.create(bob)
    graph.create(alice_knows_bob)
开发者ID:vovacooper,项目名称:FreeTv,代码行数:22,代码来源:update_tv_data_new.py

示例9: TestUser

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import delete_all [as 别名]

#.........这里部分代码省略.........
                                                        'indices': [111, 133],
                                                        'url': 'http://t.co/GVkMDCUzW3'}]},
                              'url': {'urls': [{'display_url': 'britishgas.co.uk/the-source',
                                                'expanded_url': 'http://www.britishgas.co.uk/the-source',
                                                'indices': [0, 22],
                                                'url': 'http://t.co/rlasQ9hHeu'}]}},
                 'favourites_count': 431,
                 'follow_request_sent': False,
                 'followers_count': 36081,
                 'following': False,
                 'friends_count': 4774,
                 'geo_enabled': True,
                 'id': 46630225,
                 'id_str': '46630225',
                 'is_translation_enabled': False,
                 'is_translator': False,
                 'lang': 'en',
                 'listed_count': 400,
                 'location': 'Staines, Middlesex',
                 'name': 'British Gas ',
                 'notifications': False,
                 'profile_background_color': '00AEDE',
                 'profile_background_image_url': 'http://pbs.twimg.com/profile_background_images/831694128/7187a2d2a890b67c21ae04c18861f5b9.jpeg',
                 'profile_background_image_url_https': 'https://pbs.twimg.com/profile_background_images/831694128/7187a2d2a890b67c21ae04c18861f5b9.jpeg',
                 'profile_background_tile': False,
                 'profile_banner_url': 'https://pbs.twimg.com/profile_banners/46630225/1400584801',
                 'profile_image_url': 'http://pbs.twimg.com/profile_images/552048129055289344/6oPZvR3T_normal.jpeg',
                 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/552048129055289344/6oPZvR3T_normal.jpeg',
                 'profile_link_color': '1890C4',
                 'profile_location': None,
                 'profile_sidebar_border_color': 'FFFFFF',
                 'profile_sidebar_fill_color': 'D9EDF9',
                 'profile_text_color': '333333',
                 'profile_use_background_image': True,
                 'protected': False,
                 'screen_name': 'BritishGas',
                 'status': {'contributors': None,
                            'coordinates': None,
                            'created_at': 'Mon Mar 02 18:45:18 +0000 2015',
                            'entities': {'hashtags': [],
                                         'media': [{'display_url': 'pic.twitter.com/ec4iusBe4Q',
                                                    'expanded_url': 'http://twitter.com/BritishGas/status/572467734367191041/photo/1',
                                                    'id': 572425479120007168,
                                                    'id_str': '572425479120007168',
                                                    'indices': [108, 130],
                                                    'media_url': 'http://pbs.twimg.com/media/B_Gp8L9UsAAe8ap.png',
                                                    'media_url_https': 'https://pbs.twimg.com/media/B_Gp8L9UsAAe8ap.png',
                                                    'sizes': {'large': {'h': 500,
                                                                        'resize': 'fit',
                                                                        'w': 1000},
                                                              'medium': {'h': 300,
                                                                         'resize': 'fit',
                                                                         'w': 600},
                                                              'small': {'h': 170,
                                                                        'resize': 'fit',
                                                                        'w': 340},
                                                              'thumb': {'h': 150,
                                                                        'resize': 'crop',
                                                                        'w': 150}},
                                                    'type': 'photo',
                                                    'url': 'http://t.co/ec4iusBe4Q'}],
                                         'symbols': [],
                                         'urls': [],
                                         'user_mentions': []},
                            'favorite_count': 4,
                            'favorited': False,
                            'geo': None,
                            'id': 572467734367191041,
                            'id_str': '572467734367191041',
                            'in_reply_to_screen_name': None,
                            'in_reply_to_status_id': None,
                            'in_reply_to_status_id_str': None,
                            'in_reply_to_user_id': None,
                            'in_reply_to_user_id_str': None,
                            'lang': 'en',
                            'place': None,
                            'possibly_sensitive': False,
                            'retweet_count': 3,
                            'retweeted': False,
                            'source': '<a href="https://ads.twitter.com" '
                                      'rel="nofollow">Twitter Ads</a>',
                            'text': 'Afraid of the dust bunny lurking behind your fridge? '
                                    'Check out our guide to cleaning up those fridge coils: '
                                    'http://t.co/ec4iusBe4Q',
                            'truncated': False},
                 'statuses_count': 13664,
                 'time_zone': 'London',
                 'url': 'http://t.co/rlasQ9hHeu',
                 'utc_offset': 0,
                 'verified': True}

    def setUp(self):
        self.g = Graph(get_graph_url("dev"))

    def tearDown(self):
        self.g.delete_all()

    def testAddNewUser(self):
        u = User.new(self.g, properties=self.USER_DATA)
        u.get_followers()
开发者ID:salimfadhley,项目名称:neowrapper,代码行数:104,代码来源:test_user.py

示例10: print

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import delete_all [as 别名]
    print("Ended Tags Load" + str(datetime.datetime.now()))
    return
    
    


##################BEGIN PROCESS HERE#########################
# ------------------------------------------------------------
#  this 'for loop' will set 'line' to an input line from system 
#    standard input file
# ------------------------------------------------------------
initTags()
graph = Graph()


graph.delete_all()


#CREATE ALL GENRE NODES HERE
ActionGenreNode = Node("Genre", name="Action")
AdventureGenreNode = Node("Genre", name="Adventure")
AnimationGenreNode = Node("Genre", name="Animation")
ChildrensGenreNode = Node("Genre", name="Childrens")
ComedyGenreNode = Node("Genre", name="Comedy")
CrimeGenreNode = Node("Genre", name="Crime")
DocumentaryGenreNode = Node("Genre", name="Documentary")
DramaGenreNode = Node("Genre", name="Drama")
FantasyGenreNode = Node("Genre", name="Fantasy")
FilmNoirGenreNode = Node("Genre", name="FilmNoir")
HorrorGenreNode = Node("Genre", name="Horror")
MusicalGenreNode = Node("Genre", name="Musical")
开发者ID:pcwynar,项目名称:neo4j,代码行数:33,代码来源:GraphInsertMoviesTagsGenres.py

示例11: SyntaxGraph

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import delete_all [as 别名]
class SyntaxGraph():
    
    """
    The aim of this class is to find associated words to database syntax.
    A user will input a sentence, and these associations will be used to
    find the correct SQL statement to execute in the database.
    
    The relations between words are modelled as a graph. The nodes of the 
    graph are the words, and the edges (relationships) between nodes
    represent when a word means another word (e.g. is a synonym).
    
    The graph is "seeded" using a set of database syntax words, finding 
    synonyms/related words to these initial words using a call to a
    thesaurus API.
    
    The graph is then "grown" from the resulting synonyms using subsequent
    API calls, in a recursive fashion.
    
    When a user enters a sentence, this graph will be used to find 
    database syntax words which are within a certain "degree of 
    separation" from each word in the sentence, in an attempt to 
    start building a SQL query from this sentence.
    """
    
    def __init__(self, seed_words=None, seed_mappings=None):
        
        self.sql_terms = SQLTerms().sql_terms
        
        self.graph = Graph(DB_URI)
        self.tx = self.graph.cypher.begin()
        
        self.seed_mappings = seed_mappings or {'where': ['filter', 'for', 'during'],
                                               'from': ['source', 'in'],
                                               'into': ['toward', 'within', 'inside'],
                                               'group':['by'],
                                               'and': ['with']}
        
        self.seed_words = seed_words or [x for x in self.sql_terms if x not in self.seed_mappings]
    
        self.seed_words.extend([x for x in self.seed_mappings.iterkeys()])
        
        self.exclude_words = ['display']
        
    def seed(self, reset=False):
        
        print 'Seeding graph'
        
        if reset:
            self.graph.delete_all()
        
        for word in self.seed_words:
            if not self.already_called(word):
                self.add_synonyms(word)
            if word in self.seed_mappings:
                print 'Mapping %s to %s' % ( ','.join(self.seed_mappings[word]), word )
                base = self.graph.merge_one('Word', 'name', word)
                synonyms = [self.graph.merge_one('Word', 'name', x) for x in self.seed_mappings[word]]
                [self.graph.create_unique(Relationship(base, 'MEANS', synonym)) for synonym in synonyms]
                [self.graph.create_unique(Relationship(synonym, 'MEANS', base)) for synonym in synonyms]
            
                
    def grow(self, levels=1):
        
        print 'Levels left: %d' % levels
        
        query = ''' MATCH (w:Word)
                    WHERE NOT HAS (w.called)
                    RETURN w.name
                '''
        
        results = self.graph.cypher.execute(query)     
        
        for word in results:
            self.add_synonyms(word['w.name'])
            
        if levels > 1:
            self.grow(levels-1)
                
            
    def already_called(self, word):
        
        if len (self.graph.cypher.execute('''MATCH (w:Word)
                                             WHERE w.name = '%s'
                                               AND HAS (w.called)
                                             RETURN w.name 
                                          ''' % word) ) > 0:
            return True
        
    def update_set_called(self, word):
        
        word_node = self.graph.merge_one('Word', 'name', word)
        word_node.properties['called'] = 1
        word_node.push()
        
    def add_synonyms(self, word):
                                     
        url = 'http://words.bighugelabs.com/api/2/%s/%s/json' % (API_KEY, word)
        print url
        
        response = requests.get(url)
#.........这里部分代码省略.........
开发者ID:ndesmo,项目名称:Search-to-SQL,代码行数:103,代码来源:SearchToSQL.py

示例12: Neo4jWrapper

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import delete_all [as 别名]
class Neo4jWrapper(object):

    def __init__(self, user_name, password, connection_string="", current_id=1):
        self.connection_string = connection_string \
                    if connection_string != "" \
                    else "http://"+ user_name+":"+password+"@localhost:7474/db/data/"
        self.graph_db = Graph(self.connection_string)
        self.current_id = current_id

    def delete_all_nodes(self):
        self.graph_db.delete_all()

    def insert_single_node(self, node_map):
        """
        Insert pre specified node type
        :param node_map:  format {'url':, 'brand': , 'tld': , 'website':}
        :return:
        """
        self.graph_db.cypher.execute("CREATE (w:Websites {id:{I}, brand:{BRAND}, website:{W}, url:{U}, tld:{TLD}})",
                  {"BRAND": node_map['brand'], "I": self.current_id, "W": node_map['website'],
                   "U": node_map['url'], "TLD": node_map['tld']})
        self.current_id += 1

    def insert_as_transaction(self, node_map_list):
        """
        Insert nodes with transaction
        :param node_map_list: list of data in format {'url':, 'brand': , 'tld': , 'website':}
        :return: None
        """
        tx = self.graph_db.cypher.begin()
        for node_map in node_map_list:
            self.current_id += 1
            tx.append("CREATE (w:Websites {id:{I}, brand:{B}, website:{W}, url:{U}, tld:{T}})", {
                "B": node_map['brand'], "I": self.current_id, "W": node_map['website'],
                "U": node_map['url'], "T": node_map['tld']})

        tx.commit()

    def batch_create(self, node_map_list):
        """ Execute multiple insert as batch jobs
        :param node_map_list:
        """
        batch = neo4j.WriteBatch(self.graph_db)
        for node_map in node_map_list:
            self.current_id += 1
            batch.append(self.create_cypher_job(None, node_map))
        return batch.submit()

    def create_cypher_job(self, statement=None, params_dict=dict()):
        """
        Create cypher job for bach insert
        :param statement:
        :param params_dict:
        :return: neo4j.CypherJob
        """
        default_statement = "CREATE (w:Websites {id:{I}, brand:{B}, website:{W}, url:{U}, tld:{T}})"
        default_params = {"B": params_dict['brand'], "I": self.current_id, "W": params_dict['website'],
                          "U": params_dict['url'], "T": params_dict['tld']}

        if statement is None or len(params_dict) is 0:
            return neo4j.CypherJob(default_statement, default_params)
        else:
            return neo4j.CypherJob(statement, params_dict)

    def insert_single_with_loop(self, node_map_list, insertion_type="single", insertion_size=0):
        """
        Convenient method to loop on data list
        :param node_map_list: list for dict in format {'url':, 'brand': , 'tld': , 'website':}
        :param insertion_type: single | transaction | batch
        :param insertion_size: integer - the number of nodes inserted in a single transaction
        :return: None
        """
        cnt = 0
        temp_node_holder = []
        for node_map in node_map_list:
            if insertion_type is 'single':
                self.insert_single_node(node_map)
            elif insertion_type is 'transaction' or 'batch':
                cnt += 1
                if cnt % insertion_size is 0:
                    self.insert_as_transaction(temp_node_holder) \
                        if insertion_type is 'transaction' \
                        else self.batch_create(temp_node_holder)
                    # replace line instead new line
                    sys.stdout.write("\r++++INSERTED %d++++" % cnt)
                    sys.stdout.flush()
                    temp_node_holder = []
                else:
                    temp_node_holder.append(node_map)

        # insert any remaining
        if insertion_type is 'transaction' or 'batch':
            self.insert_as_transaction(temp_node_holder) \
                        if insertion_type is 'transaction' \
                        else self.batch_create(temp_node_holder)
开发者ID:pete314,项目名称:neo4j_adventures,代码行数:97,代码来源:Neo4jWrapper.py

示例13: PopItToNeo

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import delete_all [as 别名]
class PopItToNeo(object):
    def __init__(self):
        config = yaml.load(open("config.yaml"))
        self.endpoint = "https://sinar-malaysia.popit.mysociety.org/api/v0.1"

        # you know so that you can override this. why? I am not sure
        self.membership_field = "memberships"
        self.person_field = "persons"
        self.organization_field = "organizations"
        self.post_field = "posts"
        self.graph = Graph(config["graph_db"])
        if config["refresh"] == True:
            self.graph.delete_all()

        # Because I am still not familiar to query with cypher
        # So lets cache here. Hopefully the memory usage don't kill me
        self.organization_processed = {}
        self.person_processed = {}
        self.post_processed = {}

    def process_membership(self):
        # So lets start from membership
        membership_url = "%s/%s" % (self.endpoint, self.membership_field)
        while True:
            logging.warning("Processing %s" % membership_url)
            data = self.fetch_entity(membership_url)
            logging.warning("Processing membership")

            entries = data["result"]
            for entry in entries:

                # a membership have 3 important field, person_id, organization_id, posts_id
                if not (entry.get("person_id") and entry.get("organization_id")):
                    continue

                person = self.fetch_person(entry["person_id"])
                if not person:
                    continue
                role = entry.get("role","member")
                if not role:
                    role = "member"
                logging.warning("Role: %s" % role)

                params = []

                # This happens only once anyway
                kwparams = {}
                kwparams["popit_id"] = entry["id"]
                start_date = get_timestamp(entry.get("start_date"))
                if start_date:
                    kwparams["start_date"] = start_date
                end_date = get_timestamp(entry.get("end_date"))
                if end_date:
                    kwparams["end_date"] = end_date

                post_exist = False
                if entry.get("post_id"):
                    post = self.fetch_post(entry["post_id"])
                    if not post:
                        continue
                    if self.graph.match_one(person, role, post):
                        post_exist = True
                        logging.warning("Already exist, skipping")

                    if not post_exist:

                        relationship = Relationship(person, role, post, **kwparams)
                        self.graph.create(relationship)

                organization_exist = False

                if entry.get("organization_id"):
                    organization = self.fetch_organization(entry["organization_id"])
                    if not organization:
                        continue
                    if self.graph.match_one(person, role, organization):
                        logging.warning("Already exist, skipping")
                        organization_exist = True

                    if not organization_exist:

                        relationship = Relationship(person, role, organization, **kwparams)
                        self.graph.create(relationship)

            if data.get("next_url"):
                membership_url = data.get("next_url")
            else:
                break

    def fetch_person(self, person_id):
        if person_id in self.person_processed:
            logging.warning("Person %s fetch from cache" % person_id)
            return self.person_processed[person_id]

        node = self.graph.find_one("Persons", "popit_id", person_id)
        if node:
            logging.warning("Already exist, skipping")
            self.person_processed[person_id] = node
            return node

#.........这里部分代码省略.........
开发者ID:Sinar,项目名称:popit_relationship,代码行数:103,代码来源:popit_to_neo4j.py

示例14: authenticate

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import delete_all [as 别名]
import networkx as nx
from py2neo import authenticate, Node, Relationship, Graph
from py2neo.packages.httpstream.http import SocketError
from requests.exceptions import ConnectionError, HTTPError
from utils import get_results, handle_http_errors
from functools import partial

client = soundcloud.Client(client_id='454aeaee30d3533d6d8f448556b50f23')

id2username_cache = {}

# need to navigate and set the password to "pass" for first time
authenticate("localhost:7474", "neo4j", "cloudchaser")
userGraph = Graph()

userGraph.delete_all()

def getUserAttr(resource, attr):
#   if hasattr(resource, 'user'): return resource.user[attr]
    if hasattr(resource, attr): return getattr(resource, attr)
    return None

getUsername = partial(getUserAttr, attr='username')
getUserid = partial(getUserAttr, attr='id')

@handle_http_errors
def id2username(profile, kind='users'):
    global id2username_dict
    username = id2username_cache.get(profile, None)
    if username is not None: return username
开发者ID:brokoro,项目名称:cloudchaser,代码行数:32,代码来源:sc_api_calls.py

示例15: Graph

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import delete_all [as 别名]
__author__ = 'Marnee Dearman'
from py2neo import Graph, Node, Relationship
from settings import graphene

# What is the URL to my NEO4J
tuple_graph = Graph(graphene.DATABASE_URL)
print tuple_graph

# start over with delete so I can run the whole script at one time
tuple_graph.delete_all()

# Let's try modeling the group
# using Py2Neo.  This is the Python Meetup after all

# Example CYPHER
# CREATE (m:MEMBER {name:"Marnee"} )
# RETURN m
# Create a member aliased as "m" with name "Marnee"
# Return that member's node (m)

# Example PY2NEO
# one way is to setup a dictionary with the properties for the new Node, in this case MEMBER
# member_properties = {}
# member_properties["name"] = "Julian"
# show the code for py2neo
# member_node = Node.cast("MEMBER", member_properties)
# member_node = Node.cast("MEMBER", name="Julian", python_years=5)
# tuple_graph.create(member_node)

# Julian is lonely, let's give him a friend
开发者ID:MarneeDear,项目名称:presentations,代码行数:32,代码来源:demo.py


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