public LingvisticsResult ProcessText(LingvisticsTextInput input) { //System.Diagnostics.Debugger.Break(); if (input == null) { throw (new ArgumentNullException("input")); } if (input.Options == LingvisticsResultOptions.None) { return(null); } var rdfXml = _LinguisticsKernelConroller.GetRDF_New(input.Text, input.AfterSpellChecking, input.BaseDate, (int)input.Mode); var coreference = _CoreferenceResolver?.Process(rdfXml); var result = GetResultFromRDF(rdfXml, coreference, input.Options, input.GenerateAllSubthemes); #if WITH_OM_TM if ((input.Options & LingvisticsResultOptions.OpinionMiningWithTonality) == LingvisticsResultOptions.OpinionMiningWithTonality) { DigestOutputResult opinionMiningWithTonalityResult = CreateOpinionMiningWithTonalityResult(rdfXml, coreference, input.ObjectAllocateMethod); return(new LingvisticsResult(input.Options, result.RDF, result.ThemeList, result.LinkList, opinionMiningWithTonalityResult)); } else if ((input.Options & LingvisticsResultOptions.Tonality) == LingvisticsResultOptions.Tonality) { TonalityMarkingOutputResult tonalityResult = CreateTonalityResult(rdfXml, coreference, input.ObjectAllocateMethod, input.TonalityMarkingInput); return(new LingvisticsResult(input.Options, result.RDF, result.ThemeList, result.LinkList, tonalityResult)); } #endif return(result); }
public static LingvisticsResult ProcessText(LingvisticsTextInput input) { lock ( _SyncLock ) { #region [.create.] var p = _LingvisticsWorkInProcessor; if (p == null) { { p = new LingvisticsWorkInProcessor(Config.USE_COREFERENCE_RESOLUTION, Config.USE_GEONAMES_DICTIONARY, Config.MAX_ENTITY_LENGTH); } { GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); } _LingvisticsWorkInProcessor = p; } #endregion var result = _LingvisticsWorkInProcessor.ProcessText(input); return(result); } }
public static LingvisticsTextInput CreateLingvisticsTextInput4TextDummy() { var ip = new LingvisticsTextInput() { Text = TextDummy, AfterSpellChecking = false, BaseDate = DateTime.Now, Mode = SelectEntitiesMode.Full, GenerateAllSubthemes = false, Options = LingvisticsResultOptions.All, }; return(ip); }
private static string GetResultHtml(LocalParams lp) { var lingvisticsInput = new LingvisticsTextInput() { Text = lp.Text, AfterSpellChecking = false, BaseDate = DateTime.Now, Mode = SelectEntitiesMode.Full, GenerateAllSubthemes = false, }; #region [.result.] switch (lp.ProcessType) { case ProcessTypeEnum.Digest: #region [.code.] { lingvisticsInput.Options = LingvisticsResultOptions.OpinionMiningWithTonality; var lingvisticResult = _LingvisticsServer.Value.ProcessText(lingvisticsInput); var html = ConvertToHtml(lp.Context, lingvisticResult.OpinionMiningWithTonalityResult); return(html); } #endregion case ProcessTypeEnum.TonalityMarking: #region [.code.] { lingvisticsInput.TonalityMarkingInput = new TonalityMarkingInputParams4InProcess(); if (!lp.InquiryText.IsNullOrWhiteSpace()) { lingvisticsInput.TonalityMarkingInput.InquiriesSynonyms = lp.InquiryText.ToTextList(); } lingvisticsInput.ObjectAllocateMethod = lp.ObjectAllocateMethod.GetValueOrDefault(ObjectAllocateMethod.FirstVerbEntityWithRoleObj); lingvisticsInput.Options = LingvisticsResultOptions.Tonality; var lingvisticResult = _LingvisticsServer.Value.ProcessText(lingvisticsInput); var html = ConvertToHtml(lp.Context, lingvisticResult.TonalityResult, lp.OutputType); return(html); } #endregion default: throw (new ArgumentException(lp.ProcessType.ToString())); } #endregion }
public LingvisticsResult ProcessText(LingvisticsTextInput input) { _Semaphore.WaitOne(); var worker = default(LingvisticsWorkInProcessor); var result = default(LingvisticsResult); try { worker = Pop(_Stack); result = worker.ProcessText(input); } finally { if (worker != null) { _Stack.Push(worker); } _Semaphore.Release(); } return(result); }
public LingvisticsResult ProcessText(string text, bool afterSpellChecking, DateTime baseDate, LingvisticsResultOptions options = LingvisticsResultOptions.All, SelectEntitiesMode mode = SelectEntitiesMode.Full, bool generateAllSubthemes = false) { var input = new LingvisticsTextInput() { Text = text, AfterSpellChecking = afterSpellChecking, BaseDate = baseDate, Options = options, Mode = mode, GenerateAllSubthemes = generateAllSubthemes, #if WITH_OM_TM ObjectAllocateMethod = ObjectAllocateMethod.FirstEntityWithTypePronoun, #endif }; return(ProcessText(input)); }
public LingvisticsResult ProcessText(LingvisticsTextInput input) { return(CallLinguisticFunction(f => f.ProcessText(input))); }
private static string GetResultHtml(LocalParams lp) { var lingvisticsInput = new LingvisticsTextInput() { Text = lp.Text, AfterSpellChecking = false, BaseDate = DateTime.Now, Mode = SelectEntitiesMode.Full, GenerateAllSubthemes = false, }; if (lingvisticsInput.Text.IsNullOrWhiteSpace()) { return("<div style='text-align: center; border: 1px silver solid; border-radius: 2px; background: lightgray; color: darkgray; padding: 15px;'>[INPUT TEXT IS EMPTY]</div>"); } try { var html = default(string); #region [.result.] switch (lp.ProcessType) { case ProcessTypeEnum.Digest: #region [.code.] { lingvisticsInput.Options = LingvisticsResultOptions.OpinionMiningWithTonality; var lingvisticResult = LingvisticsWorkInProcessorHelper.ProcessText(lingvisticsInput); html = ConvertToHtml(lp.Context, lingvisticResult.OpinionMiningWithTonalityResult); } #endregion break; case ProcessTypeEnum.TonalityMarking: #region [.code.] { lingvisticsInput.TonalityMarkingInput = new TonalityMarkingInputParams4InProcess(); if (!lp.InquiryText.IsNullOrWhiteSpace()) { lingvisticsInput.TonalityMarkingInput.InquiriesSynonyms = lp.InquiryText.ToTextList(); } lingvisticsInput.ObjectAllocateMethod = lp.ObjectAllocateMethod.GetValueOrDefault(ObjectAllocateMethod.FirstVerbEntityWithRoleObj); lingvisticsInput.Options = LingvisticsResultOptions.Tonality; var lingvisticResult = LingvisticsWorkInProcessorHelper.ProcessText(lingvisticsInput); html = ConvertToHtml(lp.Context, lingvisticResult.TonalityResult, lp.OutputType); } #endregion break; default: throw (new ArgumentException(lp.ProcessType.ToString())); } #endregion if (!lp.IsTextDummy) { Log.Info(ref lp); } return(html); } catch (Exception ex) { Log.Error(ref lp, ex); throw; } }
private static string GetResultHtml(LocalParams lp) { var lingvisticsInput = new LingvisticsTextInput() { Text = lp.Text, AfterSpellChecking = false, BaseDate = DateTime.Now, Mode = SelectEntitiesMode.Full, GenerateAllSubthemes = false, }; try { var html = default(string); #region [.result.] switch (lp.ProcessType) { case ProcessTypeEnum.Digest: #region [.code.] { lingvisticsInput.Options = LingvisticsResultOptions.OpinionMiningWithTonality; var lingvisticResult = ConcurrentFactoryHelper.ProcessText(lingvisticsInput); html = ConvertToHtml(lp.Context, lingvisticResult.OpinionMiningWithTonalityResult); } break; #endregion case ProcessTypeEnum.TonalityMarking: #region [.code.] { lingvisticsInput.TonalityMarkingInput = new TonalityMarkingInputParams4InProcess(); if (!lp.InquiryText.IsNullOrWhiteSpace()) { lingvisticsInput.TonalityMarkingInput.InquiriesSynonyms = lp.InquiryText.ToTextList(); } lingvisticsInput.ObjectAllocateMethod = lp.ObjectAllocateMethod.GetValueOrDefault(ObjectAllocateMethod.FirstVerbEntityWithRoleObj); lingvisticsInput.Options = LingvisticsResultOptions.Tonality; var lingvisticResult = ConcurrentFactoryHelper.ProcessText(lingvisticsInput); html = ConvertToHtml(lp.Context, lingvisticResult.TonalityResult, lp.OutputType); } break; #endregion default: throw (new ArgumentException(lp.ProcessType.ToString())); } #endregion if (!lp.TextIsDummy) { LogManager.GetLogger(string.Empty)?.Info($"'{lp.ProcessType}', TEXT: '{lp.Text}'"); } return(html); } catch (Exception ex) { LogManager.GetLogger(string.Empty)?.Error($"'{lp.ProcessType}', TEXT: '{lp.Text}'", ex); throw; } }
public static LingvisticsResult ProcessText(LingvisticsTextInput input) { return(GetConcurrentFactory().ProcessText(input)); }
public LingvisticsResult ProcessText(LingvisticsTextInput input) { int maxTextSize = Math.Min(input.Text.Length, Config.Default.ProcessorMaxTextSize); //цикл на 2 повтора с уменьшением размера блока, если ни один блок за первый раз не обработан for (int i = 0; i < 2 && 0 < maxTextSize; ++i) { var blockList = (input.Text.Length <= maxTextSize) ? //обработка всего документа за раз new[] { input.Text } : //итерационная обработка документа по частям TextSplitter.Split(input.Text, maxTextSize); Logger.DebugFormat("DocSize={0}, PartCount={1}, i={2}", input.Text.Length, blockList.Length, i); var rcList = blockList.Select(t => { LingvisticsResult result = null; try { //Повтор в случае ошибки [maxRepeatTimes] раз for (int maxRepeatTimes = 1; true; --maxRepeatTimes) { var sw = Stopwatch.StartNew(); var poolItem = _ProcessorPool.GetItem(ProcessingType.Heavy); var totalSecondsGetItem = sw.Elapsed.TotalSeconds; if (Logger.IsDebugEnabled) { Logger.DebugFormat("LoadStatus: {0}", _ProcessorPool.GetLoadingStatus()); } try { var lti = new LingvisticsTextInput(input, t); result = poolItem.ProcessText(lti); break; } catch (System.TimeoutException) { throw; } catch (ApplicationException) { throw; } catch (Exception ex) { Logger.ErrorFormat("Proc({0})\n{1}", poolItem.ProcessID, ex.ToString()); if (0 < maxRepeatTimes) { continue; } throw; } finally { if (poolItem.Busy && !poolItem.Closed) { _ProcessorPool.FreeItem(poolItem); } sw.Stop(); Logger.DebugFormat("Proc({0}) dT={1:F3}c, dT(GetItem)={2:F3}c, dT(Fun)={3:F3}c", poolItem.ProcessID, sw.Elapsed.TotalSeconds, totalSecondsGetItem, sw.Elapsed.TotalSeconds - totalSecondsGetItem); } }//Повтор в случае ошибки [maxRepeatTimes] раз } catch (Exception ex) { Logger.ErrorFormat("TextPart={0}\n{1}", t, ex.Message); throw; } return(new Tuple <LingvisticsResult, string>(result, t)); } ).ToArray(); if (rcList.Any(t => t.Item1 != null)) { //объединение частичных результатов if (1 < blockList.Length) { var rdfIsEmpty = default(bool); var rdf = RDFUnifier.Union(rcList.Select(t => new Tuple <string, int>(((t.Item1 == null) ? null : t.Item1.RDF), t.Item2.Length)), out rdfIsEmpty); var semNet = SemnetUnifier.Union(rcList.Where(t => t.Item1 != null) .Select(t => new Tuple <ThemeItem[], LinkItem[]>(t.Item1.ThemeList, t.Item1.LinkList)) ); #if WITH_OM_TM if ((input.Options & LingvisticsResultOptions.OpinionMiningWithTonality) == LingvisticsResultOptions.OpinionMiningWithTonality) { var opinionMiningWithTonalityResult = TonalityResultUnifier.Union( rcList.Select(t => new Tuple <DigestOutputResult, int>( (t.Item1 == null) ? null : t.Item1.OpinionMiningWithTonalityResult, t.Item2.Length) ) ); return(new LingvisticsResult(input.Options, rdf, semNet.Item1, semNet.Item2, opinionMiningWithTonalityResult)); } else if ((input.Options & LingvisticsResultOptions.Tonality) == LingvisticsResultOptions.Tonality) { var tonalityResult = TonalityResultUnifier.Union(rdf, rdfIsEmpty, rcList.Select(t => (t.Item1 == null) ? null : t.Item1.TonalityResult) ); return(new LingvisticsResult(input.Options, rdf, semNet.Item1, semNet.Item2, tonalityResult)); } #endif return(new LingvisticsResult(input.Options, rdf, semNet.Item1, semNet.Item2)); } else { return(rcList.First().Item1); } } maxTextSize = maxTextSize >> 1; } return(null); }