本文整理汇总了C#中ErrorSet类的典型用法代码示例。如果您正苦于以下问题:C# ErrorSet类的具体用法?C# ErrorSet怎么用?C# ErrorSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ErrorSet类属于命名空间,在下文中一共展示了ErrorSet类的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: Compile
/// <summary>
/// Compiles quotation mark table into binary stream.
/// </summary>
/// <param name="quoteTable">The instance of quotation mark table.</param>
/// <param name="outputStream">The instance of output binary stream.</param>
/// <returns>Any error found during the compilation.</returns>
public static ErrorSet Compile(QuotationMarkTable quoteTable, Stream outputStream)
{
if (quoteTable == null)
{
throw new ArgumentNullException("quoteTable");
}
if (outputStream == null)
{
throw new ArgumentNullException("outputStream");
}
ErrorSet errorSet = new ErrorSet();
BinaryWriter writer = new BinaryWriter(outputStream);
writer.Write((uint)quoteTable.Language);
writer.Write((uint)quoteTable.Items.Count);
foreach (var item in quoteTable.Items)
{
writer.Write((ushort)item.Left);
writer.Write((ushort)item.Right);
writer.Write((uint)item.Direct);
}
return errorSet;
}
示例3: ValidateCompoundRule
/// <summary>
/// Validate compound rule file.
/// </summary>
/// <param name="filePath">Compound rule file path.</param>
/// <param name="phoneset">TTS phone set.</param>
/// <returns>ErrorSet.</returns>
public static ErrorSet ValidateCompoundRule(string filePath, TtsPhoneSet phoneset)
{
// Validate parameter
if (string.IsNullOrEmpty(filePath))
{
throw new ArgumentNullException("filePath");
}
if (!File.Exists(filePath))
{
throw Helper.CreateException(typeof(FileNotFoundException), filePath);
}
ErrorSet errorSet = new ErrorSet();
using (XmlTextReader xmlTextReader = new XmlTextReader(filePath))
{
while (xmlTextReader.Read())
{
if (xmlTextReader.NodeType == XmlNodeType.Element &&
xmlTextReader.Name == "out")
{
if (xmlTextReader.Read() && xmlTextReader.NodeType == XmlNodeType.Text)
{
ValidateCompoundRuleNodePron(xmlTextReader.Value.Trim(),
phoneset, xmlTextReader.LineNumber, errorSet);
}
}
}
}
return errorSet;
}
示例4: LoadDataObject
/// <summary>
/// Load Lexicon Data object.
/// </summary>
/// <param name="errorSet">ErrorSet.</param>
/// <returns>Lexicon Data object.</returns>
internal override object LoadDataObject(ErrorSet errorSet)
{
Lexicon lexicon = new Lexicon(this.Language);
Lexicon.ContentControler lexiconControler = new Lexicon.ContentControler();
lexiconControler.IsCaseSensitive = true;
lexicon.Load(this.Path, lexiconControler);
return lexicon;
}
示例5: AstHelper
public AstHelper(ModuleBuilder moduleBuilder)
{
ModuleBuilder = moduleBuilder;
Expecting = new Expecting();
Functions = new FunctionScope();
Variables = new VariableScope();
Types = new TypeScope();
Errors = new ErrorSet();
ReturnScope = new ReturnScope();
}
示例6: Compile
/// <summary>
/// Compiler.
/// </summary>
/// <param name="mapFileName">Path of phoneme mapping file.</param>
/// <param name="sourceAsId">Whether source phone is phone id, to converted into int.</param>
/// <param name="outputStream">Output Stream.</param>
/// <returns>ErrorSet.</returns>
public static ErrorSet Compile(string mapFileName, bool sourceAsId, Stream outputStream)
{
if (string.IsNullOrEmpty(mapFileName))
{
throw new ArgumentNullException("mapFileName");
}
if (outputStream == null)
{
throw new ArgumentNullException("outputStream");
}
ErrorSet errorSet = new ErrorSet();
PhonemeMap phonemeMap = new PhonemeMap();
phonemeMap.LoadXml(mapFileName);
// Convert SAPI phoneme string
if (sourceAsId)
{
ConvertSourcePhoneID(phonemeMap.Pairs);
}
phonemeMap.Sort();
// Write the binary mapping file
BinaryWriter writer = new BinaryWriter(outputStream);
{
// Write number of phoneme mapping tables
writer.Write(1);
byte[] data = phonemeMap.ToBytes();
writer.Write(data.Length);
writer.Write(data);
}
return errorSet;
}
示例7: 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;
}
示例8: CompTruncRuleData
/// <summary>
/// Compile the trunc rule into binary writer.
/// </summary>
/// <param name="truncRuleFileName">File path of trunc rule.</param>
/// <param name="phoneSet">Phone set.</param>
/// <param name="bw">Binary writer.</param>
/// <returns>Error.</returns>
private static ErrorSet CompTruncRuleData(string truncRuleFileName, TtsPhoneSet phoneSet, BinaryWriter bw)
{
// maximum truncate rule length is 5 phonmes currently
const int MaxTruncRuleLength = 5;
ErrorSet errorSet = new ErrorSet();
List<TruncateNucleusRule> rules = new List<TruncateNucleusRule>();
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(truncRuleFileName);
XmlNamespaceManager nm = new XmlNamespaceManager(xmldoc.NameTable);
nm.AddNamespace("tts", "http://schemas.microsoft.com/tts/toolsuite");
XmlNodeList nodeList = xmldoc.DocumentElement.SelectNodes(
"/tts:offline/tts:truncateRules/tts:truncateRule", nm);
if (nodeList != null)
{
foreach (XmlNode node in nodeList)
{
XmlNodeList phoneNodeList;
XmlElement xmlNode = node as XmlElement;
string side = xmlNode.GetAttribute("side");
int direction = 0;
if (side.Equals("Right", StringComparison.OrdinalIgnoreCase))
{
direction = 2; // TruncFromRight
}
else if (side.Equals("Left", StringComparison.OrdinalIgnoreCase))
{
direction = 1; // TruncFromLeft
}
else
{
errorSet.Add(UnitGeneratorDataCompilerError.WrongRuleSide,
side, xmlNode.InnerXml);
}
phoneNodeList = xmlNode.SelectNodes("tts:phone", nm);
if (phoneNodeList.Count > MaxTruncRuleLength)
{
errorSet.Add(UnitGeneratorDataCompilerError.RuleLengthExceeded,
MaxTruncRuleLength.ToString(CultureInfo.InvariantCulture), xmlNode.InnerXml);
}
else
{
int idx = 0;
short[] ids = new short[MaxTruncRuleLength + 1];
foreach (XmlNode phoneNode in phoneNodeList)
{
XmlElement xmlPhoneNode = phoneNode as XmlElement;
string phoneValue = xmlPhoneNode.GetAttribute("value");
Phone phone = phoneSet.GetPhone(phoneValue);
if (phone != null)
{
ids[idx++] = (short)phone.Id;
}
else
{
errorSet.Add(UnitGeneratorDataCompilerError.InvalidPhone, phoneValue);
}
}
ids[idx] = 0;
TruncateNucleusRule rule = new TruncateNucleusRule();
rule.Ids = ids;
rule.Direction = direction;
rules.Add(rule);
}
}
}
// write the data
bw.Write(rules.Count);
foreach (TruncateNucleusRule ci in rules)
{
bw.Write(ci.Direction);
for (int i = 0; i < ci.Ids.Length; i++)
{
bw.Write(BitConverter.GetBytes(ci.Ids[i]));
}
}
return errorSet;
}
示例9: 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);
}
}
示例10: Validate
/// <summary>
/// Data validation.
/// </summary>
/// <param name="language">Language.</param>
/// <returns>Data error set found.</returns>
public ErrorSet Validate(Language language)
{
// Files existance validation
if (!Directory.Exists(Dir))
{
throw Helper.CreateException(typeof(DirectoryNotFoundException),
Dir);
}
if (!File.Exists(ScriptFilePath))
{
throw Helper.CreateException(typeof(FileNotFoundException),
ScriptFilePath);
}
if (!File.Exists(FileMapFilePath))
{
throw Helper.CreateException(typeof(FileNotFoundException),
FileMapFilePath);
}
if (!File.Exists(UnitFeatureFilePath))
{
throw Helper.CreateException(typeof(FileNotFoundException),
UnitFeatureFilePath);
}
ErrorSet errorSet = new ErrorSet();
ErrorSet subErrorSet =
FindUnmatchedSentences(ScriptFilePath, language, FileMapFilePath);
errorSet.Merge(subErrorSet);
subErrorSet = ValidateFeatureData(UnitFeatureFilePath, ScriptFilePath,
language);
errorSet.Merge(subErrorSet);
return errorSet;
}
示例11: 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)
{
//.........这里部分代码省略.........
示例12: CreateParser
private CFlatTree CreateParser(string input, ErrorSet errorSet)
{
var antlrStringStream = new ANTLRStringStream(input);
var lexter = new CFlatLexer(antlrStringStream);
var tokens = new CommonTokenStream(lexter);
var parser = new CFlatParser(tokens);
var tree = parser.prog().Tree;
var nodes = new CommonTreeNodeStream(tree);
var walker = new CFlatTree(nodes, errorSet);
return walker;
}
示例13: 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;
}
示例14: GetObject
/// <summary>
/// Get the object.
/// </summary>
/// <param name="errorSet">ErrorSet.</param>
/// <returns>Object.</returns>
public object GetObject(ErrorSet errorSet)
{
if (errorSet == null)
{
throw new ArgumentNullException("errorSet");
}
if (!_processedLoad && _object == null)
{
_processedLoad = true;
if (string.IsNullOrEmpty(this.Path))
{
errorSet.Add(DataCompilerError.PathNotInitialized, this.Name);
}
else if (!File.Exists(this.Path))
{
errorSet.Add(DataCompilerError.RawDataNotFound, this.Name,
this.Path);
}
else
{
_object = LoadDataObject(errorSet);
}
}
else if (_processedLoad && _object == null)
{
errorSet.Add(DataCompilerError.RawDataError, this.Name);
}
return _object;
}
示例15: allErrors
public static ErrorSet allErrors() {
ErrorSet ret = new ErrorSet(bwapiPINVOKE.allErrors(), false);
return ret;
}