Exemple #1
0
    def generateKwargs(self):
        rep = self.representationWidget.value()
        alg = self.distAlgWidget.value()

        try:
            filters = int(self.filterEdit.text())
            if filters < 0:
                raise (ValueError)
        except ValueError:
            reply = QMessageBox.critical(
                self, "Invalid information",
                "The number of filters must be a number greater than 0.")
            return
        try:
            coeffs = int(self.coeffEdit.text())
            if coeffs <= 0:
                raise (ValueError)
            if int(self.coeffEdit.text()) > int(self.filterEdit.text()) - 1:
                raise (ValueError)

        except ValueError:
            if rep == 'mfcc':
                reply = QMessageBox.critical(
                    self, "Invalid information",
                    "The number of coefficients must be a number greater than 0 and less than the number of filters."
                )
                return
        try:
            freq_lims = (float(self.minFreqEdit.text()),
                         float(self.maxFreqEdit.text()))
            if freq_lims[0] < 0 or freq_lims[1] < 0:
                raise (ValueError(
                    "The minimum and maximum frequenies must be greater than 0."
                ))
            if freq_lims[0] >= freq_lims[1]:
                raise (ValueError(
                    "The maximum frequeny must be greater than the minimum frequency."
                ))
        except ValueError as e:
            reply = QMessageBox.critical(self, "Invalid information", str(e))
            return
        kwargs = {
            'type': self.compType,
            'rep': rep,
            'match_func': alg,
            'num_filters': filters,
            'freq_lims': freq_lims,
            'output_sim': self.outputSimWidget.isChecked(),
            'use_multi': self.settings['use_multi'],
            'num_cores': self.settings['num_cores'],
            'return_all': True
        }
        if rep == 'mfcc':
            kwargs['num_coeffs'] = coeffs
        if self.compType is None:
            reply = QMessageBox.critical(self, "Missing information",
                                         "Please specify a comparison type.")
            return
        elif self.compType == 'one':
            kwargs['query'] = self.oneDirectoryWidget.value()
        elif self.compType == 'two':
            dirOne = self.directoryOneWidget.value()
            if dirOne == '':
                reply = QMessageBox.critical(
                    self, "Missing information",
                    "Please specify the first directory.")
                return
            if not os.path.exists(dirOne):
                reply = QMessageBox.critical(
                    self, "Invalid information",
                    "The first directory does not exist.")
                return
            dirTwo = self.directoryTwoWidget.value()
            if dirTwo == '':
                reply = QMessageBox.critical(
                    self, "Missing information",
                    "Please specify the second directory.")
                return
            if not os.path.exists(dirTwo):
                reply = QMessageBox.critical(
                    self, "Invalid information",
                    "The second directory does not exist.")
                return

            kwargs['query'] = [dirOne, dirTwo]
        elif self.compType == 'file':
            path = self.fileWidget.value()
            if path == '':
                reply = QMessageBox.critical(
                    self, "Missing information",
                    "Please specify a path mapping file.")
                return
            if not os.path.exists(path):
                reply = QMessageBox.critical(
                    self, "Invalid information",
                    "The specified path mapping file does not exist.")
                return
            try:
                kwargs['query'] = load_path_mapping(path)
            except OSError as e:
                reply = QMessageBox.critical(self, "Invalid information",
                                             str(e))
                return
        return kwargs
Exemple #2
0
 def test_valid(self):
     return
     mapping = load_path_mapping(self.valid_path)
     for line in mapping:
         self.assertEqual(len(line), 2)
    def generateKwargs(self):
        rep = self.representationWidget.value()
        alg = self.distAlgWidget.value()

        try:
            filters = int(self.filterEdit.text())
            if filters < 0:
                raise(ValueError)
        except ValueError:
            reply = QMessageBox.critical(self,
                    "Invalid information", "The number of filters must be a number greater than 0.")
            return
        try:
            coeffs = int(self.coeffEdit.text())
            if coeffs < 0:
                raise(ValueError)
            if int(self.coeffEdit.text()) > int(self.filterEdit.text())-1:
                raise(ValueError)

        except ValueError:
            if rep == 'mfcc':
                reply = QMessageBox.critical(self,
                        "Invalid information", "The number of coefficients must be a number greater than 0 and less than the number of filters.")
                return
        try:
            freq_lims = (float(self.minFreqEdit.text()),float(self.maxFreqEdit.text()))
            if freq_lims[0] < 0 or freq_lims[1] < 0:
                raise(ValueError("The minimum and maximum frequenies must be greater than 0."))
            if freq_lims[0] >= freq_lims[1]:
                raise(ValueError("The maximum frequeny must be greater than the minimum frequency."))
        except ValueError as e:
                reply = QMessageBox.critical(self,
                        "Invalid information", str(e))
                return
        kwargs = {
                'type': self.compType,
                'rep':rep,
                'match_func':alg,
                'num_filters':filters,
                'freq_lims':freq_lims,
                'output_sim':self.outputSimWidget.isChecked(),
                'use_multi':self.settings['use_multi'],
                'num_cores':self.settings['num_cores'],
                'return_all':True}
        if rep == 'mfcc':
            kwargs['num_coeffs'] = coeffs
        if self.compType is None:
            reply = QMessageBox.critical(self,
                    "Missing information", "Please specify a comparison type.")
            return
        elif self.compType == 'one':
            kwargs['query'] = self.oneDirectoryWidget.value()
        elif self.compType == 'two':
            dirOne = self.directoryOneWidget.value()
            if dirOne == '':
                reply = QMessageBox.critical(self,
                        "Missing information", "Please specify the first directory.")
                return
            if not os.path.exists(dirOne):
                reply = QMessageBox.critical(self,
                        "Invalid information", "The first directory does not exist.")
                return
            dirTwo = self.directoryTwoWidget.value()
            if dirTwo == '':
                reply = QMessageBox.critical(self,
                        "Missing information", "Please specify the second directory.")
                return
            if not os.path.exists(dirTwo):
                reply = QMessageBox.critical(self,
                        "Invalid information", "The second directory does not exist.")
                return

            kwargs['query'] = [dirOne, dirTwo]
        elif self.compType == 'file':
            path = self.fileWidget.value()
            if path == '':
                reply = QMessageBox.critical(self,
                        "Missing information", "Please specify a path mapping file.")
                return
            if not os.path.exists(path):
                reply = QMessageBox.critical(self,
                        "Invalid information", "The specified path mapping file does not exist.")
                return
            try:
                kwargs['query'] = load_path_mapping(path)
            except OSError as e:
                reply = QMessageBox.critical(self,
                        "Invalid information", str(e))
                return
        return kwargs
 def test_valid(self):
     return
     mapping = load_path_mapping(self.valid_path)
     for line in mapping:
         self.assertEqual(len(line),2)