}//end WriteOutputTxtFile private void WriteOutputMatlabScript() { logger.LogTrace("Writting to output file..."); // Get number of targets uint numTargets = (uint)((TargetCode[])Enum.GetValues(typeof(TargetCode))).Length - 1;// -1 remove DEFAULT foreach (WordFeatures contextFeature in contextFeatures) { // Write to the output file // DEFAULT classes are not written if ((contextFeature.target != TargetCode.DEFAULT) && (contextFeature.features != null)) { // Pass numTargets since ConvertToBitfieldString assumes the value can take 0, while this is not the case for target array, so the bit-field length will be the from 0 to the passed argument, so we pass numTargets - 1 // Also, this function assumes the passed value starts from 0 while our target starts from 1 so we subtract 1 from target String targetString = FeaturesFormatter.ConvertToBitfieldString((int)contextFeature.target - 1, numTargets - 1); // Write the target targetAssignementString += targetString; // Write the features featuresAssignementString += contextFeature.features; numExamplesInOutFile++; } } // end foreach logger.LogTrace("Writting to output file done successfuly"); } //end WriteOutputMatlabScript
}// end FormatTargetStringFeatures() // Utility to return empty target string protected override String EmptyTargetString() { if ((String)configManager.suppressFeaturesHashTable["ContextTargets"] != "Suppress") { switch (configManager.targetType) { case "DIAC": return(FeaturesFormatter.ConvertToBitfieldString(0, (uint)((TargetCode[])Enum.GetValues(typeof(TargetCode))).Length)); //break; case "POS": return(FeaturesFormatter.ConvertToBitfieldString(0, (uint)Parser.maxIDs.POS_IDs[0] + 1)); //break; default: Console.WriteLine("Incorrect TargetType configuration. {0} is invalid configuration. Valid configurations are: DIAC or POS.", configManager.targetType); return(null); //break; } // end switch } // end if !Suppress("ContextTargets") else { return(null); } }// end EmptyFeatureString()
} // end ComputeStringLength // Method to format the targetString protected override void FormatTargetStringFeatures(ref WordFeatures wordFeatures) { String targetString = ""; if ((String)configManager.suppressFeaturesHashTable["ContextTargets"] != "Suppress") { // Get number of targets uint numDiacTargets = (uint)((TargetCode[])Enum.GetValues(typeof(TargetCode))).Length; uint numPOSTargets = (uint)Parser.maxIDs.POS_IDs[0] + 1; switch (configManager.targetType) { case "DIAC": targetString = FeaturesFormatter.ConvertToBitfieldString(wordFeatures.target[0], numDiacTargets); break; case "POS": targetString = FeaturesFormatter.ConvertToBitfieldString(wordFeatures.target, numPOSTargets); break; default: Console.WriteLine("Incorrect TargetType configuration. {0} is invalid configuration. Valid configurations are: DIAC or POS.", configManager.targetType); break; } // end switch } // end if !Suppress("ContextTargets") wordFeatures.targetString = targetString; }// end FormatTargetStringFeatures()
} // end ComputeStringLength // Method to format the targetString protected override void FormatTargetStringFeatures(ref Feature wordFeatures) { String targetString = ""; if ((String)configManager.suppressFeaturesHashTable["ContextTargets"] != "Suppress") { switch (configManager.targetType) { case "SYNT_DIAC": case "FULL_DIAC": case "ClassifySyntDiac": uint numDiacTargets = (uint)((TargetDiacCode[])Enum.GetValues(typeof(TargetDiacCode))).Length; targetString = FeaturesFormatter.ConvertToBitfieldString(wordFeatures.target[0], numDiacTargets); break; case "POS": uint numPOSTargets; switch (configManager.targetMode) { case "Single": numPOSTargets = (uint)((TargetPOSCode[])Enum.GetValues(typeof(TargetPOSCode))).Length; targetString = FeaturesFormatter.ConvertToBitfieldString(wordFeatures.target[0], numPOSTargets); break; case "Multiple": numPOSTargets = (uint)parser.maxIDs.POS_IDs[0] + 1; targetString = FeaturesFormatter.ConvertToBitfieldString(wordFeatures.target, numPOSTargets); break; default: Console.WriteLine("Incorrect TargetMode configuration. {0} is invalid configuration. Valid configurations are: Single or Multiple.", configManager.targetMode); break; } // end switch (configManager.targetMode) break; default: Console.WriteLine("Incorrect TargetType configuration. {0} is invalid configuration. Valid configurations are: FULL_DIAC, SYNT_DIAC, ClassifySyntDiac or POS.", configManager.targetType); break; } // end switch } // end if !Suppress("ContextTargets") wordFeatures.targetString = targetString; }// end FormatTargetStringFeatures()
} //end WriteOutputMatlabScript private void WriteOutputMatlabworkspace() { logger.LogTrace("Writting to output workspace..."); // Get number of targets uint numDiacTargets = (uint)((TargetCode[])Enum.GetValues(typeof(TargetCode))).Length - 1;// -1 remove DEFAULT uint numPOSTargets = (uint)Parser.maxIDs.POS_IDs[0] + 1; //String[] featuresStringArr = new String[contextFeatures.Length]; //String[] targetsStringArr = new String[contextFeatures.Length]; //Double[] s = new Double[contextFeatures.Length]; ArrayList featuresStringArr = new ArrayList(); ArrayList targetsStringArr = new ArrayList(); foreach (WordFeatures contextFeature in contextFeatures) { //s[i] = Double.Parse(contextFeature.features); //featuresStringArr[i] = contextFeature.features; //i++; // Write to the output file // Write to the output file if (configManager.logExamplesEvenNoTargetDetected) { // DEFAULT classes are written if (contextFeature.features != null) { String targetString = String.Empty; switch (configManager.targetType) { case "DIAC": targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target[0], numDiacTargets); break; case "POS": targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target, numPOSTargets); break; default: Console.WriteLine("Incorrect TargetType configuration. {0} is invalid configuration. Valid configurations are: DIAC or POS.", configManager.targetType); break; }// end switch //String targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target, numDiacTargets); /*if (contextFeature.target == TargetCode.DAMMETEN) * { * cntr++; * }*/ targetsStringArr.Add(targetString); //matlab.PutWorkspaceData("mTarget", "base", targetString); //matlab.Execute(@"mTargets = [mTargets; mTarget];"); featuresStringArr.Add(contextFeature.features); //matlab.PutWorkspaceData("mFeature", "base", contextFeature.features); //matlab.Execute(@"mFeatures = [mFeatures; mFeature];"); numExamplesInOutFile++; } } else { // DEFAULT classes are not written if ((contextFeature.target[0] != (int)TargetCode.DEFAULT) && (contextFeature.features != null)) { String targetString = String.Empty; switch (configManager.targetType) { case "DIAC": targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target[0], numDiacTargets); break; case "POS": targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target, numPOSTargets); break; default: Console.WriteLine("Incorrect TargetType configuration. {0} is invalid configuration. Valid configurations are: DIAC or POS.", configManager.targetType); break; }// end switch //String targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target, numDiacTargets); /*if (contextFeature.target == TargetCode.DAMMETEN) * { * cntr++; * }*/ targetsStringArr.Add(targetString); //matlab.PutWorkspaceData("mTarget", "base", targetString); //matlab.Execute(@"mTargets = [mTargets; mTarget];"); featuresStringArr.Add(contextFeature.features); //matlab.PutWorkspaceData("mFeature", "base", contextFeature.features); //matlab.Execute(@"mFeatures = [mFeatures; mFeature];"); numExamplesInOutFile++; } } }// end foreach /*matlab.PutWorkspaceData("mCurrTargets", "base", targetsStringArr.ToArray()); * matlab.Execute("mTargets = [mTargets; mCurrTargets];"); * matlab.PutWorkspaceData("mCurrFeatures", "base", featuresStringArr.ToArray()); * matlab.Execute("mFeatures = [mFeatures; mCurrFeatures];");*/ //fileNumber++; /*if (fileNumber == 101) * { * int x = 1; * }*/ String s; //targetsStringArr[2] = "1,"; matlab.PutWorkspaceData("mCurrTargets", "base", targetsStringArr.ToArray()); s = matlab.Execute("x1 = cell2mat(mCurrTargets)"); if (Regex.Match(s, "Error").Success) { logger.LogError(s, ErrorCode.MATLAB_ERROR); } s = matlab.Execute("x2 = str2num(x1)"); if (Regex.Match(s, "Error").Success) { logger.LogError(s, ErrorCode.MATLAB_ERROR); } s = matlab.Execute("mTargets = [mTargets; x2]"); if (Regex.Match(s, "Error").Success) { logger.LogError(s, ErrorCode.MATLAB_ERROR); } matlab.PutWorkspaceData("mCurrFeatures", "base", featuresStringArr.ToArray()); switch (featuresFormat) { case "Raw": s = matlab.Execute(@"for(i = 1 : size(mCurrFeatures, 1)) x4(i,:) = str2num(mCurrFeatures{i,:}); end"); if (Regex.Match(s, "Error").Success) { logger.LogError(s, ErrorCode.MATLAB_ERROR); } break; default: s = matlab.Execute("x3 = cell2mat(mCurrFeatures)"); if (Regex.Match(s, "Error").Success) { logger.LogError(s, ErrorCode.MATLAB_ERROR); } s = matlab.Execute("x4 = str2num(x3)"); if (Regex.Match(s, "Error").Success) { logger.LogError(s, ErrorCode.MATLAB_ERROR); } break; }// end switch s = matlab.Execute("clear x1 x2 x3 mCurrTargets mCurrFeatures;"); if (Regex.Match(s, "Error").Success) { logger.LogError(s, ErrorCode.MATLAB_ERROR); } //matlab.Execute("nBitfieldLength = 0"); s = matlab.Execute("find(x4 > nBitfieldLength)"); if (String.Compare(s, "\nans =\n\n Empty matrix: 0-by-1\n\n") != 0) { logger.LogError(s, ErrorCode.MATLAB_ERROR); logger.LogError("Raw ID's are " + s + " while bitfield length is " + contextBitfieldLength, ErrorCode.RAW_ID_MORE_THAN_BITFIELD_LEN); } s = matlab.Execute("mFeatures = [mFeatures; x4];"); if (Regex.Match(s, "Error").Success) { logger.LogError(s, ErrorCode.MATLAB_ERROR); } s = matlab.Execute("clear x4;"); if (Regex.Match(s, "Error").Success) { logger.LogError(s, ErrorCode.MATLAB_ERROR); } //matlab.Execute("if((size(mFeatures, 1) - size(mTargets, 1)) != 0) violatingFile = filesCount; end;"); s = matlab.Execute("if ((size(mFeatures, 1) - size(mTargets, 1)) ~= 0) violatingFile(filesCount + 1) = filesCount; end;"); if (Regex.Match(s, "Error").Success) { logger.LogError(s, ErrorCode.MATLAB_ERROR); } s = matlab.Execute("size(mFeatures, 1) - size(mTargets, 1)"); //int x = String.Compare(s, "\nans =\n\n 0\n\n"); if (String.Compare(s, "\nans =\n\n 0\n\n") != 0) { logger.LogError("Difference between targets and features sizes", ErrorCode.MATLAB_ERROR); } //matlab.PutCharArray("mFeatures", "base", s); //matlab.PutFullMatrix("mFeatures", "base", s, s); s = matlab.Execute("filesCount=filesCount+1;"); if (Regex.Match(s, "Error").Success) { logger.LogError(s, ErrorCode.MATLAB_ERROR); } logger.LogTrace("Writting to workspace done successfuly"); }//end WriteOutputTxtFile
}//end WriteOutputTxtFile private void WriteOutputMatlabScript() { logger.LogTrace("Writting to output file..."); // Get number of targets uint numDiacTargets = (uint)((TargetCode[])Enum.GetValues(typeof(TargetCode))).Length - 1;// -1 remove DEFAULT uint numPOSTargets = (uint)Parser.maxIDs.POS_IDs[0] + 1; foreach (WordFeatures contextFeature in contextFeatures) { // Write to the output file if (configManager.logExamplesEvenNoTargetDetected) { // DEFAULT classes are written if (contextFeature.features != null) { String targetString = String.Empty; switch (configManager.targetType) { case "DIAC": targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target[0], numDiacTargets); break; case "POS": targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target, numPOSTargets); break; default: Console.WriteLine("Incorrect TargetType configuration. {0} is invalid configuration. Valid configurations are: DIAC or POS.", configManager.targetType); break; }// end switch //String targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target, numDiacTargets); // Write the target targetAssignementString += targetString; // Write the features featuresAssignementString += contextFeature.features; numExamplesInOutFile++; } } else { // DEFAULT classes are not written if ((contextFeature.target[0] != (int)TargetCode.DEFAULT) && (contextFeature.features != null)) { String targetString = String.Empty; switch (configManager.targetType) { case "DIAC": targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target[0], numDiacTargets); break; case "POS": targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target, numPOSTargets); break; default: Console.WriteLine("Incorrect TargetType configuration. {0} is invalid configuration. Valid configurations are: DIAC or POS.", configManager.targetType); break; }// end switch //String targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target, numDiacTargets); // Write the target targetAssignementString += targetString; // Write the features featuresAssignementString += contextFeature.features; numExamplesInOutFile++; } } } // end foreach logger.LogTrace("Writting to output file done successfuly"); } //end WriteOutputMatlabScript
}//end WriteOutputTxtFile private void WriteOutputMatlabScript() { logger.LogTrace("Writting to output file..."); // Get number of targets /*uint numDiacTargets = (uint)((TargetDiacCode[])Enum.GetValues(typeof(TargetDiacCode))).Length - 1 - (uint)configManager.suppressTargetsHashTable.Count;// -1 remove DEFAULT * uint numPOSTargets = (uint)parser.maxIDs.POS_IDs[0] + 1 - (uint)configManager.suppressTargetsHashTable.Count;*/ uint numDiacTargets; uint numPOSTargets; foreach (Feature contextFeature in contextFeatures) { // Write to the output file if (configManager.logExamplesEvenNoTargetDetected && ((String)configManager.suppressTargetsHashTable[contextFeature.target[0].ToString()] != "Suppress")) { // DEFAULT classes are written if (contextFeature.features != null) { String targetString = String.Empty; switch (configManager.targetType) { case "SYNT_DIAC": case "FULL_DIAC": case "ClassifySyntDiac": numDiacTargets = (uint)((TargetDiacCode[])Enum.GetValues(typeof(TargetDiacCode))).Length - 1; // -1 remove DEFAULT //targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target[0], numDiacTargets); targetString = FeaturesFormatter.ConvertTargetToBitfieldString(contextFeature.target[0], numDiacTargets, configManager.suppressTargetsHashTable); break; case "POS": switch (configManager.targetMode) { case "Single": numPOSTargets = (uint)((TargetPOSCode[])Enum.GetValues(typeof(TargetPOSCode))).Length - 1; // -1 remove DEFAULT targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target[0], numPOSTargets); break; case "Multiple": numPOSTargets = (uint)parser.maxIDs.POS_IDs[0] + 1; targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target, numPOSTargets); break; default: Console.WriteLine("Incorrect TargetMode configuration. {0} is invalid configuration. Valid configurations are: Single or Multiple.", configManager.targetMode); break; } // end switch (configManager.targetMode) break; default: Console.WriteLine("Incorrect TargetType configuration. {0} is invalid configuration. Valid configurations are: FULL_DIAC, SYNT_DIAC, ClassifySyntDiac or POS.", configManager.targetType); break; }// end switch //String targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target, numDiacTargets); // Write the target targetAssignementString += targetString; // Write the features featuresAssignementString += contextFeature.features; numExamplesInOutFile++; } } else { // Is it default bool isDefault = true; switch (configManager.targetType) { case "SYNT_DIAC": case "FULL_DIAC": case "ClassifySyntDiac": isDefault = (contextFeature.target[0] == (int)TargetDiacCode.DEFAULT); break; case "POS": isDefault = (contextFeature.target[0] == (int)TargetPOSCode.DEFAULT); break; default: Console.WriteLine("Incorrect TargetType configuration. {0} is invalid configuration. Valid configurations are: FULL_DIAC, SYNT_DIAC, ClassifySyntDiac or POS.", configManager.targetType); break; } // end switch // DEFAULT classes are not written if (!isDefault && (contextFeature.features != null) && ((String)configManager.suppressTargetsHashTable[contextFeature.target[0].ToString()] != "Suppress")) { String targetString = String.Empty; switch (configManager.targetType) { case "SYNT_DIAC": case "FULL_DIAC": case "ClassifySyntDiac": numDiacTargets = (uint)((TargetDiacCode[])Enum.GetValues(typeof(TargetDiacCode))).Length - 1; // -1 remove DEFAULT //targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target[0], numDiacTargets); targetString = FeaturesFormatter.ConvertTargetToBitfieldString(contextFeature.target[0], numDiacTargets, configManager.suppressTargetsHashTable); break; case "POS": switch (configManager.targetMode) { case "Single": numPOSTargets = (uint)((TargetPOSCode[])Enum.GetValues(typeof(TargetPOSCode))).Length - 1; // -1 remove DEFAULT targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target[0], numPOSTargets); break; case "Multiple": numPOSTargets = (uint)parser.maxIDs.POS_IDs[0] + 1; targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target, numPOSTargets); break; default: Console.WriteLine("Incorrect TargetMode configuration. {0} is invalid configuration. Valid configurations are: Single or Multiple.", configManager.targetMode); break; } // end switch (configManager.targetMode) break; default: Console.WriteLine("Incorrect TargetType configuration. {0} is invalid configuration. Valid configurations are: FULL_DIAC, SYNT_DIAC, ClassifySyntDiac or POS.", configManager.targetType); break; }// end switch //String targetString = FeaturesFormatter.ConvertToBitfieldString(contextFeature.target, numDiacTargets); // Write the target targetAssignementString += targetString; // Write the features featuresAssignementString += contextFeature.features; numExamplesInOutFile++; } } } // end foreach logger.LogTrace("Writting to output file done successfuly"); } //end WriteOutputMatlabScript
} //end WriteOutputMatlabScript private void WriteOutputMatlabworkspace() { logger.LogTrace("Writting to output workspace..."); // Get number of targets uint numTargets = (uint)((TargetCode[])Enum.GetValues(typeof(TargetCode))).Length - 1;// -1 remove DEFAULT //String[] featuresStringArr = new String[contextFeatures.Length]; //String[] targetsStringArr = new String[contextFeatures.Length]; //Double[] s = new Double[contextFeatures.Length]; ArrayList featuresStringArr = new ArrayList(); ArrayList targetsStringArr = new ArrayList(); foreach (WordFeatures contextFeature in contextFeatures) { //s[i] = Double.Parse(contextFeature.features); //featuresStringArr[i] = contextFeature.features; //i++; // Write to the output file // DEFAULT classes are not written if ((contextFeature.target != TargetCode.DEFAULT) && (contextFeature.features != null)) { // Pass numTargets since ConvertToBitfieldString assumes the value can take 0, while this is not the case for target array, so the bit-field length will be the from 0 to the passed argument, so we pass numTargets - 1 // Also, this function assumes the passed value starts from 0 while our target starts from 1 so we subtract 1 from target String targetString = FeaturesFormatter.ConvertToBitfieldString((int)contextFeature.target - 1, numTargets - 1); /*if (contextFeature.target == TargetCode.DAMMETEN) * { * cntr++; * }*/ targetsStringArr.Add(targetString); //matlab.PutWorkspaceData("mTarget", "base", targetString); //matlab.Execute(@"mTargets = [mTargets; mTarget];"); featuresStringArr.Add(contextFeature.features); //matlab.PutWorkspaceData("mFeature", "base", contextFeature.features); //matlab.Execute(@"mFeatures = [mFeatures; mFeature];"); numExamplesInOutFile++; } }// end foreach /*matlab.PutWorkspaceData("mCurrTargets", "base", targetsStringArr.ToArray()); * matlab.Execute("mTargets = [mTargets; mCurrTargets];"); * matlab.PutWorkspaceData("mCurrFeatures", "base", featuresStringArr.ToArray()); * matlab.Execute("mFeatures = [mFeatures; mCurrFeatures];");*/ //fileNumber++; /*if (fileNumber == 101) * { * int x = 1; * }*/ matlab.PutWorkspaceData("mCurrTargets", "base", targetsStringArr.ToArray()); matlab.Execute("x1 = cell2mat(mCurrTargets)"); matlab.Execute("x2 = str2num(x1)"); matlab.Execute("mTargets = [mTargets; x2];"); matlab.PutWorkspaceData("mCurrFeatures", "base", featuresStringArr.ToArray()); switch (featuresFormat) { case "Raw": matlab.Execute(@"for(i = 1 : size(mCurrFeatures, 1)) x4(i,:) = str2num(mCurrFeatures{i,:}); end"); break; default: matlab.Execute("x3 = cell2mat(mCurrFeatures)"); matlab.Execute("x4 = str2num(x3)"); break; }// end switch matlab.Execute("clear x1 x2 x3 mCurrTargets mCurrFeatures;"); matlab.Execute("mFeatures = [mFeatures; x4];"); matlab.Execute("clear x4;"); //matlab.PutCharArray("mFeatures", "base", s); //matlab.PutFullMatrix("mFeatures", "base", s, s); logger.LogTrace("Writting to workspace done successfuly"); }//end WriteOutputTxtFile