private List <Audio> GetStorageFiles(Options options) { var parts = options.Source.Replace("gs://", "").Split('/'); if (parts.Length < 2) { return(new List <Audio>()); } string bucket = $"{string.Join('/', parts.Take(parts.Length - 1))}"; string name = parts[parts.Length - 1]; if (!name.Contains("*")) { return new List <Audio> { new Audio(options.Source, GetOutputFile(options, name), RecognitionAudio.FromStorageUri(options.Source)) } } ; var storageClient = StorageClient.Create(GoogleCredential.FromFile(options.KeyPath)); string[] fileNames = storageClient.ListObjects(bucket).Select(f => f.Name).ToArray(); WildCard wildCard = new WildCard(name, RegexOptions.IgnoreCase); return(fileNames .Where(fileName => !fileName.EndsWith("/") && wildCard.IsMatch(fileName)) .Select(fileName => { string source = $"gs://{bucket}/{fileName}"; return new Audio(source, GetOutputFile(options, fileName), RecognitionAudio.FromStorageUri(source)); }).ToList()); }
/// <summary> /// 対象ファイルを名前で絞り込むフィルターを作成します。 /// </summary> /// <returns>ファイル名で絞り込む処理</returns> public Func <string, bool> CreateFileFilter() { Func <string, bool> inclusionFilter; if (string.IsNullOrWhiteSpace(InclusionFilePattern)) { inclusionFilter = name => true; } else { var wildCard = new WildCard(InclusionFilePattern, WildCardOptions.MultiPattern); inclusionFilter = wildCard.IsMatch; } Func <string, bool> exclusionFilter; if (string.IsNullOrWhiteSpace(ExclusionFilePattern)) { exclusionFilter = name => false; } else { var wildCard = new WildCard(ExclusionFilePattern, WildCardOptions.MultiPattern); exclusionFilter = wildCard.IsMatch; } return(name => exclusionFilter(name) == false && inclusionFilter(name)); }
private bool AssertEqual(FindAction findElementAction, string x, string y) { bool result = false; if (string.IsNullOrEmpty(x) || string.IsNullOrEmpty(y)) { return(result); } if (findElementAction.Trim) { x = x.Trim(); } if (findElementAction.Contains) { result = x.Contains(y); } else if (findElementAction.WildCard) { result = WildCard.Test(y, x); } else { result = x == y; } return(result); }
public void CleanPatternTest() { Assert.AreEqual("ааа*фф*ф", WildCard.CleanPattern("ааа****фф**ф")); Assert.AreEqual("а*б*в", WildCard.CleanPattern("а*б*в")); Assert.AreEqual("при*вет*мир*", WildCard.CleanPattern("при***вет***мир***")); Assert.AreEqual("*бон*жур*", WildCard.CleanPattern("****бон**жур**")); }
private void LoadRegexMatchExpression(StringComparisonType stringComparisonType) { //for a string the comparison type should always be contains, startswith, endswith etc are not supported in this class if (stringComparisonType == StringComparisonType.Contains || stringComparisonType == StringComparisonType.NotContains) { //stringcomparisonType denotes items that are compatible with the contains function in c# for this class it means //that we are comparing the property on the left with a regex match call on the right if (_caseSensitive) { //default behaviour of .net is to do it case sensitive match _wildCard = new WildCard(_originalValueToCompare); _patternToMatch = _wildCard.WildcardToRegex(_originalValueToCompare); } else { //only if specified will it do a case insensitive match _wildCard = new WildCard(_originalValueToCompare, RegexOptions.IgnoreCase); _patternToMatch = _wildCard.WildcardToRegex(_originalValueToCompare.ToLower()); } BuildRegexMatchMethodInvokeExpression(); } else { throw new ApplicationException("Wildcard search is not supported for any string compare types other than Contains or No Contains"); } }
internal XElement ExecuteFSM(IEnumerator<XElement> enumerator, XName requestingXName, WildCard requestingWildCard) { XElement currElem = null; WildCard matchingWildCard = null; XName matchingName = null; while(enumerator.MoveNext()){ currElem = enumerator.Current; currentState = FsmMakeTransition(currentState, currElem.Name, out matchingName, out matchingWildCard); if (currentState!= FSM.InvalidState) { if ( (requestingXName != null) && (matchingName != null)) { if (requestingXName.Equals(currElem.Name)) return currElem; } else if ( (requestingWildCard != null) && (matchingWildCard != null) ){//requesting for ANY if (requestingWildCard.Allows(currElem.Name)) //Make sure current element is allowed by requesting ANY property return currElem; } } else {//Get stuck. No recovery attempt is provided for now. return null; } } //No matching elements/wildcards are found return null; }
internal static CodeExpression CreateWildCardExpr(WildCard any) { return(new CodeObjectCreateExpression( Constants.WildCard, new CodeExpression[] { new CodePrimitiveExpression(any.NsList.Namespaces), new CodePrimitiveExpression(any.NsList.TargetNamespace) } )); }
public HttpResponseMessage Get(string report) { //Get all area List <WildCard> lstWildCard = WildCard.getWCOptions(report); var jsonNew = new { result = lstWildCard }; return(Request.CreateResponse(HttpStatusCode.OK, jsonNew)); }
public void MatchTest() { Assert.IsTrue(WildCard.Match("пост", "по?т")); Assert.IsTrue(WildCard.Match("порт", "по?т")); Assert.IsFalse(WildCard.Match("пот", "по?т")); Assert.IsTrue(WildCard.Match("здравый", "здрав*й*")); Assert.IsTrue(WildCard.Match("здравствуй", "здрав*й*")); Assert.IsTrue(WildCard.Match("здравствуйте", "здрав*й*")); Assert.IsFalse(WildCard.Match("здравие", "здрав*й*")); }
public IEnumerable <string> SearchWords(string pattern) { List <string> newWords = new List <string>(); foreach (string word in _words) { if (WildCard.Match(word, pattern)) { newWords.Add(word); } } return(newWords); }
protected override void PrivateHandle(UserInfo info, List <string> args) { IEnumerable <UserPerChannelInfo> whoList; var filterInvisible = true; if (!info.PassAccepted) { IrcDaemon.Replies.SendPasswordMismatch(info); return; } ChannelInfo channel; var mask = string.Empty; if (args.Count < 1 || args[0] == "0") { whoList = IrcDaemon.Nicks.SelectMany(n => n.Value.UserPerChannelInfos); } else if (args.Count > 0 && IrcDaemon.Channels.TryGetValue(args[0], out channel)) { whoList = channel.UserPerChannelInfos.Values; if (!channel.UserPerChannelInfos.ContainsKey(info.Nick)) { filterInvisible = false; } } else { mask = args[0]; var wildCard = new WildCard(mask, WildcardMatch.Anywhere); whoList = IrcDaemon.Nicks.Values.Where(u => wildCard.IsMatch(u.Usermask)).SelectMany(n => n.UserPerChannelInfos); } if (filterInvisible) { whoList = whoList.Where(w => !w.UserInfo.Modes.Exist <ModeInvisible>()); } if (args.Count > 1 && args[1] == "o") { whoList = whoList.Where(w => w.UserInfo.Modes.Exist <ModeOperator>() || w.UserInfo.Modes.Exist <ModeLocalOperator>()); } foreach (var who in whoList) { IrcDaemon.Replies.SendWhoReply(info, who); } IrcDaemon.Replies.SendEndOfWho(info, mask); }
public HttpResponseMessage GetByChar(String wildCardType, String companyId, String divisionId, String keyStrokes) { /* Dictionary<string, string> listType = WildCard.getAllEntires(Convert.ToInt32(wildCardType),companyId,divisionId,keyStrokes); * var jsonSerialiser = new JavaScriptSerializer(); * jsonSerialiser.MaxJsonLength = int.MaxValue; * var json = jsonSerialiser.Serialize(listType); * return json;*/ var jsonNew = new { result = WildCard.getAllEntiresList(Convert.ToInt32(wildCardType), companyId, divisionId, keyStrokes) }; return(Request.CreateResponse(HttpStatusCode.OK, jsonNew)); }
public HttpResponseMessage Get(string report, string keyStroke) { //Get all area List <WildCard> lstWildCard = WildCard.getWCOptions(report); List <WildCard> lstFilteredWildCard = new List <WildCard>(); for (int i = 0; i < lstWildCard.Count; i++) { if (lstWildCard[i].value.ToLower().Contains(keyStroke.ToLower())) // (you use the word "contains". either equals or indexof might be appropriate) { lstFilteredWildCard.Add(lstWildCard[i]); } } var jsonNew = new { result = lstFilteredWildCard }; return(Request.CreateResponse(HttpStatusCode.OK, jsonNew)); }
public static string ToSymbolString(this WildCard wildCard) { var returnValue = string.Empty; switch (wildCard) { case WildCard.Asterick: { returnValue = "*"; break; } default: { returnValue = "?"; break; } } return(returnValue); }
/// <summary>Constructs the <see cref="SearchInfo"/> enumerable.</summary> /// /// <param name="path"> /// The relative or absolute path to the directory to search. This string is not case-sensitive. /// </param> /// <param name="searchPattern"> /// The search string to match against file-system entries in path. This parameter can contain a /// combination of valid literal path and wildcard (* and ?) characters (see Remarks), but doesn't /// support regular expressions. /// </param> /// <param name="files">True if files are returned.</param> /// <param name="subdirs">True if directories are returned.</param> /// <param name="searchOrder">How subdirectories should be searched, if at all.</param> /// <param name="ignoreCase">True if pattern casing should be ignored.</param> public SearchInfo(string path, string searchPattern, bool files, bool subdirs, SearchOrder searchOrder, bool ignoreCase) { if (!Enum.IsDefined(typeof(SearchOrder), searchOrder)) { throw new ArgumentException(nameof(searchOrder)); } if (!files && !subdirs) { throw new ArgumentException($"{nameof(files)} or {nameof(subdirs)} must be true!"); } if (searchOrder == SearchOrder.AllSubdirectories && searchPattern != "*") { throw new ArgumentException($"{nameof(SearchOrder.AllSubdirectories)} can only be " + $"used when a search pattern of '*'!"); } if (!PathUtils.IsValidNamePattern(searchPattern)) { throw new ArgumentException($"{nameof(searchPattern)} is not a valid wildcard pattern!"); } Path = path; SearchPattern = searchPattern; Files = files; Subdirs = subdirs; SearchOrder = searchOrder; IgnoreCase = ignoreCase; if (searchPattern != "*" && (searchOrder != SearchOrder.TopDirectoryOnly || !ignoreCase)) { Regex = WildCard.ToRegex(SearchPattern, ignoreCase); } else { Regex = null; } IsCustomRegex = false; }
public LikeCompiler(ISqlCompiler firstParameter, WildCard token = WildCard.Both) { _Token = token; _FirstParameter = firstParameter; }
internal static CodeExpression CreateWildCardExpr(WildCard any) { CodeExpression[] codePrimitiveExpression = new CodeExpression[] { new CodePrimitiveExpression(any.NsList.Namespaces), new CodePrimitiveExpression(any.NsList.TargetNamespace) }; return(new CodeObjectCreateExpression("WildCard", codePrimitiveExpression)); }
internal int FsmMakeTransition(int prevState, XName inputSymbol, out XName matchingName, out WildCard matchingWildCard) { Transitions currTrans = ValidationStates.Trans[prevState]; return currTrans.GetNextState(inputSymbol, out matchingName, out matchingWildCard); }
protected IEnumerable<XElement> GetWildCards(WildCard requestingWildCard) { IEnumerator<XElement> enumerator = this.GetUntyped().Elements().GetEnumerator(); XElement elem = null; StartFsm(); do { elem = ExecuteFSM(enumerator, null, requestingWildCard); if (elem != null) yield return elem; else yield break; } while(elem != null); }
public void IsMatchStaticTest() { IsMatchSinglePatternTest((input, pattern) => WildCard.IsMatch(input, pattern)); IsMatchSinglePatternOnlyTest((input, pattern) => WildCard.IsMatch(input, pattern)); }
public void IsMatchMultiPatternStaticTest() { IsMatchSinglePatternTest((input, pattern) => WildCard.IsMatch(input, pattern, WildCardOptions.MultiPattern)); IsMatchMultiPatternTest((input, pattern) => WildCard.IsMatch(input, pattern, WildCardOptions.MultiPattern)); }