public IPatternUnit WithSuffix(string suffix, bool ignoreCase = false) { Type |= PatternUnitType.Suffix; Suffix = suffix; CaseSensitive = !ignoreCase; return(this); }
public IPatternUnit WithPrefix(string prefix, bool ignoreCase = false) { Type |= PatternUnitType.Prefix; Prefix = prefix; CaseSensitive = !ignoreCase; return(this); }
public IPatternUnit WithLength(int minLength, int maxLength) { Type |= PatternUnitType.Length; MinLength = minLength; MaxLength = maxLength; return(this); }
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); }
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); }
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; }
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; }
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; }
public IPatternUnit LikeEmail() { Type |= PatternUnitType.LikeEmail; return(this); }
public IPatternUnit IsClosingParenthesis() { Type |= PatternUnitType.IsClosingParenthesis; return(this); }
public IPatternUnit IsTitleCase() { Type |= PatternUnitType.IsTitleCase; return(this); }
public IPatternUnit LikeURL() { Type |= PatternUnitType.LikeURL; return(this); }
public IPatternUnit IsPunctuation() { Type |= PatternUnitType.IsPunctuation; return(this); }
public IPatternUnit IsUpperCase() { Type |= PatternUnitType.IsUpperCase; return(this); }
public IPatternUnit IsLetterOrDigit() { Type |= PatternUnitType.IsLetterOrDigit; return(this); }
public IPatternUnit IsEmoji() { Type |= PatternUnitType.IsEmoji; return(this); }
public IPatternUnit IsAlpha() { Type |= PatternUnitType.IsAlpha; return(this); }
public IPatternUnit HasNumeric() { Type |= PatternUnitType.HasNumeric; return(this); }
public IPatternUnit WithPOS(params PartOfSpeech[] pos) { Type |= pos.Length > 1 ? PatternUnitType.MultiplePOS : PatternUnitType.POS; POS = pos; return(this); }
public IPatternUnit WithShape(string shape) { Type |= PatternUnitType.Shape; Shape = shape.AsSpan().Shape(false); return(this); }
public IPatternUnit WithoutEntityType(string entityType) { Type |= PatternUnitType.NotEntity; EntityType = entityType; return(this); }