예제 #1
0
    def insert_bulk_edge(self, project, type, list_of_edges):
        retVal = self.__get_edge_parameters(project, type)[0][0]

        source_label = retVal['source_label']
        target_label = retVal['target_label']
        is_doubled = retVal['isdoubled']

        retVal = []
        try:
            i = 0
            while i < len(list_of_edges):
                result = self.__insert_bulk_edge(source_label, target_label,
                                                 type, is_doubled,
                                                 list_of_edges[i:i + 10000])[0]
                for res in result:
                    retVal.append(res['id'])
                i += 10000
                print(i)

            return retVal
        except IndexError as ie:
            raise interface_errors.GraphSyntaxError(str(ie))
        except GraphError as ge:
            raise interface_errors.GraphInterfaceException(
                "Unexpected error. The exception is {0}".format(str(ge)))
예제 #2
0
    def insert_single_edge(self, project, type, edge):
        try:
            retVal = self.__get_edge_parameters(project, type)[0][0]
            source_label = retVal['source_label']
            target_label = retVal['target_label']
            is_doubled = retVal['isdoubled']
        except IndexError:
            raise interface_errors.GraphNonExistElementError(
                'It is strange, the validator does not work')

        source_id = edge.pop('source_id')
        target_id = edge.pop('target_id')
        attributes = self.converter(dict_=edge,
                                    prefix_='',
                                    connector_=':',
                                    join_element_=', ',
                                    parenthesis_=['{', '}'])

        try:
            return self.__insert_edge(source_id, source_label, target_id,
                                      target_label, type, attributes,
                                      is_doubled)[0][0]['id']
        except GraphError as ge:
            raise interface_errors.GraphInterfaceException(
                'Unexpected exception occurred. The exception: {}'.format(
                    str(ge)))
예제 #3
0
    def insert_single_node(self, project, type, node):
        try:
            onto_parents = self.__get_ontology_parents(
                project, type)[0][0]['collection']
            onto_parents.append(type)
        except IndexError:
            onto_parents = [
                type,
            ]

        labels = ":".join(onto_parents)
        attributes = self.converter(dict_=node,
                                    prefix_='',
                                    connector_=':',
                                    join_element_=', ',
                                    parenthesis_=['{', '}'])

        try:
            retVal = int(
                self.__insert_node(label_=labels,
                                   attributes_=attributes)[0][0]['id'])
        except (GraphError, IndexError) as gie:
            raise interface_errors.GraphInterfaceException(
                'Unexpected Error: {}'.format(str(gie)))

        return retVal
예제 #4
0
 def delete_single_node(self, id):
     try:
         return self.__delete_node(id)[0][0]['id']
     except GraphError as ge:
         raise interface_errors.GraphInterfaceException(str(ge))
     except IndexError as ie:
         raise interface_errors.GraphNonExistElementError(
             'Node does not exist')
예제 #5
0
 def delete_single_edge_non_typed(self, source_id, target_id):
     try:
         return self.__delete_single_edge(source_id, target_id,
                                          None)[0][0]['collection']
     except GraphError as ge:
         raise interface_errors.GraphInterfaceException(
             'Unexpected error: {0}'.format(str(ge)))
     except IndexError:
         raise interface_errors.GraphNonExistElementError(
             'The given edge does not exist')
예제 #6
0
    def get_single_edge_typed(self, source_id, target_id, type):
        try:
            return self.__get_single_edge(source_id, target_id,
                                          type)[0][0]['edge'].properties

        except GraphError:
            raise interface_errors.GraphInterfaceException('Unexpected error')
        except IndexError:
            raise interface_errors.GraphNonExistElementError(
                'The given edge does not exist')
예제 #7
0
    def get_single_edge_non_typed(self, source_id, target_id):
        try:
            result = self.__get_single_edge(source_id, target_id, None)[0]
            retVal = []
            for res in result:
                retVal.append(res['node'].properties)

            return retVal
        except GraphError:
            raise interface_errors.GraphInterfaceException('Unexpected error')
        except IndexError:
            raise interface_errors.GraphNonExistElementError(
                'The given edge does not exist')
예제 #8
0
    def get_bulk_node(self, type, list_of_node_ids):
        retVal = []
        try:
            result = self.__get_bulk_node(type, list_of_node_ids)[0]

            for res in result:
                retVal.append(res['node'].properties)
            return retVal
        except GraphError as ge:
            raise interface_errors.GraphInterfaceException(
                "Unexpected error. The exception is {0}".format(str(ge)))
        except IndexError:
            raise interface_errors.GraphNonExistElementError(
                'The requested graph nodes do not exist')
예제 #9
0
    def delete_bulk_node(self, type, list_of_ids):
        retVal = []
        try:
            result = self.__delete_bulk_node(type, list_of_ids)[0]

            for res in result:
                retVal.append(res['id'])
            return retVal
        except GraphError as ge:
            raise interface_errors.GraphInterfaceException(
                "Unexpected error. The exception is {0}".format(str(ge)))
            #It is always raised when a node has, at least, one edge

        except IndexError:
            raise interface_errors.GraphNonExistElementError(
                'The requested graph nodes do not exist')
예제 #10
0
    def insert_bulk_node(self, project, type, nodes):
        try:
            onto_parents = self.__get_ontology_parents(
                project, type)[0][0]['collection']
            onto_parents.append(type)
        except IndexError:
            onto_parents = [
                type,
            ]

        labels = ":".join(onto_parents)
        list_of_attributes = []

        for node in nodes:
            list_of_attributes.append(
                self.converter(dict_=node,
                               prefix_='',
                               connector_=':',
                               join_element_=', ',
                               parenthesis_=['{', '}']))
        try:
            i = 0
            retVal = []

            while i < len(list_of_attributes):
                result = self.__insert_bulk_node(
                    labels, list_of_attributes[i:i + 10000])
                for res in result[0]:
                    retVal.append(int(res['id']))
                i += 10000
                print(i)

            return retVal
        except GraphError as ge:
            raise interface_errors.GraphInterfaceException(
                'Unexpected error! The exception is {0}'.format(str(ge)))
예제 #11
0
 def delete_meta_node(self, *args, **kwargs):
     raise interface_errors.GraphInterfaceException(
         'Non-implemented functionality')
예제 #12
0
 def insert_bulk_edge(self, *args, **kwargs):
     raise interface_errors.GraphInterfaceException(
         'Non-implemented functionality')
예제 #13
0
 def delete_single_edge_non_typed(self, *args, **kwargs):
     raise interface_errors.GraphInterfaceException(
         'Non-implemented functionality')
예제 #14
0
 def get_single_node(self, *args, **kwargs):
     raise interface_errors.GraphInterfaceException(
         'Non-implemented functionality')