<commit_before>
''' NeoDB class for WorkBench '''

class NeoDB():

    def __init__(self, uri='http://localhost:7474/db/data'):

        # Get connection to Neo4j
        try:
            # Open the Neo4j DB and get version (just testing Neo connection)
            self.graph_db = neo4j.GraphDatabaseService(uri)
            version = self.graph_db.neo4j_version
            print 'Neo4j GraphDB connected: %s %s' % (str(uri), version)
        except packages.httpstream.http.SocketError:
            print 'Neo4j connection failed! Is your Neo4j server running? $ neo4j start'
            raise RuntimeError('Could not connect to Neo4j')

    def add_node(self, node_id, name, labels):
        ''' Add the node with name and labels '''
        node = self.graph_db.get_or_create_indexed_node('Node', 'node_id', node_id, {'node_id':node_id, 'name':name})
        node.add_labels(*labels)

    def has_node(self, node_id):
        ''' Add the node with name and labels '''
        return True if self.graph_db.get_indexed_node('Node', 'node_id', node_id) else False

    def add_rel(self, source_node_id, target_node_id, rel):
        ''' Add a relationship: source, target must already exist (see add_node)<commit_msg>trying to catch exception from older NeoDB versions<commit_after>
''' NeoDB class for WorkBench '''

class NeoDB():

    def __init__(self, uri='http://localhost:7474/db/data'):

        # Get connection to Neo4j
        try:
            # Open the Neo4j DB and get version (just testing Neo connection)
            self.graph_db = neo4j.GraphDatabaseService(uri)
            version = self.graph_db.neo4j_version
            print 'Neo4j GraphDB connected: %s %s' % (str(uri), version)
        except packages.httpstream.http.SocketError:
            print 'Neo4j connection failed! Is your Neo4j server running? $ neo4j start'
            raise RuntimeError('Could not connect to Neo4j')

    def add_node(self, node_id, name, labels):
        ''' Add the node with name and labels '''
        node = self.graph_db.get_or_create_indexed_node('Node', 'node_id', node_id, {'node_id':node_id, 'name':name})
        try:
            node.add_labels(*labels)
        except NotImplementedError:
            print 'Got a NotImplementedError when adding labels. Upgrade your Neo4j DB!'

    def has_node(self, node_id):
        ''' Add the node with name and labels '''
        return True if self.graph_db.get_indexed_node('Node', 'node_id', node_id) else False

    def add_rel(self, source_node_id, target_node_id, rel):
        ''' Add a relationship: source, target must already exist (see add_node)
{'fraction_non_alphanumeric': 0.10313216195569137, 'fraction_numerical': 0.010313216195569137, 'mean_word_length': 2.9502262443438916, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '868104', 'n_tokens_mistral': 813, 'n_tokens_neox': 776, 'n_words': 238}