Ejemplo n.º 1
0
        public static void ErrorEx(this ILog log, string methodName, Exception ex, string clientRemoteAddress, InputParamsBase inputParams, XDocument xdocument)
        {
            var value = ("{0}]. ").FormatEx(Interlocked.Increment(ref _TotalLogCount)) +
                        ("{0} => '{1}': '{2}'").FormatEx(methodName, ex.GetType().Name, ex.Message) +
                        ("\r\n\t ClientRemoteAddress: {0}").FormatEx(clientRemoteAddress) +
                        ("\r\n\t Input text (length: {0}): ").FormatEx(inputParams.InputText.Length) +
                        inputParams.InputText.InSingleQuote() +
                        ((xdocument != null) ? ("\r\n\t XML: [\r\n{0}\r\n]").FormatEx(xdocument.ToString()) : string.Empty);

            log.Error(value, ex);

        #if DEBUG
            lock ( _SynRoot )
            {
                var fc = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(Environment.NewLine + value + Environment.NewLine + Environment.NewLine + ex.GetType().Name + " => " + ex.ToString());
                Console.ForegroundColor = fc;
                Console.WriteLine(RuleBase.GetDebugInfoOutput());
            }
        #endif
        }
Ejemplo n.º 2
0
        public static void InfoEx(this ILog log, string methodName, string clientRemoteAddress, TimeSpan linguisticElapsed, TimeSpan opinionMiningElapsed, InputParamsBase inputParams)
        {
            var value = Interlocked.Increment(ref _TotalLogCount) + "]. " +
                        methodName + " => \r\n\t ClientRemoteAddress: " + clientRemoteAddress +
                        "\r\n\t Linguistic     processing time: " + linguisticElapsed +
                        "\r\n\t Opinion-mining processing time: " + opinionMiningElapsed +
                        "\r\n\t Input text (length: {0}): ".FormatEx(inputParams.InputText.Length) +
                        inputParams.InputText.Get4Log();

            log.Info(value);

        #if DEBUG
            lock ( _SynRoot )
            {
                var fc = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(Environment.NewLine + value);
                Console.ForegroundColor = fc;
                Console.WriteLine(RuleBase.GetDebugInfoOutput());
            }
        #endif
        }
        public OpinionMiningOutputResult ExecuteOpinionMining(OpinionMiningInputParams inputParams)
        {
            var xdocument = default(XDocument);

            try
            {
                #region [.check input.]
                inputParams.ThrowIfNull("inputParams");
                #endregion

                #region [.Linguistic.]
                var linguisticStopwatch = Stopwatch.StartNew();
                switch (inputParams.InputTextFormat)
                {
                case InputTextFormat.PlainText:
                    xdocument = LinguisticsDecorator.ProcessText(inputParams);
                    break;

                case InputTextFormat.LinguisticXml:
                    xdocument = Algorithms.PreprocessRdf(inputParams.InputText);
                    break;

                default:
                    throw (new ArgumentException(inputParams.InputTextFormat.ToString()));
                }
                linguisticStopwatch.Stop();

                if (!xdocument.Root.HasElements)
                {
                    throw (new ArgumentException("Linguistics returned empty xml."));
                }
                #endregion

                #region [.read coreference-info from Rdf.]
                var coreferenceInfo = _CoreferenceResolver.ReadFromRdf(xdocument.Root);
                #endregion

                #region [.Opinion-mining.]
                var opinionMiningStopwatch = Stopwatch.StartNew();

                var opinionMiningTuples = ExecuteInternal(xdocument, inputParams, coreferenceInfo);

                opinionMiningStopwatch.Stop();
                #endregion

                #region [.write in log.]
                LOG.InfoEx(MethodBase.GetCurrentMethod().Name, WcfHelper.ClientRemoteAddress, linguisticStopwatch.Elapsed, opinionMiningStopwatch.Elapsed, inputParams);
                #endregion

                #region [.result.]
                var opinionMiningOutputResult = new OpinionMiningOutputResult
                                                (
                    opinionMiningTuples,
                    RuleBase.GetOperateRulesNamesDebugInfoOutput()
                                                );

                return(opinionMiningOutputResult);

                #endregion
            }
            catch (Exception ex)
            {
                #region [.write error in log & rethrow.]
                LOG.ErrorEx(MethodBase.GetCurrentMethod().Name, ex, WcfHelper.ClientRemoteAddress, inputParams, xdocument);
                throw;
                #endregion
            }
        }
        public static OpinionMiningOutputResult ExecuteOpinionMiningInprocWithLinguisticService(
            XDocument rdf, bool callPreprocessRdf, ObjectAllocateMethod objectAllocateMethod, ICoreferenceInfo coreferenceInfo)
        {
            #region [.check input.]
            rdf.ThrowIfNull("rdf");
            if (!rdf.Root.HasElements)
            {
                throw (new ArgumentException("Input linguistics-RDF is empty."));
            }
            #endregion

            #region [.Opinion-mining.]
            if (callPreprocessRdf)
            {
                rdf = Algorithms.PreprocessRdf(rdf);
            }

            var inputParams = new OpinionMiningInputParams("[NEVER MIND]", InputTextFormat.LinguisticXml)
            {
                ObjectAllocateMethod = objectAllocateMethod
            };

            var opinionMiningTuples = ExecuteInternal(rdf, inputParams, coreferenceInfo);
            #endregion

            #region [.result.]
            var opinionMiningOutputResult = new OpinionMiningOutputResult(opinionMiningTuples, RuleBase.GetOperateRulesNamesDebugInfoOutput());
            return(opinionMiningOutputResult);

            #endregion
        }