예제 #1
0
        private static string GetEnumString(string value, EnumCase enumCase)
        {
            switch (enumCase)
            {
            case EnumCase.lower:
                return(value.ToLowerInvariant());

            case EnumCase.upper:
                return(value.ToUpperInvariant());

            default:
                return(value);
            }
        }
예제 #2
0
        public static TAttr GetEnumAttribute <TAttr>(this XmlReader reader, string name, TAttr defaultValue, EnumCase enumCase)
        {
            string value = reader.GetAttribute(name);

            if (!string.IsNullOrEmpty(value))
            {
                try
                {
                    return((TAttr)Enum.Parse(typeof(TAttr), GetEnumString(value, enumCase)));
                }
                catch (ArgumentException x)
                {
                    throw new InvalidDataException(string.Format(Resources.XmlUtil_GetAttribute_The_value__0__is_not_valid_for_the_attribute__1__, value, name), x);
                }
            }
            return(defaultValue);
        }
예제 #3
0
        private static async Task <List <List <SentenceDetector.SentenceDetectorToken> > > ReadCorpusAsync(List <string> trainDocuments, EnumCase ConvertCase, SentenceDetector sentenceDetector)
        {
            var allLines = new List <string>();

            foreach (var file in trainDocuments)
            {
                allLines.AddRange(await File.ReadAllLinesAsync(file));
            }

            var sentences = allLines.Where(l => l.StartsWith("# text =")).Select(l => l.Split(new char[] { '=' }, 2).Last().Trim()).ToList();

            if (ConvertCase == EnumCase.ForceUpper)
            {
                sentences = sentences.Select(s => s.ToUpperInvariant()).ToList();
            }
            if (ConvertCase == EnumCase.ForceLower)
            {
                sentences = sentences.Select(s => s.ToLowerInvariant()).ToList();
            }

            return(sentences.Select(s =>
            {
                var tk = sentenceDetector.SentenceDetectorTokenizer(s).Select(t => new SentenceDetector.SentenceDetectorToken(t.Value, t.Begin, t.End)).ToList();
                tk.Last().IsSentenceEnd = true;
                return tk;
            }).ToList());
        }
예제 #4
0
 public static TAttr GetEnumAttribute <TAttr>(this XmlReader reader, string name, TAttr defaultValue, EnumCase enumCase)
 {
     return(reader.GetEnumAttribute(name, null, defaultValue, enumCase));
 }
예제 #5
0
        private static List <List <SentenceDetector.SentenceDetectorToken> > ReadCorpus(List <string> trainDocuments, EnumCase ConvertCase, SentenceDetector sentenceDetector)
        {
            var allLines  = trainDocuments.SelectMany(f => File.ReadAllLines(f));
            var sentences = allLines.Where(l => l.StartsWith("# text =")).Select(l => l.Split(new char[] { '=' }, 2).Last().Trim()).ToList();

            if (ConvertCase == EnumCase.ForceUpper)
            {
                sentences = sentences.Select(s => s.ToUpperInvariant()).ToList();
            }
            if (ConvertCase == EnumCase.ForceLower)
            {
                sentences = sentences.Select(s => s.ToLowerInvariant()).ToList();
            }

            return(sentences.Select(s =>
            {
                var tk = sentenceDetector.SentenceDetectorTokenizer(s).Select(t => new SentenceDetector.SentenceDetectorToken(t.Value, t.Begin, t.End)).ToList();
                tk.Last().IsSentenceEnd = true;
                return tk;
            }).ToList());
        }
예제 #6
0
파일: XMLUtil.cs 프로젝트: laeubisoft/pwiz
        public static TAttr GetEnumAttribute <TAttr>(this XmlReader reader, string name, TAttr defaultValue, EnumCase enumCase)
        {
            string value = reader.GetAttribute(name);

            if (!string.IsNullOrEmpty(value))
            {
                try
                {
                    return((TAttr)Enum.Parse(typeof(TAttr), GetEnumString(value, enumCase)));
                }
                catch (ArgumentException x)
                {
                    throw new InvalidDataException(string.Format("The value {0} is not valid for the attribute {1}", value, name), x);
                }
            }
            return(defaultValue);
        }