Exemplo n.º 1
0
 public IPatternUnit WithSuffix(string suffix, bool ignoreCase = false)
 {
     Type         |= PatternUnitType.Suffix;
     Suffix        = suffix;
     CaseSensitive = !ignoreCase;
     return(this);
 }
Exemplo n.º 2
0
 public IPatternUnit WithPrefix(string prefix, bool ignoreCase = false)
 {
     Type         |= PatternUnitType.Prefix;
     Prefix        = prefix;
     CaseSensitive = !ignoreCase;
     return(this);
 }
Exemplo n.º 3
0
 public IPatternUnit WithLength(int minLength, int maxLength)
 {
     Type     |= PatternUnitType.Length;
     MinLength = minLength;
     MaxLength = maxLength;
     return(this);
 }
Exemplo n.º 4
0
 public IPatternUnit WithToken(string token, bool ignoreCase = false)
 {
     Type         |= PatternUnitType.Token;
     Token         = token;
     CaseSensitive = !ignoreCase;
     TokenHash     = ignoreCase ? IgnoreCaseHash64(token.AsSpan()) : Hash64(token.AsSpan());
     return(this);
 }
Exemplo n.º 5
0
 public IPatternUnit WithTokens(IEnumerable <string> tokens, bool ignoreCase = false)
 {
     if (tokens.Count() == 1)
     {
         return(WithToken(tokens.First(), ignoreCase));
     }
     Type         |= PatternUnitType.Set;
     Set           = new HashSet <string>(tokens);
     CaseSensitive = !ignoreCase;
     SetHashes     = new HashSet <ulong>(tokens.Select(tk => ignoreCase ? IgnoreCaseHash64(tk.AsSpan()) : Hash64(tk.AsSpan())));
     return(this);
 }
Exemplo n.º 6
0
 public PatternUnit(PatternMatchingMode mode, bool optional, bool caseSensitive, PatternUnitType type, PartOfSpeech[] pos, string suffix, string prefix, string shape, string token, HashSet <string> set, string entityType, HashSet <ulong> setHashes, ulong tokenHash, PatternUnit leftSide, PatternUnit rightSide)
 {
     Mode          = mode;
     Optional      = optional;
     CaseSensitive = caseSensitive;
     Type          = type;
     POS           = pos;
     Suffix        = suffix;
     Prefix        = prefix;
     Shape         = shape?.AsSpan().Shape(false);
     Token         = token;
     Set           = set;
     EntityType    = entityType;
     SetHashes     = setHashes ?? (set is null ? null : new HashSet <ulong>(set.Select(tk => CaseSensitive ? PatternUnitPrototype.Hash64(tk.AsSpan()) : PatternUnitPrototype.IgnoreCaseHash64(tk.AsSpan()))));
     TokenHash     = tokenHash;
     LeftSide      = leftSide;
     RightSide     = rightSide;
 }
Exemplo n.º 7
0
        public PatternUnit(PatternMatchingMode mode, bool optional, bool caseSensitive, PatternUnitType type, PartOfSpeech[] pos, string suffix, string prefix, string shape, string token, HashSet <string> set, string entityType, HashSet <ulong> setHashes, ulong tokenHash, PatternUnit leftSide, PatternUnit rightSide)
        {
            Mode          = mode;
            Optional      = optional;
            CaseSensitive = caseSensitive;
            Type          = type;
            POS           = pos;
            Suffix        = suffix;
            Prefix        = prefix;
            Shape         = shape?.AsSpan().Shape(false);
            Token         = token;
            Set           = set;
            EntityType    = entityType;
            SetHashes     = setHashes ?? (set is null ? null : new HashSet <ulong>(set.Select(tk => CaseSensitive ? PatternUnitPrototype.Hash64(tk.AsSpan()) : PatternUnitPrototype.IgnoreCaseHash64(tk.AsSpan()))));
            TokenHash     = tokenHash;
            LeftSide      = leftSide;
            RightSide     = rightSide;

            _splitSuffix     = Suffix?.Split(splitCharWithWhitespaces, StringSplitOptions.RemoveEmptyEntries)?.Distinct()?.ToArray();
            _splitPrefix     = Prefix?.Split(splitCharWithWhitespaces, StringSplitOptions.RemoveEmptyEntries)?.Distinct()?.ToArray();
            _splitEntityType = EntityType is object?new HashSet <string>(EntityType.Split(splitChar, StringSplitOptions.RemoveEmptyEntries)) : null;
            _splitShape      = Shape is object?new HashSet <string>(Shape.Split(splitCharWithWhitespaces, StringSplitOptions.RemoveEmptyEntries)) : null;
        }
Exemplo n.º 8
0
        public PatternUnit(IPatternUnit prototype)
        {
            var p = (PatternUnitPrototype)prototype;

            Mode          = p.Mode;
            Optional      = p.Optional;
            CaseSensitive = p.CaseSensitive;
            Type          = p.Type;
            POS           = p.POS;
            Suffix        = p.Suffix;
            Prefix        = p.Prefix;
            Shape         = p.Shape;
            Token         = p.Token;
            Set           = p.Set;
            EntityType    = p.EntityType;
            SetHashes     = p.SetHashes ?? (p.Set is null ? null : new HashSet <ulong>(p.Set.Select(token => p.CaseSensitive ? PatternUnitPrototype.Hash64(token.AsSpan()) : PatternUnitPrototype.IgnoreCaseHash64(token.AsSpan()))));
            TokenHash     = p.TokenHash;
            LeftSide      = p.LeftSide is object?new PatternUnit(p.LeftSide) : null;
            RightSide     = p.RightSide is object?new PatternUnit(p.RightSide) : null;
            ValidChars    = p.ValidChars;
            MinLength     = p.MinLength;
            MaxLength     = p.MaxLength;
        }
Exemplo n.º 9
0
 public IPatternUnit LikeEmail()
 {
     Type |= PatternUnitType.LikeEmail; return(this);
 }
Exemplo n.º 10
0
 public IPatternUnit IsClosingParenthesis()
 {
     Type |= PatternUnitType.IsClosingParenthesis; return(this);
 }
Exemplo n.º 11
0
 public IPatternUnit IsTitleCase()
 {
     Type |= PatternUnitType.IsTitleCase; return(this);
 }
Exemplo n.º 12
0
 public IPatternUnit LikeURL()
 {
     Type |= PatternUnitType.LikeURL; return(this);
 }
Exemplo n.º 13
0
 public IPatternUnit IsPunctuation()
 {
     Type |= PatternUnitType.IsPunctuation; return(this);
 }
Exemplo n.º 14
0
 public IPatternUnit IsUpperCase()
 {
     Type |= PatternUnitType.IsUpperCase; return(this);
 }
Exemplo n.º 15
0
 public IPatternUnit IsLetterOrDigit()
 {
     Type |= PatternUnitType.IsLetterOrDigit; return(this);
 }
Exemplo n.º 16
0
 public IPatternUnit IsEmoji()
 {
     Type |= PatternUnitType.IsEmoji; return(this);
 }
Exemplo n.º 17
0
 public IPatternUnit IsAlpha()
 {
     Type |= PatternUnitType.IsAlpha; return(this);
 }
Exemplo n.º 18
0
 public IPatternUnit HasNumeric()
 {
     Type |= PatternUnitType.HasNumeric; return(this);
 }
Exemplo n.º 19
0
 public IPatternUnit WithPOS(params PartOfSpeech[] pos)
 {
     Type |= pos.Length > 1 ? PatternUnitType.MultiplePOS : PatternUnitType.POS;
     POS   = pos;
     return(this);
 }
Exemplo n.º 20
0
 public IPatternUnit WithShape(string shape)
 {
     Type |= PatternUnitType.Shape;
     Shape = shape.AsSpan().Shape(false);
     return(this);
 }
Exemplo n.º 21
0
 public IPatternUnit WithoutEntityType(string entityType)
 {
     Type      |= PatternUnitType.NotEntity;
     EntityType = entityType;
     return(this);
 }