Ejemplo n.º 1
0
        private IList <ISingleFilter> GetFilters()
        {
            var filters = new List <ISingleFilter>();

            if (filterEnglish)
            {
                filters.Add(new EnglishFilter());
            }
            var lenFilter = new LengthFilter();

            if (ignoreSingleWord)
            {
                lenFilter.MinLength = 2;
            }
            if (ignoreLongWord)
            {
                lenFilter.MaxLength = ignoreWordLength;
            }
            if (ignoreSingleWord || ignoreLongWord)
            {
                filters.Add(lenFilter);
            }
            if (filterSpaceWord)
            {
                filters.Add(new SpaceFilter());
            }
            return(filters);
        }
Ejemplo n.º 2
0
        public void IsCharacterOverwritingEnabled_Default_ReturnsFalse()
        {
            var obj = new LengthFilter(0);

            var result = obj.IsCharacterOverwritingEnabled;

            Assert.False(result);
        }
Ejemplo n.º 3
0
        public void Removes_Words_Equal_To_Two_Characters()
        {
            var text = "XY";

            var filter = new LengthFilter(2);

            var result = filter.Execute(text).Trim();

            Assert.Equal(string.Empty, result);
        }
Ejemplo n.º 4
0
        public void Ignores_Words_Greater_Than_Two_Characters()
        {
            var text = "XYZ";

            var filter = new LengthFilter(2);

            var result = filter.Execute(text).Trim();

            Assert.Equal(text, result);
        }
Ejemplo n.º 5
0
        public void ShouldChangeText_NullResponderWithCharacterOverwritingEnabled_ReturnsExpected()
        {
            var range  = new NSRange(2, 0);
            var filter = new LengthFilter(0);

            filter.IsCharacterOverwritingEnabled = true;
            var result = filter.ShouldChangeText(null !, "old", range, "new");

            Assert.False(result);
        }
Ejemplo n.º 6
0
        private IList <ISingleFilter> GetFilters()
        {
            var filters = new List <ISingleFilter>();

            if (filterConfig.NoFilter)
            {
                return(filters);
            }
            if (filterConfig.IgnoreEnglish)
            {
                filters.Add(new EnglishFilter());
            }
            if (filterConfig.IgnoreFirstCJK)
            {
                filters.Add(new FirstCJKFilter());
            }
            var lenFilter = new LengthFilter();

            lenFilter.MinLength = filterConfig.WordLengthFrom;
            lenFilter.MaxLength = filterConfig.WordLengthTo;

            if (filterConfig.WordLengthFrom > 1 || filterConfig.WordLengthTo < 9999)
            {
                filters.Add(lenFilter);
            }
            var rankFilter = new RankFilter();

            rankFilter.MaxLength = filterConfig.WordRankTo;
            rankFilter.MinLength = filterConfig.WordRankFrom;
            if (filterConfig.WordRankFrom > 1 || filterConfig.WordRankTo < 999999)
            {
                filters.Add(rankFilter);
            }
            if (filterConfig.IgnoreSpace)
            {
                filters.Add(new SpaceFilter());
            }
            if (filterConfig.IgnorePunctuation)
            {
                filters.Add(new ChinesePunctuationFilter());
                filters.Add(new EnglishPunctuationFilter());
            }
            if (filterConfig.IgnoreNumber)
            {
                filters.Add(new NumberFilter());
            }
            if (filterConfig.IgnoreNoAlphabetCode)
            {
                filters.Add(new NoAlphabetCodeFilter());
            }
            return(filters);
        }
Ejemplo n.º 7
0
        public async Task ShouldChangeText_InvalidRange_ThrowsArgumentOutOfRangeException()
        {
            var result = Helpers.RunOnUIThreadAsync(() =>
            {
                var textField = new UITextField();
                var filter    = new LengthFilter(0);

                var range = new NSRange(0, 1000);
                return(filter.ShouldChangeText(textField, "old", range, "new"));
            });

            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => result);
        }
Ejemplo n.º 8
0
 private List <Action> GenerateTasksFromDirectory(DirectoryInfo directory, string solverDir, Func <ISolver> solverMaker)
 {
     return(directory.GetFiles().Where(d => LengthFilter == null || LengthFilter.Contains(d.Name)).SelectMany(file =>
     {
         List <Action> tasks = new List <Action>();
         for (int i = FirstNumber; i < FirstNumber + Times; i++)
         {
             var solver = solverMaker();
             int seed = (int)(((long)solver.Seed + Random.Next()) % int.MaxValue);
             string solutionName = Path.Combine(SolutionsDirectory, solver.Description, solverDir, $"{i}{file.Name}");
             tasks.Add(GenerateSolveTask(file.FullName, solutionName, solverMaker, seed));
         }
         return tasks;
     }).ToList());
 }
Ejemplo n.º 9
0
        public async Task ShouldChangeText_UITextField_ReturnsExpected(
            string oldText,
            int insertPosition,
            string newText,
            int maxLength,
            bool expectedResult)
        {
            var result = await Helpers.RunOnUIThreadAsync(() =>
            {
                var textField = new UITextField();
                var range     = new NSRange(insertPosition, 0);
                var filter    = new LengthFilter(maxLength);

                return(filter.ShouldChangeText(textField, oldText, range, newText));
            });

            Assert.Equal(expectedResult, result);
        }
Ejemplo n.º 10
0
        public static ArrayList removePunctuation(String inputString)
        {
            StringReader reader            = new StringReader(inputString);
            Tokenizer    standardTokenizer = new LetterTokenizer(reader);

            TokenStream tokenStream   = new LengthFilter(standardTokenizer, 2, int.MaxValue);
            var         termAttribute = tokenStream.GetAttribute <ITermAttribute>();

            tokenStream.Reset();

            ArrayList tokenizedString = new ArrayList();

            while (tokenStream.IncrementToken())
            {
                tokenizedString.Add(termAttribute.Term);
            }

            tokenStream.End();
            tokenStream.Dispose();

            return(tokenizedString);
        }
Ejemplo n.º 11
0
        public static ArrayList defaultSplit(String inputString)
        {
            StringReader reader = new StringReader(inputString);
            Tokenizer    whiteSpaceTokenizer = new WhitespaceTokenizer(reader);

            TokenStream tokenStream   = new LengthFilter(whiteSpaceTokenizer, 2, int.MaxValue);
            var         termAttribute = tokenStream.GetAttribute <ITermAttribute>();

            tokenStream.Reset();

            ArrayList tokenizedString = new ArrayList();

            while (tokenStream.IncrementToken())
            {
                tokenizedString.Add(termAttribute.Term);
            }

            tokenStream.End();
            tokenStream.Dispose();

            return(tokenizedString);
        }
Ejemplo n.º 12
0
        public async Task ShouldChangeText_UITextFieldWithCharacterOverwritingEnabled_ReturnsExpected(
            string oldText,
            int insertPosition,
            string newText,
            int maxLength,
            string expectedResult)
        {
            var result = await Helpers.RunOnUIThreadAsync(() =>
            {
                var textField = new UITextField {
                    Text = oldText
                };
                var range  = new NSRange(insertPosition, 0);
                var filter = new LengthFilter(maxLength);

                filter.IsCharacterOverwritingEnabled = true;
                filter.ShouldChangeText(textField, oldText, range, newText);

                return(textField.Text);
            });

            Assert.Equal(expectedResult, result);
        }
Ejemplo n.º 13
0
        private CommandType RunCommand(string command)
        {
            if (command == "--help" || command == "-?")
            {
                showHelp(this.cbxImportItems);
                return(CommandType.Help);
            }
            if (command == "--version" || command == "-v")
            {
                Console.WriteLine("Version:" + Assembly.GetExecutingAssembly().GetName().Version);
                return(CommandType.Help);
            }
            if (command.StartsWith("-i:"))
            {
                wordLibraryImport = GetImportInterface(command.Substring(3));
                beginImportFile   = true;
                return(CommandType.Import);
            }

            if (command.StartsWith("-o:"))
            {
                wordLibraryExport = GetExportInterface(command.Substring(3));
                beginImportFile   = false;
                return(CommandType.Export);
            }
            if (command.StartsWith("-c:")) //code
            {
                codingFile = command.Substring(3);
                pattern.MappingTablePath = codingFile;
                pattern.IsPinyinFormat   = false;
                beginImportFile          = false;
                return(CommandType.Coding);
            }
            if (command.StartsWith("-ft:")) //filter
            {
                var   filterStrs = command.Substring(4);
                Regex lenRegex   = new Regex(@"len:(\d+)-(\d+)");
                Regex rankRegex  = new Regex(@"rank:(\d+)-(\d+)");
                Regex rmRegex    = new Regex(@"rm:(\w+)");
                foreach (var filterStr in filterStrs.Split('|'))
                {
                    if (lenRegex.IsMatch(filterStr))
                    {
                        var match        = lenRegex.Match(filterStr);
                        var from         = Convert.ToInt32(match.Groups[1].Value);
                        var to           = Convert.ToInt32(match.Groups[2].Value);
                        var numberFilter = new LengthFilter()
                        {
                            MinLength = from, MaxLength = to
                        };
                        this.filters.Add(numberFilter);
                    }
                    else if (rankRegex.IsMatch(filterStr))
                    {
                        var match   = rankRegex.Match(filterStr);
                        var from    = Convert.ToInt32(match.Groups[1].Value);
                        var to      = Convert.ToInt32(match.Groups[2].Value);
                        var rFilter = new RankFilter()
                        {
                            MinLength = from, MaxLength = to
                        };
                        this.filters.Add(rFilter);
                    }
                    else if (rmRegex.IsMatch(filterStr))
                    {
                        var           match  = rmRegex.Match(filterStr);
                        var           rmType = match.Groups[1].Value;
                        ISingleFilter filter;
                        switch (rmType)
                        {
                        case "eng": filter = new EnglishFilter(); break;

                        case "num": filter = new NumberFilter(); break;

                        case "space": filter = new SpaceFilter(); break;

                        case "pun": filter = new EnglishPunctuationFilter(); break;

                        default: throw new ArgumentException("Unsupport filter type:" + rmType);
                        }
                        this.filters.Add(filter);
                    }
                }
                return(CommandType.Coding);
            }
            if (command.StartsWith("-ct:")) //code type
            {
                var codeType = command.Substring(4).ToLower();
                switch (codeType)
                {
                case "pinyin": pattern.CodeType = CodeType.Pinyin; break;

                case "wubi": pattern.CodeType = CodeType.Wubi; break;

                case "zhengma": pattern.CodeType = CodeType.Zhengma; break;

                case "cangjie": pattern.CodeType = CodeType.Cangjie; break;

                case "zhuyin": pattern.CodeType = CodeType.TerraPinyin; break;

                default: pattern.CodeType = CodeType.Pinyin; break;
                }
                return(CommandType.CodeType);
            }
            if (command.StartsWith("-r:")) //Rank
            {
                var rankType = command.Substring(3).ToLower();
                switch (rankType)
                {
                case "baidu": this.wordRankGenerater = new BaiduWordRankGenerater(); break;

                case "google": this.wordRankGenerater = new GoogleWordRankGenerater(); break;

                default: {
                    var rankNumber = Convert.ToInt32(rankType);
                    var gen        = new DefaultWordRankGenerater();
                    gen.ForceUse           = true;
                    gen.Rank               = rankNumber;
                    this.wordRankGenerater = gen;
                } break;
                }
                return(CommandType.CodeType);
            }
            if (command.StartsWith("-os:")) //code type
            {
                var os = command.Substring(4).ToLower();
                switch (os)
                {
                case "windows": pattern.OS = OperationSystem.Windows; break;

                case "mac":
                case "macos": pattern.OS = OperationSystem.MacOS; break;

                case "linux":
                case "unix": pattern.OS = OperationSystem.Linux; break;

                default: pattern.OS = OperationSystem.Windows; break;
                }
                return(CommandType.OS);
            }
            if (command.StartsWith("-ld2:")) //ld2 encoding
            {
                string   ecodes = command.Substring(5);
                string[] arr    = ecodes.Split(',');

                wordEncoding = Encoding.GetEncoding(arr[0]);
                if (arr.Length > 1)
                {
                    xmlEncoding = Encoding.GetEncoding(arr[1]);
                }

                return(CommandType.Encoding);
            }
            if (command.StartsWith("-f:")) //format
            {
                format          = command.Substring(3);
                beginImportFile = false;
                var sort = new List <int>();
                for (int i = 0; i < 3; i++)
                {
                    char c = format[i];
                    sort.Add(Convert.ToInt32(c));
                }
                pattern.Sort            = sort;
                pattern.CodeSplitString = format[3].ToString();
                pattern.SplitString     = format[4].ToString();
                string t = format[5].ToString().ToLower();
                beginImportFile = false;
                if (t == "l")
                {
                    pattern.CodeSplitType = BuildType.LeftContain;
                }
                if (t == "r")
                {
                    pattern.CodeSplitType = BuildType.RightContain;
                }
                if (t == "b")
                {
                    pattern.CodeSplitType = BuildType.FullContain;
                }
                if (t == "n")
                {
                    pattern.CodeSplitType = BuildType.None;
                }
                pattern.ContainCode = (format[6].ToString().ToLower() == "y");
                pattern.ContainRank = (format[8].ToString().ToLower() == "y");
                return(CommandType.Format);
            }

            if (beginImportFile)
            {
                importPaths.AddRange(FileOperationHelper.GetFilesPath(command));
            }
            if (type == CommandType.Export)
            {
                exportPath = command;
            }
            return(CommandType.Other);
        }
Ejemplo n.º 14
0
        private void UpdatePropertiesPanel(XmlNode selectedItem)
        {
            if (selectedItem.Name == "input")
            {
                switch (selectedItem.Attributes["type"].Value)
                {
                case "MSMQ":
                    MyGrid = new MSMQIN(selectedItem, this.View);
                    break;

                case "MQ":
                    MyGrid = new MQIN(selectedItem, this.View);
                    break;

                case "FILE":
                    MyGrid = new FILEIN(selectedItem, this.View);
                    break;

                case "KAFKA":
                    MyGrid = new KAFKAIN(selectedItem, this.View);
                    break;

                case "HTTP":
                    MyGrid = new HTTPIN(selectedItem, this.View);
                    break;

                case "RABBITDEFEX":
                    MyGrid = new RABBITIN(selectedItem, this.View);
                    break;

                case "MQTT":
                    MyGrid = new MQTTIN(selectedItem, this.View);
                    break;

                case "TCPSERVER":
                    MyGrid = new TCPIN(selectedItem, this.View);
                    break;

                case "TESTSOURCE":
                    MyGrid = new TESTSOURCE(selectedItem, this.View);
                    break;
                }
            }
            else if (selectedItem.Name == "output" || selectedItem.Name == "altqueue")
            {
                switch (selectedItem.Attributes["type"].Value)
                {
                case "MSMQ":
                    MyGrid = new MSMQOUT(selectedItem, this.View);
                    break;

                case "MQ":
                    MyGrid = new MQOUT(selectedItem, this.View);
                    break;

                case "FILE":
                    MyGrid = new FILEOUT(selectedItem, this.View);
                    break;

                case "KAFKA":
                    MyGrid = new KAFKAOUT(selectedItem, this.View);
                    break;

                case "REST":
                    MyGrid = new RESTOUT(selectedItem, this.View);
                    break;

                case "HTTP":
                    MyGrid = new HTTPOUT(selectedItem, this.View);
                    break;

                case "TCPCLIENT":
                    MyGrid = new TCPOUT(selectedItem, this.View);
                    break;

                case "RABBITDEFEX":
                    MyGrid = new RABBITOUT(selectedItem, this.View);
                    break;

                case "MQTT":
                    MyGrid = new MQTTIN(selectedItem, this.View);
                    break;

                case "SMTP":
                    MyGrid = new SMTPOut(selectedItem, this.View);
                    break;

                case "FTP":
                    MyGrid = new FTPOut(selectedItem, this.View);
                    break;

                case "SINK":
                    MyGrid = new SINK(selectedItem, this.View);
                    break;
                }
            }
            else if (selectedItem.Name == "monitor")
            {
                MyGrid = new MonitorGrid(selectedItem, this.View);
            }
            else if (selectedItem.Name == "filter")
            {
                MyGrid = new Filter(selectedItem, this.View);
            }
            else if (selectedItem.Name == "pipe")
            {
                MyGrid = new PIPE(selectedItem, this.View);
            }
            else if (selectedItem.Name == "namespace")
            {
                MyGrid = new NameSpaceGrid(selectedItem, this.View);
            }
            else if (selectedItem.Name == "service")
            {
                MyGrid = new ServiceSetting(selectedItem, this.View);
            }
            else if (selectedItem.Name == "and" || selectedItem.Name == "or" || selectedItem.Name == "xor" || selectedItem.Name == "not")
            {
                MyGrid = new BooleanExpression(selectedItem, this.View);
            }
            else if (selectedItem.Name == "contains")
            {
                MyGrid = new ContainsFilter(selectedItem, this.View);
            }
            else if (selectedItem.Name == "equals")
            {
                MyGrid = new EqualsFilter(selectedItem, this.View);
            }
            else if (selectedItem.Name == "matches")
            {
                MyGrid = new MatchesFilter(selectedItem, this.View);
            }
            else if (selectedItem.Name == "length")
            {
                MyGrid = new LengthFilter(selectedItem, this.View);
            }
            else if (selectedItem.Name == "xpexists")
            {
                MyGrid = new XPExistsFilter(selectedItem, this.View);
            }
            else if (selectedItem.Name == "xpmatches")
            {
                MyGrid = new XPMatchesFilter(selectedItem, this.View);
            }
            else if (selectedItem.Name == "xpequals")
            {
                MyGrid = new XPEqualsFilter(selectedItem, this.View);
            }
            else if (selectedItem.Name == "dateRange")
            {
                MyGrid = new DateRangeFilter(selectedItem, this.View);
            }
            else if (selectedItem.Name == "contextContains")
            {
                MyGrid = new ContextFilter(selectedItem, this.View);
            }

            OnPropertyChanged("MyGrid");
        }
Ejemplo n.º 15
0
        public void Ctor_Positive_ReturnsITextFilter(int maxLength)
        {
            var obj = new LengthFilter(maxLength);

            Assert.IsAssignableFrom <ITextFilter>(obj);
        }