Esempio n. 1
0
        private void AddSuffix(SuffixDictionaryLine entry,
            Dictionary<string, Suffix> suffixesById,
            MorphemeSurfaceDictionary<Suffix> suffixes)
        {
            string id = entry.Id;
            string lex = entry.Lex;
            MorphemeType morphemeType;

            if (!Enum.TryParse(entry.Type, out morphemeType))
            {
                morphemeType = MorphemeType.O;
                Console.WriteLine("Invalid Morpheme Type: " + entry.Type);
            }

            string[] flags = entry.Flags.Split(new[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);
            string[] rulesToken = entry.Rules.Split(new[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);
            Debug.Assert(entry.Surfaces != null, "entry.Surfaces != null");
            var surfaces =
                new List<string>(entry.Surfaces.Split(new[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries));

            List<OrthographyRule> rules = _orthography.GetRules(rulesToken);
            var suffix = new Suffix(id, lex, morphemeType, LabelSet.ConvertLabelNamesToIndexes(flags), rules);
            suffixesById.Add(id, suffix);

            foreach (string surface in surfaces)
            {
                suffixes.Add(surface, suffix);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Appends the given suffix to this word.
        /// </summary>
        /// <param name="suffix">The suffix to be appended</param>
        public void AddSuffix(Suffix suffix)
        {
            var allomorph = new Allomorph(suffix);

            _allomorphs.AddLast(allomorph);
            allomorph.SetNode(_allomorphs.Last);
        }
Esempio n. 3
0
        public void AddSuffixAfterRoot(Suffix suffix)
        {
            var allomorph = new Allomorph(suffix);

            _allomorphs.AddAfter(_allomorphs.First, allomorph);
            allomorph.SetNode(_allomorphs.First.Next);
            ResetSurface();
        }
Esempio n. 4
0
 /// <summary>
 /// Appends the given suffix to this word and returns true if this operation is valid for the given language.
 /// Otherwise does not append the suffix and returns false.
 /// </summary>
 /// <param name="suffix">The suffix to be appended</param>
 /// <param name="language">The language for which the validity check is performed</param>
 public bool AddSuffix(Suffix suffix, Language language)
 {
     AddSuffix(suffix);
     if (!language.Morphotactics.IsValid(this))
     {
         RemoveLastSuffix();
         return(false);
     }
     return(true);
 }
Esempio n. 5
0
        private void AddSuffix(SuffixDictionaryLine entry,
            Dictionary<string, Suffix> suffixesById,
            MorphemeSurfaceDictionary<Suffix> suffixes)
        {
            string id = entry.Id;
            string lex = entry.Lex;
            MorphemeType morphemeType;

            if (!Enum.TryParse(entry.Type, out morphemeType))
            {
                morphemeType = MorphemeType.O;
                Trace.TraceEvent(TraceEventType.Error, 0, $"Invalid Morpheme Type: {entry.Type}");
            }

            string[] labels = entry.Labels.Split(new[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);
            string[] rulesToken = entry.Rules.Split(new[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);
            Debug.Assert(entry.Surfaces != null, "entry.Surfaces != null");
            var surfaces =
                new List<string>(entry.Surfaces.Split(new[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries));

            List<OrthographyRule> rules = _orthography.GetRules(rulesToken);
            var suffix = new Suffix(id, lex, new ImmutableSortedSet<string>(surfaces), morphemeType, new ImmutableHashSet<string>(labels), rules);
            if (suffixesById.ContainsKey(id))
            {
                Trace.TraceEvent(TraceEventType.Warning, 0, $"Duplicate suffix: {id}");
            }
            else
            {
                suffixesById.Add(id, suffix);
            }

            foreach (string surface in surfaces)
            {
                suffixes.Add(surface.Replace('_', ' '), suffix);
            }
        }