Пример #1
0
        public virtual void Annotate(Annotation annotation)
        {
            if (verbose)
            {
                System.Console.Out.WriteLine("Adding column data classifier annotation...");
            }
            string text = DummyLabelColumn + annotation.Get(typeof(CoreAnnotations.TextAnnotation));

            if (verbose)
            {
                System.Console.Out.WriteLine("Dummy column: " + text);
            }
            // todo [cdm 2016]: At the moment this is hardwired to only work with answer = col 0, datum = col 1 classifier
            IDatum <string, string> datum = cdcClassifier.MakeDatumFromLine(text);

            if (verbose)
            {
                System.Console.Out.WriteLine("Datum: " + datum.ToString());
            }
            string label = cdcClassifier.ClassOf(datum);

            annotation.Set(typeof(CoreAnnotations.ColumnDataClassifierAnnotation), label);
            if (verbose)
            {
                System.Console.Out.WriteLine(string.Format("annotation=%s", annotation.Get(typeof(CoreAnnotations.ColumnDataClassifierAnnotation))));
            }
            if (verbose)
            {
                System.Console.Out.WriteLine("Done.");
            }
        }
Пример #2
0
 /// <summary>
 /// 可读描述
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("Datum: " + Datum.ToString() + ", CoordSystem:" + CoordinateSystem.ToString());
 }
Пример #3
0
        static void Main(string[] args)
        {
            var    parser = new Parser();
            string expr   = "";


            // add C-c keyboard event listener
            Console.CancelKeyPress += new ConsoleCancelEventHandler(CancelKeyPress);

            // first load std.lisp
            var lex = new Lexer(File.ReadAllText("std.lisp"));

            Evaluator.Eval(parser.Parse(lex.Tokenize()));

            // then load repl.lisp
            lex = new Lexer(File.ReadAllText("repl.lisp"));
            Evaluator.Eval(parser.Parse(lex.Tokenize()));

            // then load test.lisp
            lex = new Lexer(File.ReadAllText("test.lisp"));
            Evaluator.Eval(parser.Parse(lex.Tokenize()));

            Evaluator.environment.Add("*prompt*", new Atom("mslisp"));

            // repl
            while (true)
            {
                try
                {
                    IDatum prompt = Evaluator.environment["*prompt*"];
                    Console.Write(string.Format("{0}> ", (string)prompt.Value));

                    expr += Console.ReadLine();

                    // todo: need a better way to count parenthesis
                    var open  = expr.Count(c => c == '(');
                    var close = expr.Count(c => c == ')');

                    if (open != close)
                    {
                        continue;
                    }


                    // have lexer count parens?
                    // lexer should count line numbers.
                    var lexer  = new Lexer(expr);
                    var tokens = parser.Parse(lexer.Tokenize());

                    // eval and print
                    tokens.ForEach((list) =>
                    {
                        IDatum eval = Evaluator.Eval(list, Evaluator.environment);
                        Console.WriteLine(eval.ToString());
                    });


                    // cleanup
                    expr = "";
                }
                catch (MsLisp.ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                    expr = "";
                }
                catch (SyntaxException ex)
                {
                    Console.WriteLine(ex.Message);
                    expr = "";
                }
                catch (TypeException ex)
                {
                    Console.WriteLine(ex.Message);
                    expr = "";
                }
                catch (Exception ex)
                {
                    ReplError(ex);
                    expr = "";
                }
            }
        }
Пример #4
0
 public void Stringify(string s, IDatum datum)
 {
     Assert.AreEqual(s, datum.ToString());
 }