public void Dispose()
 {
     Combiner = null;
     Changer  = null;
     Tagger?.Dispose();
     Tagger = null;
 }
        public string ChangeText(string text)
        {
            IEnumerable <WNode> nodes = Tagger.Parse(text);

            if (ChangeToJotai)
            {
                Changer.PreferDearu = (JotaiPreferences & JotaiPreferences.PreferDearu) != 0;
                var buffer = new EditBuffer(nodes);
                Changer.ToJotai(buffer);
                nodes = buffer;
            }
            Combiner.CombineMode = CombineMode;
            switch (WidthPreferences
                    & (WidthPreferences.HalfwidthParentheses | WidthPreferences.FullwidthParentheses))
            {
            case WidthPreferences.HalfwidthParentheses:
                Combiner.Postprocess = TokenCombiner.AsciiParentheses;
                break;

            case WidthPreferences.FullwidthParentheses:
                Combiner.Postprocess = TokenCombiner.FullWidthParentheses;
                break;

            default:
                Combiner.Postprocess = null;
                break;
            }
            if (WidthPreferences.None != (WidthPreferences
                                          & (WidthPreferences.FullwidthAlphabets
                                             | WidthPreferences.FullwidthDigits
                                             | WidthPreferences.FullwidthSymbols
                                             | WidthPreferences.CustomFullwidthSet)))
            {
                var p = TokenCombiner.SimpleFullwidthPostprocess(
                    WidthPreferences.HasFlag(WidthPreferences.FullwidthAlphabets) ? TokenCombiner.AsciiAlphabets : null,
                    WidthPreferences.HasFlag(WidthPreferences.FullwidthDigits) ? TokenCombiner.AsciiDigits : null,
                    WidthPreferences.HasFlag(WidthPreferences.FullwidthSymbols) ? TokenCombiner.OtherAsciiSymbols : null,
                    WidthPreferences.HasFlag(WidthPreferences.CustomFullwidthSet) ? CustomFullwidthSet : null);
                var q = Combiner.Postprocess;
                Combiner.Postprocess = (q == null) ? p : sb => p(q(sb));
            }
            if (WidthPreferences.None != (WidthPreferences
                                          & WidthPreferences.CustomHalfwidthSet))
            {
                var p = TokenCombiner.SimpleHalfwidthPostprocess(
                    WidthPreferences.HasFlag(WidthPreferences.CustomHalfwidthSet) ? CustomHalfwidthSet : null);
                var q = Combiner.Postprocess;
                Combiner.Postprocess = (q == null) ? p : sb => p(q(sb));
            }
            var result = Combiner.Combine(nodes);

            return(result);
        }
        public TextStyleChanger()
        {
            try
            {
                var dir = Path.GetDirectoryName(GetType().Assembly.Location);
                Tagger = Tagger <WNode> .Create(() => new WNode(), Path.Combine(dir, "UniDic-CWJ"));

                Changer  = new LanguageStyleChanger(Tagger);
                Combiner = new TokenCombiner <WNode>(n => n.Surface, n => n.RLength != n.Length);
            }
            catch (Exception)
            {
                Tagger?.Dispose();
                throw;
            }
        }
Exemple #4
0
 public string Combine(IEnumerable <TToken> tokens)
 {
     return(TokenCombiner.Combine(tokens, CombineMode, Space, Renderer, Spacer, Postprocess));
 }