コード例 #1
0
ファイル: Program.cs プロジェクト: benhauman/storelake
        static int Main(string[] args)
        {
            ConsoleTraceListener listener = new ColoredConsoleTraceListener(false);

            Trace.Listeners.Clear();
            Trace.Listeners.Add(listener); // SharedListeners
            s_tracer.Listeners.Add(listener);

            //s_tracer.Listeners.Add(listener);

            s_tracer.TraceEvent(TraceEventType.Information, 0, "CurrentDirectory: " + Environment.CurrentDirectory);
            s_tracer.TraceEvent(TraceEventType.Information, 0, "FileVersion:" + typeof(Program).Assembly.GetCustomAttribute <AssemblyFileVersionAttribute>().Version);
            try
            {
                ToolArguments targs = StoreLakeSdkTool.ParseArguments(args);
                if (targs == null)
                {
                    s_tracer.TraceEvent(TraceEventType.Information, 0, "USAGE:");
                    s_tracer.TraceEvent(TraceEventType.Information, 0, " StoreLake.Sdk.Cli.exe inputdir=... dacpac=sample.dacpac");
                    return(-2);
                }
                else
                {
                    StoreLakeSdkTool.Run(targs);
                    return(0);
                }
            }
            catch (Exception ex)
            {
                DumpException(ex);
                return(-1);
            }
        }
コード例 #2
0
 public IFirebaseTool  Initialize(ToolArguments arguments)
 {
     ValidateAndStoreApiKey(arguments);
     ValidateAndStoreEmail(arguments);
     ValidateAndStorePassword(arguments);
     return(this);
 }
コード例 #3
0
        private void ValidateAndStoreEmail(ToolArguments arguments)
        {
            if (string.IsNullOrEmpty(arguments.Email))
            {
                throw new ArgumentNullException(nameof(arguments.Email));
            }

            _email = arguments.Email;
        }
コード例 #4
0
        private void ValidateAndStorePassword(ToolArguments arguments)
        {
            if (string.IsNullOrEmpty(arguments.Password))
            {
                throw new ArgumentNullException(nameof(arguments.Password));
            }

            _password = arguments.Password;
        }
コード例 #5
0
        private void ValidateAndStoreApiKey(ToolArguments arguments)
        {
            if (string.IsNullOrEmpty(arguments.ApiKey))
            {
                throw new ArgumentNullException(nameof(arguments.ApiKey));
            }

            _apiKey = arguments.ApiKey;
        }
コード例 #6
0
        private static IFirebaseTool GetSelectedTool(ToolArguments arg)
        {
            IFirebaseTool tool = arg.Mode switch
            {
                ApplicationTool.AuthToken => new AuthTokenTool(),
                _ => throw new ArgumentOutOfRangeException()
            };

            return(tool);
        }
    }
コード例 #7
0
        public static void Main(string[] args)
        {
            ToolArguments parsedArgs = new ToolArguments(args, "None", new MainClass());

            PorterStemmer stemmer = new PorterStemmer();

            if (parsedArgs["stem"] != null)
            {
                Console.WriteLine(parsedArgs["stem"] + " => " + stemmer.stemTerm(parsedArgs["stem"]));
            }

            if (parsedArgs["freqrows"] != null)
            {
                DataReader reader = new DataReader(parsedArgs["f"]);
                for (string[] row = reader.ReadRow(); row != null; row = reader.ReadRow())
                {
                    TwoTuple <int, int> counts = FrequencyTools.WordCount(parsedArgs["freqrows"], row[1]);
                    Console.WriteLine(counts.one + "," + counts.two + ",\"" + row[2] + "\"");
                }
            }

            if (parsedArgs["emotion"] != null)
            {
                ANEWEmotionSensor sensor   = new ANEWEmotionSensor("/Users/jrising/projects/virsona/github/data");
                double[]          emotions = sensor.EstimateEmotions(parsedArgs["emotion"]);
                for (int ii = 0; ii < (int)ANEWEmotionSensor.Emotions.COUNT; ii++)
                {
                    Console.WriteLine(((ANEWEmotionSensor.Emotions)ii).ToString() + ": " + emotions[ii]);
                }
            }

            if (parsedArgs["emorows"] != null)
            {
                int rows = 0, valids = 0;
                ANEWEmotionSensor sensor = new ANEWEmotionSensor("/Users/jrising/projects/virsona/github/data");
                DataReader        reader = new DataReader(parsedArgs["f"]);
                for (string[] row = reader.ReadRow(); row != null; row = reader.ReadRow())
                {
                    rows++;
                    double[] emotions = sensor.EstimateEmotions(row[1]);
                    Console.WriteLine("\"" + row[0] + "\"," + emotions[0] + "," + emotions[1] + "," + emotions[2] + "," + emotions[3] + "," + emotions[4] + "," + emotions[5] + "," + emotions[6] + "," + emotions[7] + ",\"" + row[2] + "\"");
                    if (!double.IsNaN(emotions[0]))
                    {
                        valids++;
                    }
                }
            }
        }
コード例 #8
0
 private static async Task Run(ToolArguments arg)
 {
     try
     {
         var tool = GetSelectedTool(arg);
         tool.Initialize(arg);
         await tool.Run();
     }
     catch (ArgumentNullException e)
     {
         Console.WriteLine($"Argument {e.ParamName} was not provided");
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
コード例 #9
0
        public static void Main(string[] args)
        {
            ToolArguments parsedArgs = new ToolArguments(args, "None", new MainClass());

            PorterStemmer stemmer = new PorterStemmer();

            if (parsedArgs["stem"] != null)
            {
                Console.WriteLine(parsedArgs["stem"] + " => " + stemmer.stemTerm(parsedArgs["stem"]));
            }

            /*ANEWEmotionSensor sensor2 = new ANEWEmotionSensor("/Users/jrising/projects/virsona/github/data");
             * for (int rr = 0; rr < sensor2.positiveMatrix.GetLength(0); rr++) {
             *      for (int cc = 0; cc < sensor2.positiveMatrix.GetLength(1); cc++)
             *              Console.Write(sensor2.positiveMatrix[rr, cc] + ", ");
             *      Console.WriteLine(" - ");
             * }
             * for (int rr = 0; rr < sensor2.negativeMatrix.GetLength(0); rr++) {
             *      for (int cc = 0; cc < sensor2.negativeMatrix.GetLength(1); cc++)
             *              Console.Write(sensor2.negativeMatrix[rr, cc] + ", ");
             *      Console.WriteLine(" - ");
             * }
             * return;*/

            if (parsedArgs["freqrows"] != null)
            {
                DataReader reader = new DataReader(parsedArgs["f"]);
                for (string[] row = reader.ReadRow(); row != null; row = reader.ReadRow())
                {
                    TwoTuple <int, int> counts = FrequencyTools.WordCount(parsedArgs["freqrows"], row[1]);
                    Console.WriteLine(counts.one + "," + counts.two + ",\"" + row[2] + "\"");
                }
            }

            if (parsedArgs["emotion"] != null)
            {
                ANEWEmotionSensor sensor   = new ANEWEmotionSensor("/Users/jrising/projects/virsona/github/data");
                double[]          emotions = sensor.EstimateEmotions(parsedArgs["emotion"]);
                for (int ii = 0; ii < (int)ANEWEmotionSensor.Emotions.COUNT; ii++)
                {
                    Console.WriteLine(((ANEWEmotionSensor.Emotions)ii).ToString() + ": " + emotions[ii]);
                }
            }

            if (parsedArgs["emorows"] != null)
            {
                int rows = 0, valids = 0;
                ANEWEmotionSensor sensor = new ANEWEmotionSensor("/Users/jrising/projects/virsona/github/data");
                DataReader        reader = new DataReader(parsedArgs["f"]);
                for (string[] row = reader.ReadRow(); row != null; row = reader.ReadRow())
                {
                    rows++;
                    double[] emotions = sensor.EstimateEmotions(row[1]);
                    Console.WriteLine("\"" + row[0] + "\"," + emotions[0] + "," + emotions[1] + "," + emotions[2] + "," + emotions[3] + "," + emotions[4] + "," + emotions[5] + "," + emotions[6] + "," + emotions[7] + ",\"" + row[2] + "\"");
                    if (!double.IsNaN(emotions[0]))
                    {
                        valids++;
                    }
                }
            }

            if (parsedArgs["eimpute"] != null)
            {
                ANEWEmotionSensor sensor = new ANEWEmotionSensor("/Users/jrising/projects/virsona/github/data");

                // DIAGNOSTIC

                /*List<List<string>> rows = new List<List<string>>();
                 * rows.Add(TwitterUtilities.SplitWords("happy aaaa cccc"));
                 * rows.Add(TwitterUtilities.SplitWords("sad bbbb cccc"));
                 *
                 * IDataSource<string, ThreeTuple<ContinuousDistribution, ContinuousDistribution, ContinuousDistribution>> inputed = sensor.ImputeEmotionalContent(rows, 1000);
                 * foreach (KeyValuePair<string, ThreeTuple<ContinuousDistribution, ContinuousDistribution, ContinuousDistribution>> kvp in inputed)
                 *      Console.WriteLine(kvp.Key + ": " + kvp.Value.one.Mean + ", " + kvp.Value.two.Mean + ", " + kvp.Value.three.Mean);*/

                bool smallFile = false;
                if (smallFile)
                {
                    DataReader            reader = new DataReader(parsedArgs["f"]);
                    List <List <string> > rows   = new List <List <string> >();
                    for (string[] row = reader.ReadRow(); row != null; row = reader.ReadRow())
                    {
                        Console.WriteLine(row);
                        rows.Add(TwitterUtilities.SplitWords(row[10].ToLower()));
                    }
                    reader.Close();

                    /*IDataSource<string, ThreeTuple<ContinuousDistribution, ContinuousDistribution, ContinuousDistribution>> inputed = sensor.ImputeEmotionalContent(rows, 10);
                     * double minv = 1, maxv = 0;
                     * foreach (KeyValuePair<string, ThreeTuple<ContinuousDistribution, ContinuousDistribution, ContinuousDistribution>> kvp in inputed) {
                     *      minv = Math.Min(minv, kvp.Value.one.Mean);
                     *      maxv = Math.Max(maxv, kvp.Value.one.Mean);
                     *      Console.WriteLine(kvp.Key + ": " + kvp.Value.one.Mean + " x " + kvp.Value.one.Variance + ", " + kvp.Value.two.Mean + ", " + kvp.Value.three.Mean);
                     * }
                     *
                     * Console.WriteLine("Min: " + minv + ", Max: " + maxv);*/

                    sensor.ImputeEmotionalContent(rows, 10, parsedArgs["f"] + "imputed");
                }
                else
                {
                    sensor.ImputeEmotionalContentFromFile(parsedArgs["f"], 11, 0, parsedArgs["f"].Substring(0, parsedArgs["f"].Length - 4) + "imputed.csv");
                }

                uint jj = 0;
                using (var stream = File.CreateText(parsedArgs["f"] + "result")) {
                    jj++;
                    if (jj % 1000 == 0)
                    {
                        Console.WriteLine("#" + jj);
                    }

                    DataReader reader = new DataReader(parsedArgs["f"]);
                    for (string[] row = reader.ReadRow(); row != null; row = reader.ReadRow())
                    {
                        double[] emotions = sensor.EstimateEmotions(row[11]);
                        for (int ii = 0; ii < 11; ii++)
                        {
                            stream.Write(row[ii] + ",");
                        }
                        stream.WriteLine(emotions[0] + "," + emotions[1] + "," + emotions[2] + "," + emotions[3] + "," + emotions[4] + "," + emotions[5] + "," + emotions[6] + "," + emotions[7]);
                    }
                }
            }
        }