ProgramNode ParseModule(ModulePath?path, SourceText source, SyntaxContext context) { var msg = path != null ? $" with path '{path}'" : string.Empty; if (!_loading.Add(source.FullPath)) { throw new ModuleLoadException($"Module{msg} could not be loaded due to circular 'use' declarations."); } try { if (context.Parses.ContainsKey(source.FullPath)) { throw new ModuleLoadException($"Module{msg} was already loaded previously."); } var lex = LanguageLexer.Lex(source); var parse = LanguageParser.Parse(lex, SyntaxMode.Normal); context.AddParse(source.FullPath, parse); foreach (var diag in lex.Diagnostics) { context.AddDiagnostic(diag); } foreach (var diag in parse.Diagnostics) { context.AddDiagnostic(diag); } var analysis = LanguageAnalyzer.Analyze(parse, this, context); foreach (var diag in analysis.Diagnostics) { context.AddDiagnostic(diag); } return(analysis.IsSuccess ? (ProgramNode)parse.Tree : throw new ModuleLoadException( $"Module{msg} failed to load due to syntax and/or semantic errors.")); } finally { _ = _loading.Remove(source.FullPath); } }
/// <summary> /// This is the main entry point for your service replica. /// This method executes when this replica of your service becomes primary and has write status. /// </summary> /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param> protected override async Task RunAsync(CancellationToken cancellationToken) { IReliableDictionary <string, string> myDictionary = await StateManager.GetOrAddAsync <IReliableDictionary <string, string> >("offsetDictionary"); var eventHubClient = EventHubClient.CreateFromConnectionString(Config.EhConnectionString, Config.EhCommentPath); EventHubClient publishClient = EventHubClient.CreateFromConnectionString(Config.EhConnectionString, Config.EhAnalyticPath); while (true) { cancellationToken.ThrowIfCancellationRequested(); using (ITransaction tx = StateManager.CreateTransaction()) { StateHandler stateHandler = new StateHandler(tx, StateManager); EventReader reader = new EventReader(eventHubClient, stateHandler); IEnumerable <AnalysedRedditComment> comments = await reader.GetComments(); IEnumerable <IReadOnlyDictionary <string, AnalysedRedditComment> > batches = BatchComments(comments, BatchSize); foreach (IReadOnlyDictionary <string, AnalysedRedditComment> batch in batches) { LanguageAnalyzer languageAnalyzer = new LanguageAnalyzer(); SentimentAnalyzer sentimentAnalyzer = new SentimentAnalyzer(); KeyPhraseAnalyzer keyPhraseAnalyzer = new KeyPhraseAnalyzer(); await languageAnalyzer.DoAnalysis(batch); // do language analysis first await sentimentAnalyzer.DoAnalysis(batch); await keyPhraseAnalyzer.DoAnalysis(batch); ProcessMessages(batch.Values, publishClient); } // If an exception is thrown before calling CommitAsync, the transaction aborts, all changes are // discarded, and nothing is saved to the secondary replicas. await tx.CommitAsync(); } await Task.Delay(TimeSpan.FromSeconds(PullDelay), cancellationToken); } // ReSharper disable once FunctionNeverReturns }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject o = JObject.Load(reader); var result = existingValue as Dictionary <string, AnalyzerBase> ?? new Dictionary <string, AnalyzerBase>(); foreach (var childProperty in o.Children <JProperty>()) { var propertyName = childProperty.Name; var typeProperty = ((JObject)childProperty.Value).Property("type"); typeProperty.Remove(); var typePropertyValue = typeProperty.Value.ToString(); Language language; if (Enum.TryParse(typePropertyValue, true, out language)) { typePropertyValue = "Language"; } var itemType = Type.GetType("Nest." + typePropertyValue + "Analyzer", false, true); AnalyzerBase item; if (itemType == typeof(LanguageAnalyzer)) { item = new LanguageAnalyzer(language); serializer.Populate(childProperty.Value.CreateReader(), item); } else if (itemType != null) { item = serializer.Deserialize(childProperty.Value.CreateReader(), itemType) as AnalyzerBase; } else { continue; } result[propertyName] = item; } return(result); }
public async Task <IActionResult> AddPublicaton(NewPostRequest request) { var user = _userManager.GetBySecretKey(request.Key); if (user == null) { return(StatusCode((int)HttpStatusCode.Forbidden)); } var extractor = new X.Web.MetaExtractor.Extractor(); var languageAnalyzer = new LanguageAnalyzer(Settings.Current.CognitiveServicesTextAnalyticsKey); try { var metadata = await extractor.Extract(new Uri(request.Link)); var languageCode = languageAnalyzer.GetTextLanguage(metadata.Description); var languageId = _localizationManager.GetLanguageId(languageCode) ?? Language.EnglishId; var publication = new DAL.Publication { Title = metadata.Title, Description = metadata.Description, Link = metadata.Url, Image = metadata.Image.FirstOrDefault(), Type = metadata.Type, DateTime = DateTime.Now, UserId = user.Id, CategoryId = request.CategoryId, Comment = request.Comment, LanguageId = languageId }; if (EmbededPlayer.GetPlayerSoure(request.Link) != null) { var player = new EmbededPlayer(request.Link); publication.EmbededPlayerCode = player.Render(); } publication = await _publicationManager.Save(publication); if (publication != null) { var model = new PublicationViewModel(publication, Settings.Current.WebSiteUrl); //If we can embed main content into site page, so we can share this page. var url = string.IsNullOrEmpty(model.EmbededPlayerCode) ? model.Link : model.ShareUrl; await _crossPostManager.Send(request.CategoryId, request.Comment, url); return(Created(new Uri(model.ShareUrl), model)); } else { throw new Exception("Can't save publication to databse"); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
protected override void BuildLanguageAnalyzer(LanguageAnalyzer languageAnalyzer) { languageAnalyzer.StopWords = _stopwords; }
protected virtual void BuildLanguageAnalyzer(LanguageAnalyzer languageAnalyzer) { }
private void BuildLanguageAnalyzerCore(LanguageAnalyzer languageAnalyzer) { BuildLanguageAnalyzer(languageAnalyzer); }
protected sealed override IEnumerable<KeyValuePair<string, AnalyzerBase>> Build() { var languageAnalyzer = new LanguageAnalyzer(Language); BuildLanguageAnalyzerCore(languageAnalyzer); yield return new KeyValuePair<string, AnalyzerBase>(Name, languageAnalyzer); }
protected override sealed IEnumerable<KeyValuePair<string, AnalyzerBase>> Build() { var languageAnalyzer = new LanguageAnalyzer(Language); BuildLanguageAnalyzerCore(languageAnalyzer); yield return new KeyValuePair<string, AnalyzerBase>(Name, languageAnalyzer); }
int Run(Options options) { ReadLine.AutoCompletionHandler = null; var loader = new StandardModuleLoader(ModuleLoaderMode.Interactive); var i = 0; while (true) { Console.ForegroundColor = ConsoleColor.Cyan; Console.Write($"flare({i})> "); Console.ResetColor(); var text = new StringBuilder(); var quit = false; var continued = false; while (true) { var input = ReadLine.Read(); if (input != string.Empty) { ReadLine.AddHistory(input); } var broken = false; if (input == "'repl:quit") { quit = true; break; } if (continued && input == "'repl:break") { broken = true; } else { _ = text.AppendLine(input); } var lex = LanguageLexer.Lex(StringSourceText.From("<repl>", text.ToString())); foreach (var diag in lex.Diagnostics) { LogDiagnostic(diag); } if (!lex.IsSuccess) { break; } var parse = LanguageParser.Parse(lex, SyntaxMode.Interactive); if (!broken && IsIncomplete(parse)) { Console.ForegroundColor = ConsoleColor.Cyan; Console.Write($".....({i})> "); Console.ResetColor(); continued = true; continue; } foreach (var diag in parse.Diagnostics) { LogDiagnostic(diag); } var analysis = LanguageAnalyzer.Analyze(parse, loader, new SyntaxContext()); foreach (var diag in analysis.Diagnostics) { LogDiagnostic(diag); } break; } if (quit) { break; } i++; } return(0); }