public static void FindWords( GraphNode <char> node, ICollection <string> words, HashSet <GraphNode <char> > visited, StringBuilder word) { if (EnglishDictionary.IsWord(word.ToString())) { words.Add(word.ToString()); } foreach (GraphNode <char> neighbor in node.Neighbors) { if (!visited.Contains(neighbor)) { visited.Add(neighbor); word.Append(neighbor.Value); FindWords(neighbor, words, visited, word); visited.Remove(neighbor); word.Remove(word.Length - 1, 1); } } }
public async Task <Stream> Run(RequestContext requestContext) { var data = await _logger.GetRequestsByPartialUrl(requestContext.OriginUrl.ToString()); var vector = new RequestVector() { Url = requestContext.OriginUrl, ErrorCount = requestContext.OwinContext.Response.Header.StatusCode.GetValueOrDefault(0) >= 400 ? 1 : 0, IsCacheable = IsCacheable(requestContext.OwinContext), IsPublic = IsPublic(requestContext.OwinContext), IsHtml = requestContext.OwinContext.Response.Header.ContentMimeType.Contains("text/html"), IsJson = requestContext.OwinContext.Response.Header.ContentMimeType.Contains("json"), PathCount = requestContext.OriginUrl.PathAndQuery.Split('/').Count(), RequestCount = data.Items.Count, ResponseSize = data.Items.Select(r => r.ResponseSize / 1024d).Mean(), ResponseTime = data.Items.Select(r => r.ElapsedMilliseconds).Mean(), UniqueRefererCount = data.Items.Where(r => r.RefererUrl != null).Select(r => r.RefererUrl).Distinct().Count() }; var tokens = (await Tokenise(requestContext)).ToList(); vector.TokenCount = tokens.Count; vector.SemanticTokenRatio = tokens.Where(t => t.Type == TokenType.Word && _dict.IsWord(t.Text)).Count() / (double)tokens.Count; vector.NumericTokenRatio = tokens.Where(t => t.Type == TokenType.Number).Count() / (double)tokens.Count; await Write(vector); return(requestContext.RequestBlob); }