def test_search(self):
        search_query = "telev"
        response = client.get(f"/api/products/search?query={search_query}")

        products = json.loads(response.text)

        for product in products:
            assert contains(product.get("brand"), search_query) or contains(
                product.get("description"), search_query)
Exemple #2
0
def test_contains():
    #begin, end, node
    assert contains(100, 300, 200)
    assert not contains(100, 300, 100)
    assert not contains(100, 300, 400)
    assert not contains(100, 300, 0)
    assert not contains(100, 300, 900)

    assert contains(800, 300, 900)
    assert contains(800, 300, 200)
    assert not contains(800, 300, 700)
    assert not contains(800, 300, 400)
Exemple #3
0
    def extract_spo_sentence(self, sent):
        """ Extract SPO triples from a sentence
		:type sent: string
		:rtype: list
		"""
        res = []
        for trig in utils.TRIGGERS:
            index = utils.contains(sent, trig)
            if index > 0:
                # print(trig,'==> ',sent)
                # print('trigger word:',sent[index:index+len(trig)])
                trig_str = sent[index:index + len(trig)].strip()
                label_list, term_list, cause_index = self.reform_dependency_patterns(
                    sent, trig_str)
                # print(label_list)
                # deliver label_list to trie tree to search;
                for i in range(0, cause_index[0] - 1):
                    ans = self.trieTree.search(label_list[i:])
                    if ans:
                        # print(ans)
                        sub = ' '.join([term_list[i + j] for j in ans[0]])
                        cause_label = term_list[i + ans[1]]
                        for objx in ans[2:]:
                            obj = ' '.join([term_list[i + j] for j in objx])
                            # add to res
                            res.append([sub, cause_label, obj])
                        # gready stop, avoid shorter subject
                        break
                # avoid repeat detection, e.g. cause of and cause
                break
        return res
Exemple #4
0
    def node_join(self, args):
        """Process JOIN_REQ message.

        Parameters:
            args (dict): addr and id of the node trying to join
        """

        self.logger.debug("Node join: %s", args)
        addr = args["addr"]
        identification = args["id"]
        if self.identification == self.successor_id:  # I'm the only node in the DHT
            self.successor_id = identification
            self.successor_addr = addr
            #TODO update finger table
            args = {
                "successor_id": self.identification,
                "successor_addr": self.addr
            }
            self.send(addr, {"method": "JOIN_REP", "args": args})
        elif contains(self.identification, self.successor_id, identification):
            args = {
                "successor_id": self.successor_id,
                "successor_addr": self.successor_addr,
            }
            self.successor_id = identification
            self.successor_addr = addr
            #TODO update finger table
            self.send(addr, {"method": "JOIN_REP", "args": args})
        else:
            self.logger.debug("Find Successor(%d)", args["id"])
            self.send(self.successor_addr, {
                "method": "JOIN_REQ",
                "args": args
            })
        self.logger.info(self)
Exemple #5
0
def process_tail(tile_dir, selection, remove_trash=False):
    """
    Crops images in tile_dir folder.
    :param tile_dir: str
        path to directory
    :param selection: array
        contains coordinates for cropping
    :param remove_trash: Bool
    """
    # selection = transform_coordinates(coordinates_from_geojson(geojson))
    does_not_contain = True
    for image_name in os.listdir(tile_dir):
        image_path = os.path.join(tile_dir, image_name)
        if contains(get_corner_coordinates(image_path),
                    selection) is True:
            does_not_contain = False
            output_file_name = 'c' + os.path.splitext(image_name)[0] + '.tiff'
            # print('\t' + output_file_name)
            crop(selection, image_path,
                 os.path.join(tile_dir, output_file_name))
        else:
            print('\t' + 'does not contain your selection')
            logging.info(tile_dir + ' does not contain selection')
        if remove_trash is True:
            logging.info('removing ' + image_path)
            os.remove(image_path)

    if does_not_contain and remove_trash:
        logging.info('removing ' + tile_dir)
        shutil.rmtree(tile_dir)
Exemple #6
0
def submit(ctx, challenge_key, submission_key):
    challenge = get_challenge(ctx, challenge_key)
    if challenge:
        if challenge['state'] == 'OPEN':
            submissions = challenge['submissions']
            if contains(submissions, submission_key):
                Log("Submission already exists.")
                return False
            elif len(submissions) < 100:
                Log("Adding new submission.")
                submissions.append(submission_key)
                challenge['submissions'] = submissions
                set_challenge(ctx, challenge_key, challenge)
                return True
            elif GetTime() > challenge['timestamp'] + 1209600:
                Log("This challenge has expired.")
                challenge['state'] = 'CLOSED'
                set_challenge(ctx, challenge_key, challenge)
                return False
            else:
                Log("The maximum number of submissions for this challenge has been reached."
                    )
                challenge['state'] = 'CLOSED'
                set_challenge(ctx, challenge_key, challenge)
                return False
        else:
            return False
    Log("This challenge does not exist.")
    return False
Exemple #7
0
def approver_fund_claim(ctx, voter, challenger, owner, challenge_id):
    submission_key = generate_submission_key(challenger, owner, challenge_id)
    Log("Generating submission key.")
    submission = get_submission(ctx, submission_key)
    if submission:
        if GetTime() >= submission['timestamp'] + 87000:
            Log("Submission is closed.")
            approvers = submission['approvers']
            approver = contains(approvers, voter)
            if approver:
                Log("Voter approved the submission.")
                if submission['status'] == 'APPROVED':
                    Log("Submission was approved. Voter is eligible for claim."
                        )
                    approvers.remove(approver[voter])
                    submission['approvers'] = approvers
                    set_submission(ctx, submission_key, submission)
                    Log("Voter has been removed from the approver list. Claim can proceed."
                        )
                    return submission['approver_count']
                else:
                    Log("Submission was not approved.")
                    return False
            else:
                Log("Voter is not in the approver list.")
                return False
        else:
            Log("Submission is still open.")
            return False
    else:
        Log("This submission does not exist.")
        return False
 def get_result(self):
     rects = self.get_rects()
     for rect in rects:
         x, y, w, h = rect
         img = self.get_bg_image()[y:y + 2, x:x + 2, :]
         color_name = utils.analyze_image_color(img)
         if color_name == self._semantic.color:
             rect_chars = []
             for char in self.get_chars():
                 if self.get_semantic().in_out == "内":
                     if utils.contains(rect, char.bbox):
                         rect_chars.append(char)
                 else:
                     if utils.contains(rect, char.bbox) == False:
                         rect_chars.append(char)
             return self.get_codes(rect_chars)
     return self.get_codes(self.get_chars())
 def filter_duplicate_notifications(self, notifications):
     filtered_notifications = list()
     for notification in notifications:
         if not utils.contains(
                 filtered_notifications, lambda x: x.miner_name ==
                 notification.miner_name and x.source == notification.source
                 and x.message == notification.message):
             filtered_notifications.append(notification)
     return filtered_notifications
Exemple #10
0
 def is_valid_position(self, current_piece, offset_x = 0, offset_y = 0):
     """
     Checks if the piece is in a valid position within the board      
     """
     for x in range(pieces.Piece.TEMPLATE_WIDTH):
         pos_x = current_piece.get_pos_x() + x + offset_x
         for y in range(pieces.Piece.TEMPLATE_HEIGHT):
             pos_y = current_piece.get_pos_y() + y + offset_y
             if current_piece.get_template()[y][x]:
                 if not utils.contains(0, 0, game_config.BOARD_BOX_COUNT_X, game_config.BOARD_BOX_COUNT_Y, pos_x, pos_y, 1, 1):
                     return False
                 if self.board.get_cell(pos_x, pos_y):
                     return False
     return True 
Exemple #11
0
    def notify(self, args):
        """Process NOTIFY message.
            Updates predecessor pointers.

        Parameters:
            args (dict): id and addr of the predecessor node
        """

        self.logger.debug("Notify: %s", args)
        if self.predecessor_id is None or contains(self.predecessor_id,
                                                   self.identification,
                                                   args["predecessor_id"]):
            self.predecessor_id = args["predecessor_id"]
            self.predecessor_addr = args["predecessor_addr"]
        self.logger.info(self)
Exemple #12
0
    def _complex(self, sentence):
        """
        Check if the construction contains X, Y or Z
        :param sentence: string
        :return: an array of clauses which contains X, Y or Z
        """
        segments = list()

        if utils.contains(["X", "Y", "Z"], self.construction):
            clauses = re.split(r'\W+', sentence)

            for clause in clauses:
                if utils.includes(clause, self._constants):
                    segments.append(clause)

        return segments
Exemple #13
0
 def handle_option(o,args):
     # option arguments must be ignored, but here only a basic option parsing is done just by looking
     # for option markers.
     if options.cli_parser().has_option(o): # WORKARROUND: ignore option arguments, if they look like options
         #log.info("    opt: "+o)
         if o != '-V' and not o.startswith('--variant-') and not targetopts.has_option(o):
             index=contains(o,'=')
             if index>=0:
                 k=o[:index]
             else:
                 k=o
             #log.info("found unsupported option "+k)
             nargs=curopts.get_option(k).nargs
             log.warning("given option '"+k+"' with "+str(nargs)+" arg(s) is not supported by selected xmake version -> option omitted")
             if k!=o:
                 nargs=0
             args=remove_arg(o,nargs,args)
     return args
Exemple #14
0
def submit(ctx, challenge_key, submission_key):
    challenge = get_challenge(ctx, challenge_key)
    if challenge:
        Log("Challenge exists.")
        if challenge['state'] == 'OPEN':
            Log("Challenge is open")
            submissions = challenge['submissions']
            if contains(submissions, submission_key):
                Log("Submission already exists.")
                return False
            else:
                Log("Adding new submission.")
                submissions.append(submission_key)
                challenge['submissions'] = submissions
                set_challenge(ctx, challenge_key, challenge)
                return True
        else:
            Log("Challenge is closed")
            return False
    Log("This challenge does not exist.")
    return False
Exemple #15
0
    def stabilize(self, from_id, addr):
        """Process STABILIZE protocol.
            Updates all successor pointers.

        Parameters:
            from_id: id of the predecessor of node with address addr
            addr: address of the node sending stabilize message
        """

        self.logger.debug("Stabilize: %s %s", from_id, addr)
        if from_id is not None and contains(
            self.identification, self.successor_id, from_id
        ):
            # Update our successor
            self.successor_id = from_id
            self.successor_addr = addr
            #TODO update finger table

        # notify successor of our existence, so it can update its predecessor record
        args = {"predecessor_id": self.identification, "predecessor_addr": self.addr}
        self.send(self.successor_addr, {"method": "NOTIFY", "args": args})
Exemple #16
0
    def _policy(self, index, sentence):
        """
        Create policy based on pos of word
        :param index: string - the mark of the sentence
        :param sentence: string
        :return: dict - update the policy of the feature
        """
        feature = self.features[index]
        words, tags = self._posseg(sentence)
        score, count = 0, 0
        segments = self._complex(sentence)

        for word, tag in zip(words, tags):
            if len(segments) > 0 and utils.contains(["X", "Y", "Z"], self.construction):
                step = self._judge(segments, word, sentence, count)
            else:
                step = self._observe(word, tag, count, sentence, feature[str(count)])

            score += self.conf.policies[step]
            # update the feature
            feature[str(count)]["tag"] = step
            feature[str(count)]["policy"] = score
            if score < 0 and feature[str(count)]["regex"] == 1.5:
                feature[str(count)]["regex"] = 0.5

            shared = self.agree()

            if word in shared:
                feature[str(count)]["agree"] = 1

            if step == "variable" and len(shared) > 0:
                if "X" or "Y" or "Z" in shared:
                    feature[str(count)]["agree"] = 1
                elif tag in shared:
                    feature[str(count)]["agree"] = 1

            count += 1

        return feature
Exemple #17
0
    def new_wormhole(self, cells, obstacles, cells_op=[]):
        corners = [[1, 1], [1, self.height - 2], [self.width - 2, 1],
                   [self.width - 2, self.height - 2]]
        forbiddens = []
        forbiddens.extend(cells)
        forbiddens.extend(obstacles)
        forbiddens.extend(cells_op)

        new_wormhole = [1, 1]
        if contains(forbiddens, corners):
            while new_wormhole in forbiddens:
                new_wormhole = [
                    randint(1, self.width - 2),
                    randint(1, self.height - 2)
                ]
            self.wormhole = new_wormhole
            return new_wormhole
        else:
            while new_wormhole in forbiddens:
                new_wormhole = random.choice(corners)
            self.wormhole = new_wormhole
            return new_wormhole
Exemple #18
0
def reject(ctx, voter, challenger, owner, challenge_id):
    submission_key = generate_submission_key(challenger, owner, challenge_id)
    Log("Generating submission key.")
    submission = get_submission(ctx, submission_key)
    if submission:
        if GetTime() < submission['timestamp'] + 87000:
            voters = submission['voters']
            voted = contains(voters, voter)
            Log("Checking that the user has not already voted for this submission."
                )
            Log(voted)
            if voted == False:
                Log("Rejecting submission.")
                rejecters = submission['rejecters']
                voters.append(voter)
                rejecters.append(voter)
                submission['voters'] = voters
                submission['rejecters'] = rejecters
                submission['rejecter_count'] = len(submission['rejecters'])
                submission['difference'] = submission[
                    'approver_count'] - submission['rejecter_count']
                if submission['difference'] >= 0:
                    submission['status'] = 'APPROVED'
                elif submission['difference'] < 0:
                    submission['status'] = 'REJECTED'
                set_submission(ctx, submission_key, submission)
                return True
            else:
                Log("The user already voted.")
                return False
        else:
            Log("This submission has expired.")
            submission['state'] = 'CLOSED'
            set_submission(ctx, submission_key, submission)
            return False
    else:
        Log("This submission does not exist.")
        return False
Exemple #19
0
 def restrict_tag_and(self, tags):
     self.contacts = [
         contact for contact in self.contacts
         if contains(contact.tags, tags)
     ]
Exemple #20
0
def update_presence():
    """
    Update presence in Discord
    """

    if rpc_obj is None or not rpc_obj.connected:
        # If we're flagged as disconnected, skip all this processing and save some CPU cycles.
        return
    global ignored_file_types
    global ignored_directories
    if (ignored_file_types == -1):
        # Lazy init
        if (vim.eval("exists('{}')".format("g:vimsence_ignored_file_types")) ==
                "1"):
            ignored_file_types = vim.eval("g:vimsence_ignored_file_types")
        else:
            ignored_file_types = []
        if (vim.eval("exists('{}')".format("g:vimsence_ignored_directories"))
                == "1"):
            ignored_directories = vim.eval("g:vimsence_ignored_directories")
        else:
            ignored_directories = []

    activity = base_activity

    large_image = ""
    large_text = ""
    details = ""
    state = ""

    filename = get_filename()
    directory = get_directory()
    filetype = get_filetype()

    editing_text = 'Editing a {} file'
    if (vim.eval(
            "exists('{}')".format("g:vimsence_editing_large_text")) == "1"):
        editing_text = vim.eval("g:vimsence_editing_large_text")

    editing_state = 'Workspace: {}'
    if (vim.eval("exists('{}')".format("g:vimsence_editing_state")) == "1"):
        editing_state = vim.eval("g:vimsence_editing_state")
    state = editing_state.format(directory)

    editing_details = 'Editing {}'
    if (vim.eval("exists('{}')".format("g:vimsence_editing_details")) == "1"):
        editing_details = vim.eval("g:vimsence_editing_details")
    details = editing_details.format(filename)

    if (u.contains(ignored_file_types, filetype)
            or u.contains(ignored_directories, directory)):
        # Priority #1: if the file type or folder is ignored, use the default activity to avoid exposing
        # the folder or file.
        rpc_obj.set_activity(base_activity)
        return
    elif filetype and (filetype in has_thumbnail or filetype in remap):
        # Check for files with thumbnail support
        large_text = editing_text.format(filetype)
        if (filetype in remap):
            filetype = remap[filetype]

        large_image = filetype
    elif filetype in file_explorers or u.contains_fuzzy(
            file_explorer_names, filename):
        # Special case: file explorers. These have a separate icon and description.
        large_image = 'file-explorer'

        large_text = 'In the file explorer'
        if (vim.eval("exists('{}')".format("g:vimsence_file_explorer_text")) ==
                "1"):
            large_text = vim.eval("g:vimsence_file_explorer_text")

        details = 'Searching for files'
        if (vim.eval("exists('{}')".format("g:vimsence_file_explorer_details"))
                == "1"):
            details = vim.eval("g:vimsence_file_explorer_details")
    elif (is_writeable() and filename):
        # if none of the other match, check if the buffer is writeable. If it is,
        # assume it's a file and continue.
        large_image = 'none'

        large_text = editing_text.format(
            filetype if filetype else
            "Unknown" if not get_extension() else get_extension())
    else:
        large_image = 'none'
        large_text = 'Nothing'
        details = 'Nothing'

    # Update the activity
    activity['assets']['large_image'] = large_image
    activity['assets']['large_text'] = large_text
    activity['details'] = details
    activity['state'] = state

    try:
        rpc_obj.set_activity(activity)
    except BrokenPipeError:
        # Connection to Discord is lost
        pass
    except NameError:
        # Discord is not running
        pass
    except OSError:
        # IO-related issues (possibly disconnected)
        pass
Exemple #21
0
    q_out = Queue.Queue()
    p = audiobackend.Play(channels=1, queue=q_out)
    x = utils.rand_gen(10240)
    Fcarr = 2000
    Fsampl = 8000
    K = 6
    signal = modulate(x, Fcarr, Fsampl, K)
    y = demodulate(signal, Fcarr, Fsampl, K)
    x = x.tolist()

    # print len(x)
    # print len(y)
    # print x
    # print y

    if bool(utils.contains(x[0:196], y)) == False:
    # if bool(utils.contains(x, y)) == False:
        print "data error"
    else:
        print "data ok"

    s = utils.conv_to_audio(signal)

    p.start()

    for x in utils.chunk(s,size):
        q_out.put(x)
        p.samples_ready()
    p.done()
    p.join()
Exemple #22
0
def test_source(d, s, time_err, pos_err):
    """
    @param
    s: source (type: Source)
    d: data from trajectory file (type: dic)
    time_err: time threshold (type: float)
    time_pos: space threshold (type: float)
    @return:
    False if someting went wrong. Otherwise, return True
    """
    logging.info("testing source ids: %s", ", ".join(map(str, s.ids)))
    debug_msg = ("source properties: \n\t\t\t\t time_min=" + str(s.time_min) +
                 " time_max=" + str(s.time_max) + "\n"
                 "\t\t\t\t xmin=" + str(s.xmin) + " xmax=" + str(s.xmax) + "\n"
                 "\t\t\t\t ymin=" + str(s.ymin) + " ymax=" + str(s.ymax) + "\n"
                 "\t\t\t\t startX=" + str(s.startX) + " startY=" +
                 str(s.startY) + "\n"
                 "\t\t\t\t frequency=" + str(s.frequency) + "\n"
                 "\t\t\t\t percent=" + str(s.percent) + "\n"
                 "\t\t\t\t rate=" + str(s.rate) + "\n"
                 "\t\t\t\t n_create=" + str(s.N_create) + "\n"
                 "\t\t\t\t agents_max=" + str(s.agents_max) + "\n"
                 "\t\t\t\t time=" + str(s.time))
    logging.info(debug_msg)
    times = []
    # TODO
    # if s.N_create:
    #     correct_length = s.N_create == len(s.ids)
    #     if no correct_length:
    #         logging.error("expected "+ str(s.N_create)
    #                       ", but got "+str(len(s.ids))
    #                       )
    #         return False

    for j, source_id in enumerate(s.ids):
        in_time_interval = True
        in_box_x = True
        in_box_y = True
        on_time = True
        if not source_id in d.keys():
            logging.error("source_id: %d is not in data", source_id)
            msg = ("Data keys : " + ", ".join(map(str, sorted(d.keys()))))
            logging.error(msg)
            return False

        if s.time:
            on_time = equals(d[source_id][0], s.time, err=time_err)

        if s.time_min and s.time_max:
            in_time_interval = contains(d[source_id][0], s.time_min,
                                        s.time_max, time_err)

        if s.xmin and s.xmax:
            in_box_x = contains(d[source_id][1], s.xmin, s.xmax, pos_err)

        if s.ymin and s.ymax:
            in_box_y = contains(d[source_id][2], s.ymin, s.ymax, pos_err)

        # frequency
        if s.frequency:
            times.append(d[source_id][0])

        if not in_time_interval or \
        not in_box_x or \
        not in_box_y or \
        not on_time:
            err_msg = ("source id " + str(source_id) + " "
                       "creation time at " + str(d[source_id][0]) +
                       " in position (" + str(d[source_id][1]) + ", " +
                       str(d[source_id][2]) + ")")

            logging.error(err_msg)
            return False

    if not times:
        return True

    msg = ("Got times : " + ", ".join(map(str, times)))

    logging.info(msg)
    should_be = s.cycle()
    # test ids
    if len(s.ids) != len(should_be):
        logging.error("length of ids is not correct")
        msg = ("ids : " + ", ".join(map(str, s.ids)))
        logging.error(msg)
        msg = ("should be : " + ", ".join(map(str, should_be)))
        logging.error(msg)
        return False
    else:
        logging.info("length of ids is fine")
    if not np.all(np.less_equal(np.abs(times - should_be), time_err)):
        err_msg = ("frequency mismatch!\n"
                   "Should be: " + ", ".join(map(str, should_be)))
        logging.error(err_msg)
        return False

    return True
Exemple #23
0
    def test_contains(self, container, string, expected):

        result = contains(container, string)

        assert result == expected
Exemple #24
0
        if get_date(feed.entries[-1]) < date:
            break

        max_results += 100

    feed.entries = entries_on(feed.entries, date)

    print('Found %d papers.' % len(feed.entries))

    # Run through each entry, and filter for keywords
    for entry in feed.entries:
        abstract, title = entry.summary, entry.title

        matches = set(
            contains(title, keywords, flaglist) +
            contains(abstract, keywords, flaglist))
        if len(matches) == 0:
            continue

        authors = ', '.join(author.name for author in entry.authors)

        with open(output_file, 'a') as f:
            f.write('## %s \n\n' % clean_whitespaces(title))
            f.write('%s \n\n' % authors)
            f.write('###' +
                    write_in_color('Keywords: ' + ', '.join(matches), 'gray') +
                    '\n\n')
            f.write(abstract + '\n\n')

        # get the links to the abs page and pdf for this e-print
Exemple #25
0
    q_out = Queue.Queue()
    p = audiobackend.Play(channels=1, queue=q_out)
    x = utils.rand_gen(10240)
    Fcarr = 2000
    Fsampl = 8000
    K = 6
    signal = modulate(x, Fcarr, Fsampl, K)
    y = demodulate(signal, Fcarr, Fsampl, K)
    x = x.tolist()

    # print len(x)
    # print len(y)
    # print x
    # print y

    if bool(utils.contains(x[0:196], y)) == False:
        # if bool(utils.contains(x, y)) == False:
        print "data error"
    else:
        print "data ok"

    s = utils.conv_to_audio(signal)

    p.start()

    for x in utils.chunk(s, size):
        q_out.put(x)
        p.samples_ready()
    p.done()
    p.join()
Exemple #26
0
def split_val_v2(val_path: str,
                 split_percentage_per_class: float,
                 _set: str = 'clean',
                 _max=None):
    """
    Takes the given percentage of images from each class und pastes them into the validation directory.
    If a class contains only one sample, the samples is only copied and will be inside train and validation set.
    """
    dirs = glob(os.path.join(MAIN_DATASET_PATH,
                             '*')) if _set == 'clean' else glob(
                                 os.path.join(NOISY_DATA_SETS[0], '*'))
    for _dir in dirs:
        files = glob(os.path.join(_dir, '*'))
        jpgs = [el for el in files if el.endswith(".jpg")]
        jpgs = utils.filter_for_filenames(IGNORE_LIST, jpgs)

        xmls = [el for el in files if el.endswith(".xml")]
        xmls = utils.filter_for_filenames(IGNORE_LIST, xmls)

        jpgs = sorted(
            jpgs,
            key=lambda el: int(
                os.path.basename(el)[:os.path.basename(el).rindex('.')]))
        xmls = sorted(
            xmls,
            key=lambda el: int(
                os.path.basename(el)[:os.path.basename(el).rindex('.')]))

        sample_label = list(zip(jpgs, xmls))
        if not utils.validate_tuple(sample_label):
            raise utils.ValidationError(
                "Not all elements have a label/description.")
        valid_count = int(split_percentage_per_class * len(sample_label))

        if _max is not None:
            valid_count = _max if valid_count > _max else valid_count

        if valid_count:
            while valid_count > 0:
                try:
                    to_move = random.choice(sample_label)
                except IndexError:
                    break

                classid = os.path.basename(os.path.dirname(to_move[0]))
                if utils.contains(os.path.dirname(to_move[0]), 2, IGNORE_LIST):
                    parent = os.path.join(val_path, classid)
                    os.makedirs(parent, exist_ok=True)
                    shutil.move(
                        to_move[0],
                        os.path.join(parent, os.path.basename(to_move[0])))
                    shutil.move(
                        to_move[1],
                        os.path.join(parent, os.path.basename(to_move[1])))
                    sample_label.remove(to_move)
                    valid_count -= 1
        else:
            if len(sample_label) > 1:
                try:
                    to_move = random.choice(sample_label)
                except IndexError:
                    break

                classid = os.path.basename(os.path.dirname(to_move[0]))
                parent = os.path.join(val_path, classid)
                os.makedirs(parent)
                shutil.move(to_move[0],
                            os.path.join(parent, os.path.basename(to_move[0])))
                shutil.move(to_move[1],
                            os.path.join(parent, os.path.basename(to_move[1])))
            else:
                to_move = sample_label[0]
                classid = os.path.basename(os.path.dirname(to_move[0]))
                parent = os.path.join(val_path, classid)
                os.makedirs(parent)
                shutil.copy(to_move[0],
                            os.path.join(parent, os.path.basename(to_move[0])))
                shutil.copy(to_move[1],
                            os.path.join(parent, os.path.basename(to_move[1])))