本文整理汇总了C#中ErrorSet.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ErrorSet.Add方法的具体用法?C# ErrorSet.Add怎么用?C# ErrorSet.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ErrorSet
的用法示例。
在下文中一共展示了ErrorSet.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
/// <summary>
/// Load stemmer file.
/// </summary>
/// <param name="stemmerFilePath">Stemmer file path.</param>
/// <param name="errorSet">Error set.</param>
/// <returns>Loaded stemmer items.</returns>
public static Dictionary<string, string> Read(string stemmerFilePath,
ErrorSet errorSet)
{
Dictionary<string, string> stemmer = new Dictionary<string, string>();
foreach (string line in Helper.FileLines(stemmerFilePath))
{
string[] items = line.Split(Delimitor.TabChars, StringSplitOptions.RemoveEmptyEntries);
if (items.Length < 2)
{
errorSet.Add(StemmerFileError.OneColumnLine, line, stemmerFilePath);
continue;
}
for (int i = 1; i < items.Length; i++)
{
if (stemmer.ContainsKey(items[i]))
{
// Skips this one if there already has it.
continue;
}
stemmer.Add(items[i], items[0]);
}
}
return stemmer;
}
示例2: StringToId
/// <summary>
/// Convert the gender string to gender id.
/// </summary>
/// <param name="gender">Gender string.</param>
/// <param name="id">Gender id.</param>
/// <returns>Error set.</returns>
public static ErrorSet StringToId(string gender, out int id)
{
if (string.IsNullOrEmpty(gender))
{
throw new ArgumentNullException("gender");
}
id = 0;
ErrorSet errorSet = new ErrorSet();
for (int i = 0; i < gender.Length; i++)
{
Gender genderId = GetId(gender[i]);
if (genderId == Gender.None)
{
errorSet.Add(GenderError.UnrecognizedGender, gender[i].ToString());
}
else if ((((int)genderId) & id) != 0)
{
errorSet.Add(GenderError.DuplicateGender, gender[i].ToString());
}
else
{
id |= (int)genderId;
}
}
return errorSet;
}
示例3: ValidateFeatureData
/// <summary>
/// Validation data alignment between feature file and script file.
/// </summary>
/// <param name="featureFile">Feature file.</param>
/// <param name="scriptFile">Script file.</param>
/// <param name="language">Language.</param>
/// <returns>Data error set found.</returns>
public static ErrorSet ValidateFeatureData(string featureFile,
string scriptFile, Language language)
{
ErrorSet errorSet = new ErrorSet();
TtsPhoneSet phoneSet = Localor.GetPhoneSet(language);
XmlScriptValidateSetting validateSetting = new XmlScriptValidateSetting(phoneSet, null);
XmlScriptFile script = XmlScriptFile.LoadWithValidation(scriptFile, validateSetting);
if (script.ErrorSet.Count > 0)
{
string message = string.Format(CultureInfo.InvariantCulture,
"{0} error(s) found in the script file [{1}]",
script.ErrorSet.Count, scriptFile);
throw new InvalidDataException(message);
}
XmlUnitFeatureFile unitFeatureFile = new XmlUnitFeatureFile(featureFile);
if (unitFeatureFile.Units.Count <= 0)
{
string message = string.Format(CultureInfo.InvariantCulture,
"Zero unit feature item in unit feature file {0}", featureFile);
errorSet.Add(VoiceFontError.OtherErrors, message);
throw new InvalidDataException(message);
}
if (unitFeatureFile.Language != language)
{
string message = string.Format(CultureInfo.InvariantCulture,
"Different lanuage\r\nScript File {0}: lang = {1}\r\n Feature File {2}: lang = {3}",
scriptFile, Localor.LanguageToString(language),
featureFile, Localor.LanguageToString(unitFeatureFile.Language));
throw new InvalidDataException(message);
}
foreach (string key in unitFeatureFile.Units.Keys)
{
UnitFeature unit = unitFeatureFile.Units[key];
string sid = unit.SentenceId;
int unitIndex = unit.Index;
string unitName = unit.Name;
if (unit.Index < 0)
{
string message = string.Format(CultureInfo.InvariantCulture,
"invalid unit index [{0}] found in feature file [{1}]. It should not be negative integer for unit indexing.",
unit.Index, featureFile);
errorSet.Add(VoiceFontError.OtherErrors, message);
continue;
}
try
{
if (!script.ItemDic.ContainsKey(unit.SentenceId))
{
string message = string.Format(CultureInfo.InvariantCulture,
"sentence id {0} in feature file [{1}] is not in script file [{2}]",
sid, featureFile, scriptFile);
errorSet.Add(ScriptError.OtherErrors, sid, message);
continue;
}
ScriptItem item = script.ItemDic[sid];
Phoneme phoneme = Localor.GetPhoneme(language);
SliceData sliceData = Localor.GetSliceData(language);
Collection<TtsUnit> itemUnits = item.GetUnits(phoneme, sliceData);
if (unitIndex >= itemUnits.Count)
{
string message = string.Format(CultureInfo.InvariantCulture,
"the {0}th unit [{1}] in sentence {2} of feature file [{3}] is out of range for sentence {2} in script file [{4}]",
unitIndex, unitName, sid, featureFile, scriptFile);
errorSet.Add(ScriptError.OtherErrors, sid, message);
continue;
}
TtsUnit ttsUnit = itemUnits[unitIndex];
string sliceName = ttsUnit.FullName.Replace(' ', '+');
if (sliceName != unitName)
{
string str1 = "the {0}th unit [{1}] in sentence {3} of feature file [{4}] ";
string str2 = "is not matched with {0}th unit [{2}] for sentence {3} in script file [{5}]";
string message = string.Format(CultureInfo.InvariantCulture,
str1 + str2,
unitIndex, unitName, sliceName, sid, featureFile, scriptFile);
errorSet.Add(ScriptError.OtherErrors, sid, message);
continue;
}
}
catch (InvalidDataException ide)
{
//.........这里部分代码省略.........
示例4: Validate
/// <summary>
/// Validate char table.
/// </summary>
/// <param name="table">Char table.</param>
/// <param name="shallow">Shallow validation.</param>
/// <param name="wordsNotInLexicon">WordsNotInLexicon.</param>
/// <returns>ErrorSet.</returns>
public ErrorSet Validate(CharTable table,
bool shallow, Collection<string> wordsNotInLexicon)
{
if (table == null)
{
throw new ArgumentNullException("table");
}
ErrorSet errorSet = new ErrorSet();
int upperCaseNumber = 0;
int lowerCaseNumber = 0;
int digitNumber = 0;
Collection<string> symbols = new Collection<string>();
foreach (CharElement charElement in table.CharList)
{
if (charElement.Type == CharElement.CharType.UpperCase)
{
upperCaseNumber++;
}
else if (charElement.Type == CharElement.CharType.LowerCase)
{
lowerCaseNumber++;
}
else if (charElement.Type == CharElement.CharType.Digit)
{
digitNumber++;
}
if (!symbols.Contains(charElement.Symbol))
{
symbols.Add(charElement.Symbol);
}
else
{
errorSet.Add(new Error(CharTableError.DuplicateSymbol,
charElement.Symbol));
}
if (!shallow)
{
ValidateCharElement(charElement, errorSet, wordsNotInLexicon);
}
}
if (upperCaseNumber != lowerCaseNumber)
{
errorSet.Add(new Error(CharTableError.MismatchUpperAndLower,
upperCaseNumber.ToString(CultureInfo.InvariantCulture),
lowerCaseNumber.ToString(CultureInfo.InvariantCulture)));
}
if (digitNumber != 10)
{
errorSet.Add(new Error(CharTableError.ErrorDigitCount));
}
return errorSet;
}
示例5: Compile
/// <summary>
/// Compiler.
/// </summary>
/// <param name="truncRuleFileName">File path of trunc rule.</param>
/// <param name="phoneSet">Phone set.</param>
/// <param name="outputStream">Output Stream.</param>
/// <returns>ErrorSet.</returns>
public static ErrorSet Compile(string truncRuleFileName,
TtsPhoneSet phoneSet, Stream outputStream)
{
if (string.IsNullOrEmpty(truncRuleFileName))
{
throw new ArgumentNullException("truncRuleFileName");
}
// pauseLengthFileName could be null
if (phoneSet == null)
{
throw new ArgumentNullException("phoneSet");
}
if (outputStream == null)
{
throw new ArgumentNullException("outputStream");
}
ErrorSet errorSet = new ErrorSet();
phoneSet.Validate();
if (phoneSet.ErrorSet.Contains(ErrorSeverity.MustFix))
{
errorSet.Add(UnitGeneratorDataCompilerError.InvalidPhoneSet);
}
else
{
BinaryWriter bw = new BinaryWriter(outputStream);
{
errorSet.Merge(CompTruncRuleData(truncRuleFileName, phoneSet, bw));
}
}
return errorSet;
}
示例6: CheckGeneralPronExist
/// <summary>
/// Check if the pronunciation for general domain exist.
/// We check general domain pronunciation to avoid the case that word have address domain pronunciation, but got LTSed in general domain.
/// </summary>
/// <param name="domainLexItems">Domain lexiconItems.</param>
/// <param name="errorSet">The errorSet.</param>
/// <param name="word">The current word.</param>
private void CheckGeneralPronExist(Dictionary<string, LexicalItem> domainLexItems,
ErrorSet errorSet, string word)
{
Helper.ThrowIfNull(domainLexItems);
Helper.ThrowIfNull(errorSet);
if (!domainLexItems.ContainsKey(DomainItem.GeneralDomain))
{
errorSet.Add(LexiconError.LackGeneralDomainPronError, word);
}
}
示例7: ParsePolyCondition
/// <summary>
/// ParsePolyCondition.
/// </summary>
/// <param name="expression">Expression.</param>
/// <param name="condition">Condition.</param>
/// <param name="errorSet">ErrorSet.</param>
private void ParsePolyCondition(string expression,
PolyphonyCondition condition, ErrorSet errorSet)
{
string subExpression = expression;
// If the value is string, then search operator before """
if (subExpression.IndexOf('"') > 0)
{
subExpression = subExpression.Substring(0, subExpression.IndexOf('"'));
}
foreach (string oper in _allOperators)
{
if (subExpression.IndexOf(oper) >= 0)
{
condition.Operator = oper;
break;
}
}
bool succeeded = true;
if (string.IsNullOrEmpty(condition.Operator))
{
errorSet.Add(PolyRuleError.MissingOperatorInCondition,
expression);
succeeded = false;
}
if (succeeded)
{
condition.Key = expression.Substring(0,
expression.IndexOf(condition.Operator)).Trim();
if (!_keyTypes.ContainsKey(condition.Key))
{
errorSet.Add(PolyRuleError.NotDeclearedConditionKey,
condition.Key, expression);
succeeded = false;
}
}
if (succeeded)
{
string valueExpression = expression.Substring(
expression.IndexOf(condition.Operator) + condition.Operator.Length).Trim();
if (_keyTypes[condition.Key] == KeyType.String)
{
Match match = Regex.Match(valueExpression, @"^""(.*)""$");
if (match.Success)
{
valueExpression = match.Groups[1].ToString();
}
else
{
errorSet.Add(PolyRuleError.InvalidConditionFormat,
expression);
succeeded = false;
}
}
else
{
int intValue;
if (!int.TryParse(valueExpression, out intValue))
{
errorSet.Add(PolyRuleError.InvalidConditionFormat,
expression);
succeeded = false;
}
}
condition.Value = valueExpression;
}
}
示例8: TryParseKeyLine
/// <summary>
/// TryParseKeyLine.
/// </summary>
/// <param name="line">Line.</param>
/// <param name="polyphonyWord">PolyphonyWord.</param>
/// <param name="errorSet">ErrorSet.</param>
/// <param name="domain">Domain.</param>
/// <returns>Whether the line is key line.</returns>
private bool TryParseKeyLine(string line, ref PolyphonyRule polyphonyWord,
ErrorSet errorSet, string domain)
{
bool isKeyLine = false;
if (IsKeyLine(line))
{
isKeyLine = true;
if (polyphonyWord != null)
{
if (polyphonyWord.PolyphonyProns.Count == 0)
{
errorSet.Add(PolyRuleError.NoConditionForWord, polyphonyWord.Word);
}
else
{
_polyphonyWords.Add(polyphonyWord);
}
}
polyphonyWord = new PolyphonyRule();
polyphonyWord.Domain = domain;
int errorCountBeforeParsing = errorSet.Errors.Count;
string keyValue = ParseKeyValueLine(line, errorSet);
if (errorSet.Errors.Count == errorCountBeforeParsing)
{
polyphonyWord.Word = keyValue;
}
}
return isKeyLine;
}
示例9: Parse
/// <summary>
/// Parse word pos pair.
/// </summary>
/// <param name="wordPosPair">Word.</param>
/// <param name="attributeSchema">AttributeSchema.</param>
/// <returns>ErrorSet.</returns>
public ErrorSet Parse(string wordPosPair, LexicalAttributeSchema attributeSchema)
{
ErrorSet errorSet = new ErrorSet();
int slashIndex = wordPosPair.LastIndexOf(WordPosDelimeter);
if (slashIndex < 0 || slashIndex > wordPosPair.Length - 1)
{
errorSet.Add(PosCorpusError.InvalidFormat, wordPosPair);
}
else if (slashIndex == 0)
{
errorSet.Add(PosCorpusError.EmptyWord, wordPosPair);
}
else if (slashIndex == wordPosPair.Length - 1)
{
errorSet.Add(PosCorpusError.EmptyPos, wordPosPair);
}
else
{
WordText = wordPosPair.Substring(0, slashIndex);
string originalPos = wordPosPair.Substring(slashIndex + 1);
if (attributeSchema != null)
{
string posTaggingPos = attributeSchema.GetPosTaggingPos(originalPos);
if (string.IsNullOrEmpty(posTaggingPos))
{
errorSet.Add(PosCorpusError.NoPosTaggingPos, originalPos);
}
else
{
Pos = posTaggingPos;
}
}
else
{
Pos = originalPos;
}
}
return errorSet;
}
示例10: Load
/// <summary>
/// Load.
/// </summary>
/// <param name="filePath">FilePath.</param>
/// <param name="attributeSchema">LexicalAttributeSchema.</param>
/// <returns>The errotset.</returns>
public ErrorSet Load(string filePath, LexicalAttributeSchema attributeSchema)
{
if (string.IsNullOrEmpty(filePath))
{
throw new ArgumentNullException("filePath");
}
if (!File.Exists(filePath))
{
throw Helper.CreateException(typeof(FileNotFoundException), filePath);
}
if (!Helper.IsUnicodeFile(filePath))
{
throw new InvalidDataException(Helper.NeutralFormat(
"Invalid corpus file format(not UNICODE), should be UNICODE."));
}
_paragraphs.Clear();
int lineNumber = 0;
ErrorSet errorSetWithLine = new ErrorSet();
foreach (string line in Helper.FileLines(filePath, Encoding.Unicode, false))
{
lineNumber ++;
if (string.IsNullOrEmpty(line.Trim()))
{
continue;
}
PosCorpusParagraph paragraph = new PosCorpusParagraph();
ErrorSet errorSet = paragraph.Parse(line, attributeSchema);
if (errorSet.Errors.Count == 0)
{
Debug.Assert(paragraph.Words.Count > 0);
_paragraphs.Add(paragraph);
}
else
{
foreach (Error error in errorSet.Errors)
{
errorSetWithLine.Add(PosCorpusError.ErrorWithLine,
error, lineNumber.ToString(CultureInfo.InvariantCulture));
}
}
}
_filePath = filePath;
return errorSetWithLine;
}
示例11: Compile
public static ErrorSet Compile(string rnnModelPath, Stream outputStream, Collection<string> addedFileNames)
{
if (string.IsNullOrEmpty(rnnModelPath))
{
throw new ArgumentNullException("rnnModelPath");
}
if (outputStream == null)
{
throw new ArgumentNullException("outputStream");
}
if (addedFileNames == null)
{
throw new ArgumentNullException("addedFileNames");
}
ErrorSet errorSet = new ErrorSet();
if (!File.Exists(rnnModelPath))
{
errorSet.Add(RNNModelCompilerError.ModelDataNotFound, rnnModelPath);
}
else
{
BinaryWriter bw = new BinaryWriter(outputStream, Encoding.Unicode);
Dictionary<string, float> polyCharactersInfo = null;
List<string> polyphones = null;
List<float> thresholds = null;
// load polyphonic characters that should be enabled in product.
string polyphonicCharFile = Path.Combine(new DirectoryInfo(Path.GetDirectoryName(rnnModelPath)).Parent.FullName, "RNNPolyphoneList.txt");
if (File.Exists(polyphonicCharFile))
{
// If the list file is existed, load it.
polyCharactersInfo = LoadPolyphonicInfo(polyphonicCharFile, errorSet);
}
else
{
errorSet.Add(RNNModelCompilerError.PolyphonicCharFileNotFound, polyphonicCharFile);
}
polyphones = GetPolyphonicChars(polyCharactersInfo);
thresholds = GetPolyphonicThreshold(polyCharactersInfo);
uint polyCharCount = 0;
uint modelOffset = 0;
// write the count of polyphonic characters and polyphonic characters
using (StringPool plycharSp = new StringPool())
{
Collection<int> polycharOffsets = new Collection<int>();
StringPool.WordsToStringPool(polyphones, plycharSp, polycharOffsets);
polyCharCount = (uint)polycharOffsets.Count;
bw.Write(modelOffset);
bw.Write(polyCharCount);
foreach (float threshold in thresholds)
{
bw.Write(threshold);
}
byte[] plycharPool = plycharSp.ToArray();
foreach (int offset in polycharOffsets)
{
bw.Write((uint)offset);
}
bw.Write(plycharPool, 0, plycharPool.Length);
}
modelOffset = (uint)bw.BaseStream.Position;
// write rnn models
using (FileStream fs = new FileStream(rnnModelPath, FileMode.Open, FileAccess.Read))
using (BinaryReader br = new BinaryReader(fs))
{
bw.Write(br.ReadBytes((int)fs.Length));
}
bw.Flush();
bw.Seek(0, SeekOrigin.Begin);
bw.Write(modelOffset);
bw.Flush();
addedFileNames.Add(rnnModelPath);
}
return errorSet;
}
示例12: LoadPolyphonicInfo
/// <summary>
/// Load Polyphonic Characters That Should Be Enabled in Product.
/// </summary>
/// <param name="listFile">List File Path.</param>
/// <param name="errorSet">Error set.</param>
/// <returns>Polyphonic characters set.</returns>
private static Dictionary<string, float> LoadPolyphonicInfo(string listFile, ErrorSet errorSet)
{
Dictionary<string, float> polyCharactersInfo = new Dictionary<string, float>();
using (StreamReader sr = new StreamReader(listFile))
{
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
if (!string.IsNullOrEmpty(line))
{
string[] parts = line.Split(new char[] { '\t' });
if (parts.Length == 2)
{
string character = parts[0];
float threshold = float.Parse(parts[1]);
if (character.Length > 1)
{
errorSet.Add(RNNModelCompilerError.InvalidCharacterListFormat, listFile);
}
else
{
polyCharactersInfo.Add(character, threshold);
}
}
else
{
errorSet.Add(RNNModelCompilerError.InvalidCharacterListFormat, listFile);
}
}
}
}
if (polyCharactersInfo.Count == 0)
{
errorSet.Add(RNNModelCompilerError.PolyphonicCharNotFound, listFile);
}
return polyCharactersInfo;
}
示例13: CheckSegment
/// <summary>
/// Check for segment error for a specific segment.
/// </summary>
/// <param name="errors">Error list.</param>
/// <param name="itemID">Script ID.</param>
/// <param name="nodePath">Path of the node.</param>
/// <param name="segmentInterval">Segment interval.</param>
/// <param name="preSegEnd">Preivous segment end point.</param>
private static void CheckSegment(ErrorSet errors, string itemID, string nodePath,
SegmentInterval segmentInterval, ref int preSegEnd)
{
if (segmentInterval.Begin < preSegEnd)
{
string errorPath = string.Format(CultureInfo.InvariantCulture, "{0}.Acoustics", nodePath);
errors.Add(ScriptError.SegmentSequenceError, itemID, errorPath,
segmentInterval.Begin.ToString(CultureInfo.InvariantCulture),
preSegEnd.ToString(CultureInfo.InvariantCulture));
}
preSegEnd = segmentInterval.End;
}
示例14: IsValidItem
/// <summary>
/// Check whether a script item is valid
/// We don't check schema here
/// Validation conditions:
/// 1. Normal word should have pronunciation
/// 2. Pronunciation should be good
/// 3. POS should be in POS set
/// We could use some flag to control the validation conditions
/// When we need flexible control.
/// </summary>
/// <param name="item">The item to be checked.</param>
/// <param name="errors">Errors if item is invalid.</param>
/// <param name="validateSetting">Validation data set.</param>
/// <returns>True is valid.</returns>
public static bool IsValidItem(ScriptItem item, ErrorSet errors, XmlScriptValidateSetting validateSetting)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
if (errors == null)
{
throw new ArgumentNullException("errors");
}
if (validateSetting == null)
{
throw new ArgumentNullException("validateSetting");
}
validateSetting.VerifySetting();
XmlScriptValidationScope scope = validateSetting.ValidationScope;
bool valid = true;
errors.Clear();
int sentIndex = 0;
foreach (ScriptSentence sentence in item.Sentences)
{
int wordIndex = 0;
foreach (ScriptWord word in sentence.Words)
{
if ((scope & XmlScriptValidationScope.Pronunciation) == XmlScriptValidationScope.Pronunciation)
{
// check pronunciation
string pron = null;
if (word.WordType == WordType.Normal)
{
pron = word.GetPronunciation(validateSetting.PhoneSet);
}
if (!string.IsNullOrEmpty(pron))
{
ErrorSet pronErrors = Core.Pronunciation.Validate(pron, validateSetting.PhoneSet);
foreach (Error error in pronErrors.Errors)
{
errors.Add(ScriptError.PronunciationError, error, item.Id, word.Grapheme);
}
}
else if (word.WordType == WordType.Normal)
{
// Pronunciation is optional for normal word, will give warning if empty pronunciation for normal word.
errors.Add(ScriptError.EmptyPronInNormalWord, item.Id, word.Grapheme);
}
}
if ((scope & XmlScriptValidationScope.POS) == XmlScriptValidationScope.POS)
{
// check pos name
if (!string.IsNullOrEmpty(word.PosString) &&
!validateSetting.PosSet.Items.ContainsKey(word.PosString))
{
errors.Add(ScriptError.UnrecognizedPos, item.Id, word.Grapheme,
word.Pronunciation, word.PosString);
}
}
string nodePath = string.Format(CultureInfo.InvariantCulture, "Sentence[{0}].Word[{1}]",
sentIndex, wordIndex);
word.IsValid(item.Id, nodePath, scope, errors);
wordIndex++;
}
sentIndex++;
}
if ((scope & XmlScriptValidationScope.SegmentSequence) == XmlScriptValidationScope.SegmentSequence)
{
CheckSegments(item, errors);
}
if (errors.Count > 0)
{
valid = false;
}
return valid;
//.........这里部分代码省略.........
示例15: AddParseError
/// <summary>
/// AddParseError.
/// </summary>
/// <param name="errorSet">ErrorSet.</param>
/// <param name="lineNum">LineNum.</param>
/// <param name="parseErrorSet">ParseErrorSet.</param>
private void AddParseError(ErrorSet errorSet, int lineNum, ErrorSet parseErrorSet)
{
foreach (Error parseError in parseErrorSet.Errors)
{
Error error = new Error(PolyRuleError.ParseError, parseError,
lineNum.ToString(CultureInfo.InvariantCulture));
// Keep the same severity with the original error severity.
error.Severity = parseError.Severity;
errorSet.Add(error);
}
}