Exemplo n.º 1
0
    def testGetParametersDict(self):
        taskInfo = TaskInfo("param1=1;param2=2", "", "")
        paramDict = taskInfo.getParametersDict()

        self.assertTrue('param1' in paramDict)
        self.assertTrue('param2' in paramDict)

        taskInfo = TaskInfo("", "", "")
        paramDict = taskInfo.getParametersDict()
        self.assertEqual(0, len(paramDict))

        taskInfo = TaskInfo("param1", "", "")

        with self.assertRaises(Exception):
            taskInfo.getParametersDict()
Exemplo n.º 2
0
    def testGatherInputData(self):
        #No data olist
        task1 = Task(
            TaskInfo("", TestTask.workingDirectory, TestTask.targetFolderErr1))

        with self.assertRaises(Exception):
            task1.gatherInputData()

        #No map .omap
        task1 = Task(
            TaskInfo("", TestTask.workingDirectory, TestTask.targetFolderErr2))

        with self.assertRaises(Exception):
            task1.gatherInputData()

        task1 = Task(
            TaskInfo("", TestTask.workingDirectory, TestTask.targetFolder1))

        task1.gatherInputData()

        self.assertTrue(MyFile.checkFileExists(task1.getTaskDirectory()))
        self.assertTrue(MyFile.checkFileExists(task1.getInputDirectory()))
        self.assertTrue(MyFile.checkFileExists(task1.getTempDirectory()))
        self.assertTrue(MyFile.checkFileExists(task1.getOutputDirectory()))

        dataListPath = "%s%s%s" % (task1.getInputDirectory(), os.sep,
                                   'data.ilist')
        dataMap1Path = "%s%s%s" % (task1.getInputDirectory(), os.sep,
                                   'audio.imap')
        dataMap2Path = "%s%s%s" % (task1.getInputDirectory(), os.sep,
                                   'model.imap')

        self.assertTrue(MyFile.checkFileExists(dataListPath))
        self.assertTrue(MyFile.checkFileExists(dataMap1Path))
        self.assertTrue(MyFile.checkFileExists(dataMap2Path))

        self.assertEqual(15, task1.inputList.getCount())
        self.assertEqual(2, len(task1.mapLists))

        for dataMap in task1.mapLists:
            self.assertTrue(dataMap.getCount() in [2, 1])

        task1 = Task(
            TaskInfo("", TestTask.workingDirectory, TestTask.targetFolderErr))

        #Two input lists
        with self.assertRaises(Exception):
            task1.gatherInputData()
Exemplo n.º 3
0
    def testSetResults(self):
        task1 = Task(
            TaskInfo("", TestTask.workingDirectory, TestTask.targetFolder1))

        task1.setResult("error", "message")
        self.assertEqual("error", task1.resultErrorFlag)
        self.assertEqual("message", task1.resultMessage)
Exemplo n.º 4
0
    def testExecute(self):
        task1 = Task(
            TaskInfo("", TestTask.workingDirectory, TestTask.targetFolder1))

        task1.validateParameters = lambda: Task.validateParameters(task1, [])

        task1.execute()
Exemplo n.º 5
0
    def testGetParametersDict(self):
        task1 = Task(
            TaskInfo("", TestTask.workingDirectory, TestTask.targetFolder1))

        paramDict = task1.getTaskInfo().getParametersDict()

        self.assertEqual(0, len(paramDict))
Exemplo n.º 6
0
    def testBuildParametersDict(self):
        task1 = Task(
            TaskInfo("param1=v1;param2=v2", TestTask.workingDirectory,
                     TestTask.targetFolder1))

        task1._buildParametersDictionary()

        task1 = Task(
            TaskInfo("param1=;param2=v2", TestTask.workingDirectory,
                     TestTask.targetFolder1))

        with self.assertRaises(Exception):
            task1._buildParametersDictionary()

        task1 = Task(
            TaskInfo("=v1;param2=v2", TestTask.workingDirectory,
                     TestTask.targetFolder1))

        with self.assertRaises(Exception):
            task1._buildParametersDictionary()
Exemplo n.º 7
0
    def testValidateParameters(self):
        task1 = Task(
            TaskInfo("", TestTask.workingDirectory, TestTask.targetFolder1))

        with self.assertRaises(Exception):
            task1.validateParameters(["param1"])

        Task.COMMON_PARAMETERS = ["param1"]

        with self.assertRaises(Exception):
            task1.validateParameters([])

        Task.COMMON_PARAMETERS = []
Exemplo n.º 8
0
	def testGetParametersDict(self):
		taskInfo = TaskInfo("param1=1;param2=2", "","")
		paramDict = taskInfo.getParametersDict()

		self.assertTrue('param1' in paramDict)
		self.assertTrue('param2' in paramDict)

		taskInfo = TaskInfo("", "","")
		paramDict = taskInfo.getParametersDict()
		self.assertEqual(0,len(paramDict))

		taskInfo = TaskInfo("param1", "","")
		
		with self.assertRaises(Exception):
			taskInfo.getParametersDict()
Exemplo n.º 9
0
#
if __name__ == "__main__":
    #Setup parser
    parser = argparse.ArgumentParser(description=usage)
    parser.add_argument("-t", "--target", help="target directory containing the data.olist and data.omap", 
                         nargs=1, dest="targetDir", required=True)
    parser.add_argument("-o", "--output", help="output directory", nargs=1, dest="outputDir", required=True)
    parser.add_argument("-r", "--regex", help="regex file", nargs=1, dest="regexFile", required=True)
    parser.add_argument("-f", "--filter", help="filter sentences", dest="filter",action="store_true")
    parser.add_argument("-d", "--debug", help="enable debug output", action="store_true")
    parser.add_argument("-n", "--rmpunctuation", help="remove punctuation", action="store_true")
    parser.add_argument("-p", "--vbpunctuation", help="verbalize punctuation", action="store_true")
    parser.add_argument("-s", "--rawseg", help="do not segment sentences with NLTK", dest="rawseg",action="store_true")
    parser.add_argument("-m", "--lm", help="prepare for lm modeling", dest="lm",action="store_true")

    #Parse arguments
    args = parser.parse_args()
    targetDir = args.targetDir[0]
    outputDir = args.outputDir[0]
    regexFile = args.regexFile[0]

    segmentWithNLTK = "True" if not args.rawseg else "False"

    setupLogging(logging.INFO, outputDir + "/task_log.txt")

    task = ImportDocumentTask(TaskInfo(STRPARAMETERS % (regexFile, str(args.debug), 
                                                        args.rmpunctuation, args.vbpunctuation,
                                                        segmentWithNLTK, args.filter, args.lm), 
                                       outputDir, targetDir))
    task.execute()
Exemplo n.º 10
0
    def testBuildTaskPath(self):
        task1 = Task(
            TaskInfo("", TestTask.workingDirectory, TestTask.targetFolder1))

        with self.assertRaises(Exception):
            task1._buildTaskPath("path")
Exemplo n.º 11
0
    def testBuildTask(self):
        task1 = Task(
            TaskInfo("", TestTask.workingDirectory, TestTask.targetFolder1))

        self.assertTrue(task1.taskUniqueId > 0)
Exemplo n.º 12
0
    def testTaskInfo(self):
        taskInfo = TaskInfo("param1=1;param2=2", "", "")

        self.assertEqual("param1=1;param2=2", taskInfo.parametersString)
        self.assertTrue("" != taskInfo.workingDirectory)
        self.assertTrue("" != taskInfo.targetDirectory)
Exemplo n.º 13
0
                        help="enable debug output",
                        action="store_true")
    parser.add_argument("-n",
                        "--rmpunctuation",
                        help="remove punctuation",
                        action="store_true")
    parser.add_argument("-p",
                        "--vbpunctuation",
                        help="verbalize punctuation",
                        action="store_true")
    parser.add_argument("-m",
                        "--lm",
                        help="prepare for lm modeling",
                        dest="lm",
                        action="store_true")

    #Parse arguments
    args = parser.parse_args()
    targetDir = args.targetDir[0]
    outputDir = args.outputDir[0]
    regexFile = args.regexFile[0]

    setupLogging(logging.INFO, outputDir + "/task_log.txt")

    task = ImportDocumentTask(
        TaskInfo(
            STRPARAMETERS % (regexFile, str(args.debug), args.rmpunctuation,
                             args.vbpunctuation, args.filter, args.lm),
            outputDir, targetDir))
    task.execute()