protected override void OnCreateDeviceIndependentResources(Direct2DFactory factory) { base.OnCreateDeviceIndependentResources(factory); this._textFormat = DirectWriteFactory.CreateTextFormat("Gabriola", 72); this._textFormat.TextAlignment = TextAlignment.Center; this._textFormat.ParagraphAlignment = ParagraphAlignment.Center; float width = ClientSize.Width / dpiScaleX; float height = ClientSize.Height / dpiScaleY; this._textLayout = DirectWriteFactory.CreateTextLayout("Click on this text Click on this text", this._textFormat, width, height); this._textAnalyzer = DirectWriteFactory.CreateTextAnalyzer(); this._source = new MyTextSource("Click on this text Click on this text"); using (FontCollection coll = this._textFormat.FontCollection) { int count = coll.Count; for (int index = 0; index < count; ++index) { using (FontFamily ff = coll[index]) { using (Font font = ff.GetFirstMatchingFont(FontWeight.Normal, FontStretch.Normal, FontStyle.Normal)) { LocalizedStrings ls = font.FaceNames; LocalizedStrings desc = font.GetInformationalStrings(InformationalStringId.Designer); int cultureIndex = ls.FindCulture(CultureInfo.CurrentCulture); string faceName = ls[cultureIndex]; FontMetrics metrics = font.Metrics; } } } } this._textAnalyzer.AnalyzeLineBreakpoints(_source, 0, (uint)_source.Text.Length); this._textAnalyzer.AnalyzeScript(_source, 0, (uint)_source.Text.Length); }
public unsafe void Append(TextAnalyzer analyzer, FontFace font, string text) { var layout = new TextLayout(); var format = new TextFormat { Font = font, Size = 32.0f }; analyzer.AppendText(text, format); analyzer.PerformLayout(0, 32, 1000, 1000, layout); var memBlock = new MemoryBlock(text.Length * 6 * PosColorTexture.Layout.Stride); var mem = (PosColorTexture*)memBlock.Data; foreach (var thing in layout.Stuff) { var width = thing.Width; var height = thing.Height; var region = new Vector4(thing.SourceX, thing.SourceY, width, height) / 4096; var origin = new Vector2(thing.DestX, thing.DestY); *mem++ = new PosColorTexture(origin + new Vector2(0, height), new Vector2(region.X, region.Y + region.W), unchecked((int)0xff000000)); *mem++ = new PosColorTexture(origin + new Vector2(width, height), new Vector2(region.X + region.Z, region.Y + region.W), unchecked((int)0xff000000)); *mem++ = new PosColorTexture(origin + new Vector2(width, 0), new Vector2(region.X + region.Z, region.Y), unchecked((int)0xff000000)); *mem++ = new PosColorTexture(origin, new Vector2(region.X, region.Y), unchecked((int)0xff000000)); count++; } vertexBuffer = new DynamicVertexBuffer(memBlock, PosColorTexture.Layout); }
protected string Lemmatize(TextAnalyzer textAnalyzer, string text) { Contract.Requires<ArgumentNullException>(textAnalyzer != null); Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(text)); string trimText = LexerUtils.TrimText(text); string[] words = trimText.Split(' '); StringBuilder stringBuilder = new StringBuilder(1024); for (int i = 0; i < words.Length; i++) { LemmatizeResult lemmatizeResult = textAnalyzer.Lemmatize(words[i]).FirstOrDefault(); if (lemmatizeResult != null) { string lemma = lemmatizeResult.GetTextByFormId(0).ToLower(); if (i != words.Length - 1) { stringBuilder.AppendFormat("{0} ", lemma); } else { stringBuilder.Append(lemma); } } } return stringBuilder.ToString(); }
public TextGenerator(TextAnalyzer textAnalyzer) { if (textAnalyzer == null) { throw new ArgumentNullException("textAnalyzer"); } _textAnalyzer = textAnalyzer; _textParser = new TextParser(_textAnalyzer); _templateParser = new TemplateParser(_textAnalyzer); }
public TemplateParser(TextAnalyzer textAnalyzer) { if (textAnalyzer == null) { throw new ArgumentNullException("textAnalyzer"); } _textAnalyzer = textAnalyzer; // TODO: Необходимо продумать логику загрузки плагинов для TemplateParser. // Необходимо убедиться, в каком порядке загружаются плагины, // т.к. это влияет на порядок их применения. PluginManager.LoadPlugins<ITemplateParserPlugin>(); }
private static void AnalyzeText(string path, Network network) { TextAnalyzer textAnalyzer = new TextAnalyzer(AdapterKind.RussianCp1251Adapter); textAnalyzer.Load( Path.Combine(Environment.CurrentDirectory, "Dictionaries", "Russian", "Dictionary.auto"), Path.Combine(Environment.CurrentDirectory, "Dictionaries", "Russian", "Paradigms.bin"), Path.Combine(Environment.CurrentDirectory, "Dictionaries", "Russian", "PredictionDictionary.auto")); List<NetworkNode> context = new List<NetworkNode>(); List<NetworkNode> context2 = new List<NetworkNode>(); using (FileStream fileStream = File.Open(path, FileMode.Open)) using (StreamReader reader = new StreamReader(fileStream)) { while (!reader.EndOfStream) { string currentLine = reader.ReadLine(); string[] words = currentLine.Split(' '); foreach (string word in words) { var foundNodes = network.Nodes.Where(node => string.Equals(node.Name, word, StringComparison.InvariantCultureIgnoreCase)); context2.AddRange(network.Nodes.Where(node => node.Name.Contains(word))); if (foundNodes.Count() > 0) { context.AddRange(foundNodes); } else { var results = textAnalyzer.Lemmatize(word, true); LemmatizeResult result = results.FirstOrDefault(); if (result != null) { PartOfSpeech partOfSpeech = result.GetPartOfSpeech(); //if (partOfSpeech == PartOfSpeech.NOUN) { string lemma = result.GetTextByFormId(0); context.AddRange(network.Nodes.Where(node => string.Equals(node.Name, lemma, StringComparison.InvariantCultureIgnoreCase))); context2.AddRange(network.Nodes.Where(node => node.Name.Contains(lemma))); } } } } } } }
public unsafe void Append(TextAnalyzer analyzer, FontFace font, string text, float fontSize, int atlasWidth, RectangleF drawRect, RgbaByte color) { if (string.IsNullOrEmpty(text)) { return; } _textLayout.Stuff.Clear(); _textFormat.Font = font; _textFormat.Size = fontSize; analyzer.AppendText(text, _textFormat); analyzer.PerformLayout(drawRect.X, drawRect.Y, drawRect.Width, drawRect.Height, _textLayout); PerformLayoutAndUpdateDeviceBuffers(atlasWidth, color); }
public unsafe void Append(TextAnalyzer analyzer, FontFace font, CharBuffer charBuffer, float fontSize, int atlasWidth, RectangleF drawRect, RgbaByte color) { if (charBuffer.Count == 0) { return; } _textLayout.Stuff.Clear(); _textFormat.Font = font; _textFormat.Size = fontSize; analyzer.AppendText(charBuffer.Buffer, 0, (int)charBuffer.Count, _textFormat); analyzer.PerformLayout(drawRect.X, drawRect.Y, drawRect.Width, drawRect.Height, _textLayout); PerformLayoutAndUpdateDeviceBuffers(atlasWidth, color); }
public void Setup() { stemmingServiceMock = new Mock <IStemmingService>(); textAnalyzer = new TextAnalyzer(stemmingServiceMock.Object); SetupStemmingServiceMock(); compareLogic = new CompareLogic { Config = new ComparisonConfig { IgnoreCollectionOrder = true } }; }
public async Task <IActionResult> OnPostDeleteAsync(int id) { using (var db = new BloggingContext()) { var p = db.Posts.Find(id); if (p != null) { db.Posts.Remove(p); await db.SaveChangesAsync(); } } TextAnalyzer.AnalyseTextAndUpdateCache(cache); return(RedirectToPage()); }
public ConsultWindow(TalesNetwork talesNetwork) : this() { Contract.Requires<ArgumentNullException>(talesNetwork != null); _talesNetwork = talesNetwork; TextAnalyzer textAnalyzer = new TextAnalyzer(AdapterKind.RussianCp1251Adapter); textAnalyzer.Load( @"Dictionaries\Russian\Dictionary.auto", @"Dictionaries\Russian\Paradigms.bin", @"Dictionaries\Russian\PredictionDictionary.auto"); _textGenerator = new TextGenerator(textAnalyzer); QuestionTextBox.Focus(); }
public void Setup() { var input = @" <w:body> <w:p> <w:r> <w:t> ok jim, ok</w:t> </w:r> </w:p> </w:body> "; var textAnalyzer = new TextAnalyzer(); var node = TestHelper.ParseString(input, true); result = textAnalyzer.Analyze(node); }
public async Task ReturnsCommentIntactIfNotAnalyzed() { var config = Options.Create(new WebConfiguration { TextAnalyticsSubscriptionKey = _invalidSubscriptionKey }); var textAnalyticsClientFactoryMock = new Mock <ITextAnalyticsClientFactory> { DefaultValue = DefaultValue.Mock }; ITextAnalyzer textAnalyzer = new TextAnalyzer(config, textAnalyticsClientFactoryMock.Object); var comment = new Comment("test-post-id", new string('*', 555), "John Doe"); var result = await textAnalyzer.AnalyzeAsync(comment).ConfigureAwait(false); Assert.Equal(comment.Score, result.Comment.Score); }
public ConsultWindow2(TalesNetwork network) { InitializeComponent(); _network = network; cmbTale.ItemsSource = _network.Tales; if (cmbTale.HasItems) cmbTale.SelectedIndex = 0; TextAnalyzer textAnalyzer = new TextAnalyzer(AdapterKind.RussianCp1251Adapter); textAnalyzer.Load( @"Dictionaries\Russian\Dictionary.auto", @"Dictionaries\Russian\Paradigms.bin", @"Dictionaries\Russian\PredictionDictionary.auto"); _textGenerator = new TextGenerator(textAnalyzer); }
static void Main(string[] args) { var textAnalyzer = new TextAnalyzer(); //var text = string.Join(" ", Texts.SimpleSentences.Take(20)); var text = Texts.ComplexSentences.ElementAt(3); foreach (var sentence in new[] { text }) { var taggingReport = textAnalyzer.AnalyzeText(sentence); var sentenceReport = new SentenceAnalyzer().Analyze(taggingReport); System.Console.WriteLine(taggingReport.GetSummary()); System.Console.WriteLine(sentenceReport.GetSummary()); System.Console.WriteLine(); System.Console.WriteLine(); } }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } using (var db = new BloggingContext()) { await db.Posts.AddAsync(Post); await db.SaveChangesAsync(); } TextAnalyzer.AnalyseTextAndUpdateCache(cache); return(RedirectToPage("Index")); }
public void SetUp() { imageSettings = new ImageSettings(); var imageHolder = new PictureBoxImageHolder(); imageHolder.RecreateImage(imageSettings); var colorSettingsProvider = new ColorSettingsProvider(); var filesSettings = new FilesSettings(); filesSettings.TextFilePath = "..\\..\\testTextAnalyzer.txt"; filesSettings.BoringWordsFilePath = "..\\..\\boring words.txt"; var textAnalyzer = new TextAnalyzer(filesSettings); fontSettings = new FontSettings(); var tagCreator = new TagCreator(fontSettings, new SpiralCloudLayouter(imageSettings), textAnalyzer, imageHolder); painter = new Painter(colorSettingsProvider, imageHolder, tagCreator); }
/// <summary> /// Analyzes the text using each of the analyzers and returns /// their results as a series of runs. /// </summary> public void GenerateResults(TextAnalyzer textAnalyzer, out Run[] runs, out LineBreakpoint[] breakpoints) { // Initially start out with one result that covers the entire range. // This result will be subdivided by the analysis processes. LinkedRun initialRun = new LinkedRun() { nextRunIndex = 0, textStart = 0, textLength = text_.Length, bidiLevel = (readingDirection_ == ReadingDirection.RightToLeft) ? 1 : 0 }; runs_ = new List <LinkedRun>(); runs_.Add(initialRun); breakpoints_ = new List <LineBreakpoint>(); //Call each of the analyzers in sequence, recording their results. if ((textAnalyzer.AnalyzeLineBreakpoints(this, 0, text_.Length, this) == Result.Ok) && (textAnalyzer.AnalyzeBidi(this, 0, text_.Length, this) == Result.Ok) && (textAnalyzer.AnalyzeScript(this, 0, text_.Length, this) == Result.Ok) && (textAnalyzer.AnalyzeNumberSubstitution(this, 0, text_.Length, this) == Result.Ok)) { breakpoints = new LineBreakpoint[breakpoints_.Count]; breakpoints_.CopyTo(breakpoints); // Resequence the resulting runs in order before returning to caller. runs = new Run[runs_.Count]; int nextRunIndex = 0; for (int i = 0; i < runs_.Count; i++) { runs[i] = runs_[nextRunIndex].AsRun; nextRunIndex = runs_[nextRunIndex].nextRunIndex; } } else { runs = new Run[0]; breakpoints = new LineBreakpoint[0]; } }
public async Task AnalyzesSentimentScore(string message, double?score) { var config = Options.Create(new WebConfiguration { TextAnalyticsSubscriptionKey = _validSubscriptionKey }); // SentimentBatchAsync extension method uses SentimentWithHttpMessagesAsync internally and mocking // extension methods with Moq isn't currently possible. Extension methods are "hard dependencies" that // one could also break by introducing a wrapper class and an interface. // Let's mock SentimentWithHttpMessagesAsync method here instead. var httpOperationResponse = new HttpOperationResponse <SentimentBatchResult> { Body = new SentimentBatchResult(new SentimentBatchResultItem[] { new SentimentBatchResultItem(score: score) }) }; var textAnalyticsClientMock = new Mock <ITextAnalyticsClient>(); textAnalyticsClientMock.Setup(x => x.SentimentWithHttpMessagesAsync( It.IsAny <bool?>(), It.IsAny <MultiLanguageBatchInput>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>())) .ReturnsAsync(httpOperationResponse); var textAnalyticsClientFactoryMock = new Mock <ITextAnalyticsClientFactory>(); textAnalyticsClientFactoryMock.Setup(x => x.CreateClient(It.IsAny <string>(), It.IsAny <string>())) .Returns(textAnalyticsClientMock.Object); ITextAnalyzer textAnalyzer = new TextAnalyzer(config, textAnalyticsClientFactoryMock.Object); var comment = new Comment("test-post-id", message, "John Doe"); var analyzedComment = await textAnalyzer.AnalyzeAsync(comment).ConfigureAwait(false); httpOperationResponse.Dispose(); Assert.Equal($"{score:0.00}", analyzedComment.Comment.Score); }
static void Main(string[] args) { Dictionary <char, int> charCounted = new Dictionary <char, int>(); char[] text = new char[50]; Random rnd = new Random(); TextAnalyzer textAnalyzer = new TextAnalyzer(); text = textAnalyzer.GeneratedText(text, rnd); Console.WriteLine("The initial string: \n"); PrintText(text); Array.Sort(text); Console.WriteLine("String sorted by asc order: \n"); PrintText(text); Console.WriteLine("Count chars: \n"); charCounted = CountChar(text); foreach (var key in charCounted.Keys) { Console.WriteLine(key + ": " + charCounted[key]); } }
public ActionResult <List <WordStats> > GetByMonth(int month) { var news = _db.NewsEntity .GetAll() .ToList() .Where(n => n.News.Date.Month == month) .Select(n => n.News) .ToList(); TextAnalyzer text = new TextAnalyzer(news); var wc = text.SplitText() .WordCount() .OrderByDescending(w => w.Value) .Select(w => new WordStats() { Word = w.Key, Frequency = w.Value }) .ToList(); return(wc.GetRange(0, RangeCeiling(wc.Count))); }
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result) { var activity = await result as IMessageActivity; double feedbackScore = TextAnalyzer.MakeAnalysisRequest(activity.Text); String clientResponse = String.Format("Ваш отзыв был оценен как положительный на {0}%.\n{1}", Math.Round(feedbackScore * 100), (feedbackScore >= 0.5) ? "Спасибо, мы будем работать для Вас еще лучше !" : "Извините, мы постараемся работать для Вас лучше !"); // (feedbackScore >= 0.5) ? // "Спасибо за отзыв, мы будем работать для Вас еще лучше !" : // "Извините, мы постараемся работать лучше для Вас !"; // --------------------------------------------------------------- // Save customer's reply to Azure Storage Tables // --------------------------------------------------------------- CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]); // ("DefaultEndpointsProtocol=https;AccountName=tevappstorage;AccountKey=NMr/WodMMGKGijaOBFV4xqVMKL8UlZbUDWB608W5XazIuYX4UMf4FHf3r2rZtNL7PdBEIWmoRsOLt8JiRW9YHw==;EndpointSuffix=core.windows.net"); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference("CustomerFeedback"); table.CreateIfNotExists(); CustomerFeedback custFeedback = new CustomerFeedback(activity.ChannelId, activity.Id); custFeedback.Locale = activity.Locale; custFeedback.Text = activity.Text; custFeedback.Score = feedbackScore; TableOperation insertOperation = TableOperation.Insert(custFeedback); await table.ExecuteAsync(insertOperation); await context.PostAsync(clientResponse); context.Done(true); // context.Wait(MessageReceivedAsync); }
private List <Results> CalculateMetrics(string path) { var res = new List <Results>(); ITextReader reader1 = new TextFileReader(path); TextAnalyzer textAnalyzer = new TextAnalyzer(reader1); textAnalyzer.AddMetrics(new MostCommonCharacter()); textAnalyzer.AddMetrics(new Language()); textAnalyzer.AddMetrics(new MostCommonWorld()); textAnalyzer.AddMetrics(new MostCommonNotSimpleWord()); textAnalyzer.AddMetrics(new CountSentence()); textAnalyzer.Analyz(); foreach (MetricsBase metrics in textAnalyzer.Metrics) { res.Add(new Results { Name = metrics.Result().Keys.FirstOrDefault(), Value = metrics.Result().Values.FirstOrDefault() }); } return(res); }
protected override void OnCreateDeviceIndependentResources(Direct2DFactory factory) { base.OnCreateDeviceIndependentResources(factory); _textFormat = DirectWriteFactory.CreateTextFormat("Gabriola", 72); _textFormat.TextAlignment = TextAlignment.Center; _textFormat.ParagraphAlignment = ParagraphAlignment.Center; float width = ClientSize.Width / dpiScaleX; float height = ClientSize.Height / dpiScaleY; _textLayout = DirectWriteFactory.CreateTextLayout("Click on this text Click on this text", _textFormat, width, height); _textAnalyzer = DirectWriteFactory.CreateTextAnalyzer(); _source = new MyTextSource("Click on this text Click on this text"); using (FontCollection coll = _textFormat.FontCollection) { int count = coll.Count; for (int index = 0; index < count; ++index) { using (FontFamily ff = coll[index]) { using (Font font = ff.GetFirstMatchingFont(FontWeight.Normal, FontStretch.Normal, FontStyle.Normal)) { LocalizedStrings ls = font.FaceNames; LocalizedStrings desc = font.GetInformationalStrings(InformationalStringId.Designer); int cultureIndex = ls.FindCulture(CultureInfo.CurrentCulture); if (cultureIndex >= 0) { string faceName = ls[cultureIndex]; FontMetrics metrics = font.Metrics; } } } } } _textAnalyzer.AnalyzeLineBreakpoints(_source, 0, (uint)_source.Text.Length); _textAnalyzer.AnalyzeScript(_source, 0, (uint)_source.Text.Length); }
static void Main(string[] args) { CmdExecutor cmdExecutor = new CmdExecutor(); while (true) { string filePath = "../../../commands/rebuildplugin.txt"; TextAnalyzer textAnalyzer = new TextAnalyzer(); var headers = textAnalyzer.AnalyzeFile(filePath); //var testingInput = headers[0].Content[0]; var testingArguments = ""; string appName = "cmd.exe"; foreach (var header in headers) { foreach (var line in header.Content) { CommandResult commandResult = cmdExecutor.ExecuteCommand(appName, line, testingArguments, 5000); Thread.Sleep(100); Console.WriteLine(commandResult.Output); } } //var input = Console.ReadLine(); // //string appName = "C:\\Program Files\\Git\\git-bash.exe"; // //string appName = "C:\\Program Files(x86)\\Microsoft Visual Studio\\2017\\Professional\\Common7\\Tools\\VsDevCmd.bat"; ////string appName = "cmd.exe"; // string appName = "C:\\Windows\\System32\\cmd.exe"; // string arguments = "/k \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\Tools\\VsDevCmd.bat\""; //CommandResult commandResult = cmdExecutor.ExecuteCommand(appName, input, arguments, 5000); // } }
static void Main(string[] args) { var serpClient = new GoogleSerpClient(); var serpResult = serpClient.Get("kuchen", 100); var websites = new List <HtmlPage>(); foreach (var link in serpResult.Links) { var webClient = new AdvancedWebClient(); var content = webClient.Get(link.UrlAsString); var htmlAnalyzer = new HtmlAnalyzer(); var website = htmlAnalyzer.AnalyzeHtmlPage(content.HtmlContent); websites.Add(website); } var textAnalyzer = new TextAnalyzer(); foreach (var website in websites) { var words = textAnalyzer.GetWords(website.Paragraphs, true); } }
public HomeController(ILogger <HomeController> logger, TextAnalyzer analyzer) { _logger = logger; _analyzer = analyzer; }
private static void TestcaseSplitAndMarge(IEnumerable <DepthText> splittedTexts, string margedText, string nest, string unnest) { TextAnalyzer.SplitWithDepth(margedText, nest, unnest).IsCollection(splittedTexts); splittedTexts.Marge(nest, unnest).Is(margedText); }
public TextParser(TextAnalyzer textAnalyzer) { Contract.Requires<ArgumentNullException>(textAnalyzer != null); _textAnalyzer = textAnalyzer; }
public CompositeAnalyzer(TextAnalyzer azure, PyBridge local) { Azure = azure; Local = local; }
private static TextAnalyzer CreateTextAnalyzer() { TextAnalyzer textAnalyzer = new TextAnalyzer(AdapterKind.RussianCp1251Adapter); textAnalyzer.Load( Path.Combine(Environment.CurrentDirectory, "Dictionaries", "Russian", "Dictionary.auto"), Path.Combine(Environment.CurrentDirectory, "Dictionaries", "Russian", "Paradigms.bin"), Path.Combine(Environment.CurrentDirectory, "Dictionaries", "Russian", "PredictionDictionary.auto")); return textAnalyzer; }
private static void AnalyzeText(TalesNetwork taleNetwork, TextAnalyzer textAnalyzer, string path) { string text = File.ReadAllText(path); //if (foundFunctionNodes.Count != 0) //{ // TaleNode taleNode = foundFunctionNodes.First().Tale; // bool areMembersOfTheSameTale = foundFunctionNodes.All(node => node.Tale == taleNode); // if (areMembersOfTheSameTale) // { // TaleNode baseTale = (TaleNode)taleNode.BaseNode; // var scenario = baseTale.Scenario; // //TODO Сценарий необходимо хранить в сети. // //List<FunctionType> scenario = new List<FunctionType> // //{ // // FunctionType.InitialState, // // FunctionType.Interdiction, // // FunctionType.Absentation, // // FunctionType.ViolationOfInterdiction, // // FunctionType.Sabotage, // // FunctionType.WoesPost // //}; // Dictionary<FunctionType, FunctionNode> scenarioFunctions = new Dictionary<FunctionType, FunctionNode>(); // foreach (FunctionType functionType in scenario) // { // FunctionNode foundNode = foundFunctionNodes.SingleOrDefault(node => node.FunctionType == functionType); // if (foundNode != null) // { // scenarioFunctions[functionType] = foundNode; // } // else // { // // TODO Необходимо рассмотреть два случая: // // 1) Вершина не смогла полностью разрезолвиться; // // 2) Вершины нет в сети. // // Хотя, наверное, возможно ограничиться только 2-ым вариантом. // TaleNode baseTaleNode = (TaleNode)taleNode.BaseNode; // FunctionNode baseFunctionNode = baseTaleNode.FunctionNodes.SingleOrDefault(node => node.FunctionType == functionType); // if (baseFunctionNode != null) // { // // В случае, когда в базовой сказке нашлась функциональная вершина с искомым типом, необходимо сделать следующее: // // 1) Необходимо определить недостающий контекст, т.е. найти те контекстные вершины (агент, реципиент и т.п.), // // которых не хватает для успешной генерации текста. // // 2) Найти дочерние вершины найденных вершин, относящиеся к текущей сказке. // TemplateParserResult baseNodeParserResult = resolvedNodes[baseFunctionNode]; // TemplateParserDictionaryContext parserContext = new TemplateParserDictionaryContext(); // if (baseNodeParserResult.UnresolvedContext.Any()) // { // foreach (NetworkEdgeType unresolvedEdgeType in baseNodeParserResult.UnresolvedContext) // { // var baseNodes = baseFunctionNode.OutgoingEdges.GetEdges(unresolvedEdgeType, false).Select(edge => edge.EndNode); // foreach (NetworkNode baseNode in baseNodes) // { // NetworkEdge isAEdge = baseNode.IncomingEdges.GetEdge(NetworkEdgeType.IsA); // if (isAEdge != null) // { // NetworkNode childNode = isAEdge.StartNode; // if (childNode != null) // { // } // } // } // } // } // else // { // NetworkNode agentNode = baseFunctionNode.Agents.First(); // //bool found = false; // NetworkEdge isAEdge = agentNode.IncomingEdges.GetEdge(NetworkEdgeType.IsA); // //NetworkEdge // if (isAEdge != null) // { // NetworkNode childNode = isAEdge.StartNode; // if (taleAgents.Any(node => node.BaseNode == childNode)) // { // parserContext.Add(NetworkEdgeType.Agent, childNode); // } // //parserContext.Add(NetworkEdgeType.Agent // } // } // } // else // { // throw new NotImplementedException(); // } // } // } // } // else // { // throw new NotImplementedException(); // } //} }
public void Initialize() { _analyzer = new PrivateKeyAnalyzer(); _vulnerabilities = new List <Vulnerability>(); _analyzer.VulnerabilityDiscovered += OnVulnerabilityDiscovered; }
protected void ShapeGlyphRun(TextAnalyzer textAnalyzer, int runIndex, ref int glyphStart) { // Shapes a single run of text into glyphs. // Alternately, you could iteratively interleave shaping and line // breaking to reduce the number glyphs held onto at once. It's simpler // for this demostration to just do shaping and line breaking as two // separate processes, but realize that this does have the consequence that // certain advanced fonts containing line specific features (like Gabriola) // will shape as if the line is not broken. Run run = runs_[runIndex]; int textStart = run.textStart; int textLength = run.textLength; int maxGlyphCount = glyphIndices_.Length - glyphStart; int actualGlyphCount = 0; run.glyphStart = glyphStart; run.glyphCount = 0; if (textLength == 0) { return;// Nothing to do.. } // Allocate space for shaping to fill with glyphs and other information, // with about as many glyphs as there are text characters. We'll actually // need more glyphs than codepoints if they are decomposed into separate // glyphs, or fewer glyphs than codepoints if multiple are substituted // into a single glyph. In any case, the shaping process will need some // room to apply those rules to even make that determintation. if (textLength > maxGlyphCount) { maxGlyphCount = EstimateGlyphCount(textLength); int totalGlyphsArrayCount = glyphStart + maxGlyphCount; short[] Resized_glyphIndices_ = new short[totalGlyphsArrayCount]; glyphIndices_.CopyTo(Resized_glyphIndices_, 0); glyphIndices_ = Resized_glyphIndices_; } ShapingTextProperties[] textProps = new ShapingTextProperties[textLength]; ShapingGlyphProperties[] glyphProps = new ShapingGlyphProperties[maxGlyphCount]; // Get the glyphs from the text, retrying if needed. int tries = 0; do { short[] call_glyphClusters_ = new short[glyphClusters_.Length - textStart]; short[] call_glyphIndices_ = new short[glyphIndices_.Length - glyphStart]; var result = textAnalyzer.GetGlyphs( text_.Substring(textStart, textLength), textLength, fontFace_, run.isSideways, (run.bidiLevel % 2 == 1), run.script, localName_, run.isNumberSubstituted ? numberSubstitution_ : null, null, null, 0, maxGlyphCount, call_glyphClusters_, textProps, call_glyphIndices_, glyphProps, out actualGlyphCount); Array.Copy(call_glyphClusters_, 0, glyphClusters_, textStart, call_glyphClusters_.Length); Array.Copy(call_glyphIndices_, 0, glyphIndices_, glyphStart, call_glyphIndices_.Length); tries++; //if (result!=SharpDX.Result.OutOfMemory) if (result != SharpDX.Result.Ok) { // Try again using a larger buffer. maxGlyphCount = EstimateGlyphCount(maxGlyphCount); int totalGlyphsArrayCount = glyphStart + maxGlyphCount; glyphProps = new ShapingGlyphProperties[maxGlyphCount]; glyphIndices_ = new short[totalGlyphsArrayCount]; } else { break; } }while (tries < 2);// We'll give it two chances. // Get the placement of the all the glyphs. if (glyphAdvances_.Length < glyphStart + actualGlyphCount) { float[] Resized_glyphAdvances_ = new float[glyphStart + actualGlyphCount]; glyphAdvances_.CopyTo(Resized_glyphAdvances_, 0); glyphAdvances_ = Resized_glyphAdvances_; } if (glyphOffsets_.Length < glyphStart + actualGlyphCount) { GlyphOffset[] Resized_glyphOffsets_ = new GlyphOffset[glyphStart + actualGlyphCount]; glyphOffsets_.CopyTo(Resized_glyphOffsets_, 0); glyphOffsets_ = Resized_glyphOffsets_; } short[] call2_glyphClusters_ = new short[glyphClusters_.Length - textStart]; Array.Copy(glyphClusters_, textStart, call2_glyphClusters_, 0, call2_glyphClusters_.Length); short[] call2_glyphIndices_ = new short[glyphIndices_.Length - glyphStart]; Array.Copy(glyphIndices_, glyphStart, call2_glyphIndices_, 0, call2_glyphIndices_.Length); float[] call2_glyphAdvances_ = new float[glyphAdvances_.Length - glyphStart]; Array.Copy(glyphAdvances_, glyphStart, call2_glyphAdvances_, 0, call2_glyphAdvances_.Length); GlyphOffset[] call2_glyphOffsets_ = new GlyphOffset[glyphOffsets_.Length - glyphStart]; Array.Copy(glyphOffsets_, glyphStart, call2_glyphOffsets_, 0, call2_glyphOffsets_.Length); var result2 = textAnalyzer.GetGlyphPlacements( text_.Substring(textStart, textLength), call2_glyphClusters_, textProps, textLength, call2_glyphIndices_, glyphProps, actualGlyphCount, fontFace_, fontEmSize_, run.isSideways, run.bidiLevel % 2 == 1, run.script, localName_, null, null, 0, call2_glyphAdvances_, call2_glyphOffsets_); //call2_glyphClusters_.CopyTo(glyphClusters_, textStart); call2_glyphAdvances_.CopyTo(glyphAdvances_, glyphStart); call2_glyphOffsets_.CopyTo(glyphOffsets_, glyphStart); // Certain fonts, like Batang, contain glyphs for hidden control // and formatting characters. So we'll want to explicitly force their // advance to zero. if (run.script.Shapes == ScriptShapes.NoVisual) { for (int i = glyphStart; i < glyphStart + actualGlyphCount; i++) { glyphAdvances_[i] = 0; } } // Set the final glyph count of this run and advance the starting glyph. run.glyphCount = actualGlyphCount; runs_[runIndex] = run; glyphStart += actualGlyphCount; }
public void WhenTextAnalyzerIsRunWithNullSentence() { try { var ta = new TextAnalyzer(); _wordCounts = ta.CountDistinctWords(_sentence); } catch (Exception e) { ScenarioContext.Current.Add("Exception_NullSentence", e); } }
public void WhenTextAnalyzerIsRun() { var ta = new TextAnalyzer(); _wordCounts = ta.CountDistinctWords(_sentence); }
private Grammem FindObjectGrammem(TextAnalyzer textAnalyzer, string predicate) { Contract.Requires<ArgumentNullException>(textAnalyzer != null); Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(predicate)); Grammem grammem = Grammem.None; string[] words = predicate.Split(' '); string verb = words.Length > 1 ? words[1] : words[0]; LemmatizeResult result = textAnalyzer.Lemmatize(verb).FirstOrDefault(); if (result != null) { _objectCasesDictionary.TryGetValue(result.GetTextByFormId(0).ToLower(), out grammem); } return grammem; }
public unsafe void Append(TextAnalyzer analyzer, FontFace font, CharBuffer charBuffer, float fontSize, int atlasWidth, RectangleF drawRect) { Append(analyzer, font, charBuffer, fontSize, atlasWidth, drawRect, RgbaByte.White); }