示例#1
0
        public static bool TryCreate(Scanner scanner, ILogger logger, out CommandletParserBase parser)
        {
            var anchor = scanner.MakeAnchor();

            if (!scanner.Expect('+'))
            {
                logger.Report(LogLevel.Error, scanner.Pointer.AsRange(scanner.Source), Messages.Error_InstructionExpected);
                parser = null;
                return(false);
            }

            scanner.SkipWhitespaces();

            var  name = scanner.Read(c => char.IsLetterOrDigit(c) || c == '-');
            Type parserType;

            if (!CommandletParsers.TryGetValue(name.ToLowerInvariant(), out parserType))
            {
                logger.Report(LogLevel.Error, scanner.Pointer.AsRange(scanner.Source), Messages.Error_UnknownInstruction);
                parser = null;
                return(false);
            }

            var nameNode = new LiteralNode <string>($"+{name}", anchor.Range);

            parser = (CommandletParserBase)Activator.CreateInstance(parserType);
            parser.CommandletNameNode = nameNode;
            return(true);
        }
示例#2
0
        public void LiteralNodeTest()
        {
            int         a = 1;
            LiteralNode n = new LiteralNode(a);

            Assert.Equal(a, n.Value);
        }
示例#3
0
        public void CreateMainMethod()
        {
            mainMethod = new MethodGraph("Main")
            {
                Class     = cls,
                Modifiers = MethodModifiers.Static
            };

            MethodSpecifier stringLengthSpecifier = new MethodSpecifier("StringLength", new MethodParameter[0], new List <TypeSpecifier>()
            {
                TypeSpecifier.FromType <int>()
            },
                                                                        MethodModifiers.None, MemberVisibility.Public, TypeSpecifier.FromType <string>(), Array.Empty <BaseType>());
            //MethodSpecifier writeConsoleSpecifier = typeof(Console).GetMethods().Single(m => m.Name == "WriteLine" && m.GetParameters().Length == 1 && m.GetParameters()[0].ParameterType == typeof(string));
            TypeSpecifier   stringType            = TypeSpecifier.FromType <string>();
            MethodSpecifier writeConsoleSpecifier = new MethodSpecifier("WriteLine", new MethodParameter[] { new MethodParameter("argName", stringType, MethodParameterPassType.Default, false, null) }, new BaseType[0],
                                                                        MethodModifiers.None, MemberVisibility.Public, TypeSpecifier.FromType(typeof(Console)), new BaseType[0]);

            // Create nodes
            LiteralNode        stringLiteralNode   = LiteralNode.WithValue(mainMethod, "Hello World");
            VariableSetterNode setStringNode       = new VariableSetterNode(mainMethod, new VariableSpecifier("testVariable", TypeSpecifier.FromType <string>(), MemberVisibility.Public, MemberVisibility.Public, cls.Type, VariableModifiers.None));
            CallMethodNode     getStringLengthNode = new CallMethodNode(mainMethod, stringLengthSpecifier);
            CallMethodNode     writeConsoleNode    = new CallMethodNode(mainMethod, writeConsoleSpecifier);

            // Connect node execs
            GraphUtil.ConnectExecPins(mainMethod.EntryNode.InitialExecutionPin, setStringNode.InputExecPins[0]);
            GraphUtil.ConnectExecPins(setStringNode.OutputExecPins[0], getStringLengthNode.InputExecPins[0]);
            GraphUtil.ConnectExecPins(getStringLengthNode.OutputExecPins[0], writeConsoleNode.InputExecPins[0]);
            GraphUtil.ConnectExecPins(writeConsoleNode.OutputExecPins[0], mainMethod.ReturnNodes.First().InputExecPins[0]);

            // Connect node data
            GraphUtil.ConnectDataPins(stringLiteralNode.ValuePin, setStringNode.NewValuePin);
            GraphUtil.ConnectDataPins(getStringLengthNode.OutputDataPins[0], writeConsoleNode.ArgumentPins[0]);
        }
示例#4
0
        public IHtmlNode Build()
        {
            IHtmlNode datagrid = null;
            IHtmlNode div = new HtmlElement("div")
                .Attribute("id", Component.Id)
                .Attributes(Component.HtmlAttributes);
            IHtmlNode script = new HtmlElement("script");

            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("$('#{0}').datagrid(", Component.Id);

            if (Component.Options.Count > 0 ||
                Component.FrozenColumns.Count > 0 ||
                Component.Columns.Count > 0 ||
                Component.ToolBar.Count > 0)
            {
                builder.Append("{ ");
                builder.Append(string.Format("{0}, {1}{2}{3}",
                    Component.Options.ToDataOptionsString(),
                    ConvertColumnsString(Component.FrozenColumns, "frozenColumns"),
                    ConvertColumnsString(Component.Columns, "columns"),
                    ConvertToolbarString(Component.ToolBar)).TrimStart(',').Trim().TrimEnd(','));
                builder.Append(" }");
            }
            builder.Append(");");

            script.Html(builder.ToString());

            datagrid = new LiteralNode(string.Format("{0}\r\n{1}", div.ToString(), script.ToString()));
            return datagrid;
        }
        private Node Literal()
        {
            Token t = _tokens.Current;

            _tokens.MoveNext();
            Node n = null;

            if (t is LeftParenthesis)
            {
                n = expression();
                if (_tokens.Current is RightParenthesis)
                {
                    // ignore right parenthesis
                    _tokens.MoveNext();
                }
                else
                {
                    throw new Exception(string.Format("Malformed expression: expected ')' found {0}", _tokens.Current));
                }
            }
            else if (t is Literal)
            {
                _variables.Add(t.value);
                n = new LiteralNode(t);
            }
            else
            {
                throw new Exception(string.Format("Malformed expression: parsing literal found {0}", _tokens.Current));
            }
            return(n);
        }
        public void GetStatementResultTypeMoneyAndDoubleTest()
        {
            var lhs = new LiteralNode(Location.Empty, "10.0", QValueType.Money);
            var rhs = new LiteralNode(Location.Empty, "5.0", QValueType.Double);

            Assert.AreEqual(QValueType.Money, StatementTypeEvaluator.GetStatementResultType(lhs, rhs));
        }
        public static LiteralNode GetLiteral(JToken jToken, string name, JsonSerializer serializer)
        {
            LiteralNode literalNode = Literal(name, false, null);

            serializer.Populate(jToken.CreateReader(), literalNode);
            return(literalNode);
        }
示例#8
0
        public object Visit(LiteralNode node)
        {
            switch (node.Token.Type)
            {
            case TokenType.IntLiteral:
                return(Convert.ToInt64(node.Token.Value));

            case TokenType.BinLiteral:
                return(Convert.ToInt64(node.Token.Value, 2));

            case TokenType.OctLiteral:
                return(Convert.ToInt64(node.Token.Value, 8));

            case TokenType.HexLiteral:
                return(Convert.ToInt64(node.Token.Value, 16));

            case TokenType.DoubleLiteral:
                return(Convert.ToDouble(node.Token.Value));

            case TokenType.BoolLiteral:
                return(Convert.ToBoolean(node.Token.Value));

            default:
                return(null);
            }
        }
示例#9
0
        public void CreateIfElseMethod()
        {
            List <TypeSpecifier> argumentTypes = new List <TypeSpecifier>()
            {
                TypeSpecifier.FromType <int>(),
                TypeSpecifier.FromType <bool>(),
            };

            List <TypeSpecifier> returnTypes = new List <TypeSpecifier>()
            {
                TypeSpecifier.FromType <int>(),
            };

            // Create method
            ifElseMethod = new Method("IfElse")
            {
                Modifiers = MethodModifiers.Public
            };
            ifElseMethod.ArgumentTypes.AddRange(argumentTypes);
            ifElseMethod.ReturnTypes.AddRange(returnTypes);

            // Create nodes
            IfElseNode  ifElseNode  = new IfElseNode(ifElseMethod);
            LiteralNode literalNode = LiteralNode.WithValue(ifElseMethod, 123);

            // Connect exec nodes
            GraphUtil.ConnectExecPins(ifElseMethod.EntryNode.InitialExecutionPin, ifElseNode.ExecutionPin);
            GraphUtil.ConnectExecPins(ifElseNode.TruePin, ifElseMethod.ReturnNodes.First().ReturnPin);
            GraphUtil.ConnectExecPins(ifElseNode.FalsePin, ifElseMethod.ReturnNodes.First().ReturnPin);

            // Connect node data
            GraphUtil.ConnectDataPins(ifElseMethod.EntryNode.OutputDataPins[1], ifElseNode.ConditionPin);
            GraphUtil.ConnectDataPins(ifElseMethod.EntryNode.OutputDataPins[0], ifElseMethod.ReturnNodes.First().InputDataPins[0]);
            GraphUtil.ConnectDataPins(literalNode.ValuePin, ifElseMethod.ReturnNodes.First().InputDataPins[0]);
        }
示例#10
0
        /// <summary>
        /// Counts the results
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <param name="bindingIDs">Binding IDs over which the Aggregate applies</param>
        /// <returns></returns>
        public override INode Apply(SparqlEvaluationContext context, IEnumerable <int> bindingIDs)
        {
            //Just Count the number of results
            int         c     = bindingIDs.Count();
            LiteralNode count = new LiteralNode(null, c.ToString(), new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger));

            return(count);
        }
        public void ExpressionNodeResultTypeDoubleAndIntTest()
        {
            var lhs        = new LiteralNode(Location.Empty, "10.0", QValueType.Double);
            var rhs        = new LiteralNode(Location.Empty, "5.0", QValueType.Integer);
            var expression = new ArthimetricExpressionNode(Location.Empty, lhs, ArthimetricOperator.Mult, rhs);

            Assert.AreEqual(QValueType.Double, expression.GetQValueType());
        }
示例#12
0
        /// <summary>
        /// Counts the results
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <param name="bindingIDs">Binding IDs over which the Aggregate applies</param>
        /// <returns></returns>
        public override INode Apply(SparqlEvaluationContext context, IEnumerable <int> bindingIDs)
        {
            int c = context.InputMultiset.Sets.Distinct().Count();

            LiteralNode count = new LiteralNode(null, c.ToString(), new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger));

            return(count);
        }
 private static Triple MakeVdsTriple(Model.Triple triple)
 {
     if (triple.IsLiteral)
     {
         LiteralNode literalNode = BrightstarLiteralNode.Create(triple.Object, triple.DataType, triple.LangCode);
         return(new Triple(MakeVdsNode(triple.Subject), MakeVdsNode(triple.Predicate), literalNode));
     }
     return(new Triple(MakeVdsNode(triple.Subject), MakeVdsNode(triple.Predicate), MakeVdsNode(triple.Object)));
 }
示例#14
0
    public void Parse_NegatedLiterals()
    {
        ASTNode root = ExpressionParser.Parse("-6");

        Assert.IsInstanceOf <LiteralNode>(root);
        LiteralNode node = (LiteralNode)root;

        Assert.AreEqual("-6", node.rawValue);
    }
示例#15
0
        override public Node Visit(LiteralNode node)
        {
            if (_literalNodeExpectations.Count > 0)
            {
                _literalNodeExpectations.Dequeue().Invoke(node);
            }

            return(VisitChildren(node));
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            /* Connect To DBPedia
             * //First define a SPARQL Endpoint for DBPedia
             * SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("http://dbpedia.org/sparql"));
             *
             * //Next define our query
             * //We're going to ask DBPedia to describe the first thing it finds which is a Person
             * String query = "DESCRIBE ?person WHERE {?person a <http://dbpedia.org/ontology/Person>} LIMIT 1";
             *
             * //Get the result
             * Graph g = endpoint.QueryWithResultGraph(query);
             *
             * FastRdfXmlWriter rxtw = new FastRdfXmlWriter();
             * rxtw.Save(g, "dbp.txt");*/


            Graph g = new Graph();

            UriNode     omid   = g.CreateUriNode(new Uri("http://www.omidey.co.cc"));
            UriNode     says   = g.CreateUriNode(new Uri("http://www.sample.com/says"));
            LiteralNode hello  = g.CreateLiteralNode("Hello World!!!");
            LiteralNode sallam = g.CreateLiteralNode("Sallam 2nyaaa!!!", "fa");

            g.Assert(new Triple(omid, says, hello));
            g.Assert(new Triple(omid, says, sallam));

            //foreach (Triple t in g.Triples)
            //{
            //    MessageBox.Show(t.ToString());
            //}

            String          query = "SELECT ?n ?p WHERE {?n ?p 'Hello World!!!'}"; // like select * => "SELECT ?n ?p ?m WHERE {?n ?p ?m}"
            SparqlResultSet res   = (SparqlResultSet)g.ExecuteQuery(query);

            foreach (SparqlResult r in res)
            {
                MessageBox.Show(r.ToString());
            }

            FastRdfXmlWriter rxtw = new FastRdfXmlWriter();

            rxtw.Save(g, "omid.txt");

            //TripleStore ts = new TripleStore();
            //Object res = ts.ExecuteQuery("SELECT * WHERE {?s ?p ?o}");
            //if (res is SparqlResultSet)
            //{
            //    SparqlResultSet results = (SparqlResultSet)res;
            //    foreach (SparqlResult sr in results)
            //    {
            //        Console.WriteLine(sr.ToString());
            //    }
            //}
        }
示例#17
0
 private EbiValueBase Evaluate(EbiScope scope, ExpressionNode expr)
 {
     return(expr switch
     {
         LiteralNode l => l.Value,
         IdentifierNode id => scope[id.Name]?.Value ?? throw new RuntimeException($"No such identifier named '{id.Name}'"),
         CallExpressionNode call => Evaluate(scope, call),
         UnaryExpressionNode un => Evaluate(scope, un),
         BinaryExpressionNode bin => Evaluate(scope, bin),
         _ => new EbiNull(),
     });
        public void InValidBoolComparisonTest()
        {
            SymbolTable.Add("TestBool", QValueType.Boolean);
            var left           = new IdentifierNode(new Location(0, 0), "TestBool");
            var right          = new LiteralNode(new Location(0, 0), "false", QValueType.Integer);
            var comparisonNode = new LogicalExpressionNode(new Location(0, 0), left, LogicalOperator.Or, right);

            var analyser = new StatementTypeAnalyser();
            var result   = analyser.Analyse(comparisonNode);

            Assert.IsFalse(result);
        }
        private LiteralNode GetTypeCoercionNode(int index)
        {
            LiteralNode node = FindCoercionType(index);

            // we can't find a literal or predicate to drive the coercion, use defaults
            if (node == null)
            {
                node = GetDefaultCoercionType();
            }

            return(node);
        }
        private Expression CreateDereferenceExpression(ParameterExpression param, int index)
        {
            NodeWithId idNode = FindChild <NodeWithId>(index);

            if (idNode != null)
            {
                LiteralNode node = GetTypeCoercionNode(index); // this is used to coerce the value to the correct type for comparison
                return(ExpressionFactory.CreateReadPropertyExpression(param, idNode.EvaluationId, node.ValueType));
            }

            return(null);
        }
        public void ValidArthimetricComparisonTest()
        {
            SymbolTable.Add("x", QValueType.DOUBLE);
            var x = new IdentifierNode(new Location(0, 0), "x");

            var five            = new LiteralNode(new Location(0, 0), "5", QValueType.INTEGER);
            var arthimetricNode = new ArthimetricExpressionNode(new Location(0, 0), x, ArthimetricOperator.MULT, five);

            var analyser = new StatementTypeAnalyser();
            var result   = analyser.Analyse(arthimetricNode);

            Assert.IsTrue(result);
        }
        public void IntAndDoubleMultiplicationTest()
        {
            SymbolTable.Add("x", QValueType.Integer);
            var x = new IdentifierNode(new Location(0, 0), "x");

            var five            = new LiteralNode(new Location(0, 0), "5.0", QValueType.Double);
            var arthimetricNode = new ArthimetricExpressionNode(new Location(0, 0), x, ArthimetricOperator.Mult, five);

            var analyser = new StatementTypeAnalyser();
            var result   = analyser.Analyse(arthimetricNode);

            Assert.IsTrue(result);
        }
        public void InValidArthimetricComparisonTest()
        {
            SymbolTable.Add("blah blah", QValueType.Text);
            var x = new IdentifierNode(new Location(0, 0), "x");

            var five            = new LiteralNode(new Location(0, 0), "5", QValueType.Integer);
            var arthimetricNode = new ArthimetricExpressionNode(new Location(0, 0), x, ArthimetricOperator.Mult, five);

            var analyser = new StatementTypeAnalyser();
            var result   = analyser.Analyse(arthimetricNode);

            Assert.IsFalse(result);
        }
示例#24
0
        public static bool TryReadNoteRepetition(Scanner scanner, ILogger logger,
                                                 out LiteralNode <NoteRepetition> ornament)
        {
            switch (scanner.ReadAnyPatternOf("tremolo"))
            {
            case "tremolo":
                ornament = new LiteralNode <NoteRepetition>(NoteRepetition.Tremolo, scanner.LastReadRange);
                return(true);
            }

            ornament = null;
            return(false);
        }
示例#25
0
        public static bool TryReadInteger(Scanner scanner, out LiteralNode <int> node)
        {
            int value;

            if (!scanner.TryReadInteger(out value))
            {
                node = null;
                return(false);
            }

            node = new LiteralNode <int>(value, scanner.LastReadRange);
            return(true);
        }
示例#26
0
        /// <summary>
        /// Counts the results
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <param name="bindingIDs">Binding IDs over which the Aggregate applies</param>
        /// <returns></returns>
        public override INode Apply(SparqlEvaluationContext context, IEnumerable <int> bindingIDs)
        {
            int          c;
            List <INode> values = new List <INode>();

            if (this._varname != null)
            {
                //Ensure the COUNTed variable is in the Variables of the Results
                if (!context.Binder.Variables.Contains(this._varname))
                {
                    throw new RdfQueryException("Cannot use the Variable " + this._expr.ToString() + " in a COUNT Aggregate since the Variable does not occur in a Graph Pattern");
                }

                //Just Count the number of results where the variable is bound
                VariableExpressionTerm varExpr = (VariableExpressionTerm)this._expr;

                foreach (int id in bindingIDs)
                {
                    INode temp = varExpr.Value(context, id);
                    if (temp != null)
                    {
                        values.Add(temp);
                    }
                }
                c = values.Distinct().Count();
            }
            else
            {
                //Count the distinct non-null results
                foreach (int id in bindingIDs)
                {
                    try
                    {
                        INode temp = this._expr.Value(context, id);
                        if (temp != null)
                        {
                            values.Add(temp);
                        }
                    }
                    catch
                    {
                        //Ignore errors
                    }
                }
                c = values.Distinct().Count();
            }

            LiteralNode count = new LiteralNode(null, c.ToString(), new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger));

            return(count);
        }
示例#27
0
        private static LiteralNode FoldTheDreadedAddition(LiteralNode op1, LiteralNode op2)
        {
            Interval interval = new Interval(op1.Interval.a, op2.Interval.b);

            //Aye.
            IntegerLiteralNode int1 = op1 as IntegerLiteralNode;
            IntegerLiteralNode int2 = op2 as IntegerLiteralNode;
            RealLiteralNode    rea1 = op1 as RealLiteralNode;
            RealLiteralNode    rea2 = op2 as RealLiteralNode;
            StringLiteralNode  str1 = op1 as StringLiteralNode;
            StringLiteralNode  str2 = op2 as StringLiteralNode;

            if (int1 != null && int2 != null)
            {
                int result = int1.Value + int2.Value;
                return(CrawlSyntaxNode.IntegerLiteral(interval, CrawlSimpleType.Tal, result));
            }
            if (str1 != null && str2 != null)
            {
                string result = str1.Value + str2.Value;
                return(CrawlSyntaxNode.StringLiteral(interval, CrawlSimpleType.Tekst, result));
            }
            if (rea1 != null && rea2 != null)
            {
                double result = rea1.Value + rea2.Value;
                return(CrawlSyntaxNode.RealLiteral(interval, CrawlSimpleType.Kommatal, result));
            }
            //Hvis de er forskellige, se om a kan tildeles til b, hvis ja,  konverter a til b's type
            //Hvis stadig ikke se om b kan tildeles til a, hvis ja, konverter b til a's type
            if (str1 != null)
            {
                string result = str1.Value + (int2?.Value.ToString() ?? rea2?.Value.ToString(CultureInfo.GetCultureInfo("en-GB")));
                return(CrawlSyntaxNode.StringLiteral(interval, CrawlSimpleType.Tekst, result));
            }
            if (str2 != null)
            {
                string result = (int1?.Value.ToString() ?? rea1?.Value.ToString(CultureInfo.GetCultureInfo("en-GB"))) + str2.Value;
                return(CrawlSyntaxNode.StringLiteral(interval, CrawlSimpleType.Tekst, result));
            }
            if (rea1 != null)
            {
                double result = rea1.Value + int2.Value;
                return(CrawlSyntaxNode.RealLiteral(interval, CrawlSimpleType.Kommatal, result));
            }
            if (rea2 != null)
            {
                double result = int1.Value + rea2.Value;
                return(CrawlSyntaxNode.RealLiteral(interval, CrawlSimpleType.Kommatal, result));
            }
            throw new NullReferenceException();
        }
示例#28
0
        private static void Walk([NotNull] Agent agent, [NotNull] LiteralNode literal, bool isStrict)
        {
            if (isStrict && literal.Value.IsDouble && octalRegex.IsMatch(literal.Raw))
            {
                throw agent.CreateSyntaxError();
            }

            if (isStrict && literal.Value.IsString)
            {
                for (var i = 0; i < literal.Raw.Length; i++)
                {
                    var c = literal.Raw[i];
                    if (c == '\\')
                    {
                        var next = literal.Raw[i + 1];
                        switch (next)
                        {
                        case 'n':
                        case 'r':
                        case 'x':
                        case 'u':
                        case 't':
                        case 'b':
                        case 'v':
                        case 'f':
                        case '\n':
                        case '\r':
                            i++;
                            break;

                        default:
                            if (next >= 48 && next <= 55)
                            {
                                var nextNext = literal.Raw[i + 2];
                                if (next == '0' && !char.IsDigit(nextNext))
                                {
                                    i++;
                                    break;
                                }

                                throw agent.CreateSyntaxError();
                            }

                            i++;
                            break;
                        }
                    }
                }
            }
        }
示例#29
0
        //Lot of swithces here. You want to have an editor that can collapse stuff.

        private static double GetNumber(LiteralNode node)
        {
            switch (node.Type)
            {
            case NodeType.IntegerLiteral:
                return(((IntegerLiteralNode)node).Value);

            case NodeType.RealLiteral:
                return(((RealLiteralNode)node).Value);

            default:
                throw new Exception("Type error where no type error should be.");
            }
        }
示例#30
0
        private bool?evalBooleanOperation(Node operation, Node lValue, Node rValue)
        {
            if (operation is FinalNode)
            {
                string opType = ((FinalNode)operation).dataString();
                string lvalueString;

                switch (opType)
                {
                case "==":

                    if (lValue is FinalNode)
                    {
                        lvalueString = ((FinalNode)lValue).dataString();
                    }
                    else if (lValue is LiteralNode)
                    {
                        LiteralNode literalNode = (LiteralNode)lValue.Instructions[0];
                        // lvalueString = (LiteralNode)literalNode.getInstructions().get( 0 );
                    }

                    break;

                case ">=":
                    break;

                case "<=":
                    break;

                case "&&":
                    if (lValue is FinalNode)
                    {
                        lvalueString = ((FinalNode)lValue).dataString();
                    }
                    else if (lValue is LiteralNode)
                    {
                        LiteralNode literalNode = (LiteralNode)lValue.Instructions[0];
                        // lvalueString = (LiteralNode)literalNode.getInstructions().get( 0 );
                    }

                    //if ( )
                    break;

                case "||":
                    break;
                }
            }

            return(false);
        }
示例#31
0
        public static bool TryReadStaffType(Scanner scanner, ILogger logger, out LiteralNode <StaffType> staffTypeNode)
        {
            StaffType staffType;

            switch (scanner.ReadToLineEnd().Trim().ToLowerInvariant())
            {
            case "guitar":
            case "acoustic guitar":
                staffType = StaffType.Guitar; break;

            case "steel":
            case "steel guitar":
                staffType = StaffType.SteelGuitar; break;

            case "nylon":
            case "nylon guitar":
            case "classical":
            case "classical guitar":
                staffType = StaffType.NylonGuitar; break;

            case "electric guitar":
                staffType = StaffType.ElectricGuitar; break;

            case "bass":
                staffType = StaffType.Bass; break;

            case "acoustic bass":
                staffType = StaffType.AcousticBass; break;

            case "electric bass":
                staffType = StaffType.ElectricBass; break;

            case "ukulele":
            case "uku":
                staffType = StaffType.Ukulele; break;

            case "mandolin":
                staffType = StaffType.Mandolin; break;

            case "vocal":
                staffType = StaffType.Vocal; break;

            default:
                staffTypeNode = null;
                return(false);
            }

            staffTypeNode = new LiteralNode <StaffType>(staffType, scanner.LastReadRange);
            return(true);
        }
        protected override IHtmlNode BuildCore()
        {
            var div = new HtmlTag("div")
                        .AddClass("t-page-i-of-n");

            var page = new LiteralNode(localization.Page);

            page.AppendTo(div);

            var input = new HtmlTag("input")
                            .Attribute("type", "text")
                            .Attribute("value", Value);

            input.AppendTo(div);

            var of = new LiteralNode(string.Format(localization.PageOf, TotalPages));

            of.AppendTo(div);

            return div;
        }
        public IHtmlNode Create(GridPagerData section)
        {
            var div = new HtmlElement("div")
                .AddClass("t-page-i-of-n");

            var page = new LiteralNode(section.PageText);

            page.AppendTo(div);

            var input = new HtmlElement("input", TagRenderMode.SelfClosing)
                .Attribute("type", "text")
                .Attribute("value", section.CurrentPage.ToString());

            input.AppendTo(div);

            var of = new LiteralNode(string.Format(section.PageOfText, section.PageCount));

            of.AppendTo(div);

            return div;
        }
        public IHtmlNode Create(GridPagerData section)
        {
            var span = new HtmlElement("span")
                .AddClass("k-pager-input", "k-label");

            var page = new LiteralNode(section.Messages.Page);

            page.AppendTo(span);

            var input = new HtmlElement("input", TagRenderMode.SelfClosing)
                .Attribute("type", "text")
                .AddClass("k-textbox")
                .Attribute("value", section.Page.ToString());

            input.AppendTo(span);

            var of = new LiteralNode(string.Format(section.Messages.Of, section.TotalPages));

            of.AppendTo(span);

            return span;
        }
示例#35
0
        /// <summary>
        /// Counts the results
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <param name="bindingIDs">Binding IDs over which the Aggregate applies</param>
        /// <returns></returns>
        public override INode Apply(SparqlEvaluationContext context, IEnumerable<int> bindingIDs)
        {
            int c = context.InputMultiset.Sets.Distinct().Count();

            LiteralNode count = new LiteralNode(null, c.ToString(), new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger));
            return count;
        }
 /// <summary>
 ///   Gets the value of the function in the given Evaluation Context for the given Binding ID
 /// </summary>
 /// <param name = "context">Evaluation Context</param>
 /// <param name = "bindingID">Binding ID</param>
 /// <returns>
 ///   Returns a constant Literal Node which is a Date Time typed Literal
 /// </returns>
 public override INode Value(SparqlEvaluationContext context, int bindingID)
 {
     if (_currQuery == null)
     {
         _currQuery = context.Query;
     }
     if (_node == null || !ReferenceEquals(_currQuery, context.Query))
     {
         _node = new LiteralNode(null, DateTime.Now.ToString(XmlSpecsHelper.XmlSchemaDateTimeFormat),
                                 new Uri(XmlSpecsHelper.XmlSchemaDataTypeDateTime));
         _ebv = false;
     }
     return _node;
 }
        private Node Literal()
        {
            Token t = _tokens.Current;
            _tokens.MoveNext();
            Node n = null;
            if (t is LeftParenthesis)
            {
                n = expression();
                if (_tokens.Current is RightParenthesis)
                {
                    // ignore right parenthesis
                    _tokens.MoveNext();
                }
                else
                {
                    throw new Exception(string.Format("Malformed expression: expected ')' found {0}",_tokens.Current));
                }

            }
            else if (t is Literal)
            {
                _variables.Add(t.value);
                n = new LiteralNode(t);
            }
            else
            {
                throw new Exception(string.Format("Malformed expression: parsing literal found {0}",_tokens.Current));
            }
            return n;
        }
 public void Apply(IHtmlNode parent)
 {
     var text = new LiteralNode(button.Text);
     text.AppendTo(parent);
 }
示例#39
0
        /// <summary>
        /// Counts the results
        /// </summary>
        /// <param name="context">Evaluation Context</param>
        /// <param name="bindingIDs">Binding IDs over which the Aggregate applies</param>
        /// <returns></returns>
        public override INode Apply(SparqlEvaluationContext context, IEnumerable<int> bindingIDs)
        {
            int c;
            List <INode> values = new List<INode>();

            if (this._varname != null)
            {
                //Ensure the COUNTed variable is in the Variables of the Results
                if (!context.Binder.Variables.Contains(this._varname))
                {
                    throw new RdfQueryException("Cannot use the Variable " + this._expr.ToString() + " in a COUNT Aggregate since the Variable does not occur in a Graph Pattern");
                }

                //Just Count the number of results where the variable is bound
                VariableExpressionTerm varExpr = (VariableExpressionTerm)this._expr;

                foreach (int id in bindingIDs)
                {
                    INode temp = varExpr.Value(context, id);
                    if (temp != null)
                    {
                        values.Add(temp);
                    }
                }
                c = values.Distinct().Count();
            }
            else
            {
                //Count the distinct non-null results
                foreach (int id in bindingIDs)
                {
                    try
                    {
                        INode temp = this._expr.Value(context, id);
                        if (temp != null)
                        {
                            values.Add(temp);
                        }
                    }
                    catch
                    {
                        //Ignore errors
                    }
                }
                c = values.Distinct().Count();
            }

            LiteralNode count = new LiteralNode(null, c.ToString(), new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger));
            return count;
        }
示例#40
0
 /// <summary>
 /// Counts the results
 /// </summary>
 /// <param name="context">Evaluation Context</param>
 /// <param name="bindingIDs">Binding IDs over which the Aggregate applies</param>
 /// <returns></returns>
 public override INode Apply(SparqlEvaluationContext context, IEnumerable<int> bindingIDs)
 {
     //Just Count the number of results
     int c = bindingIDs.Count();
     LiteralNode count = new LiteralNode(null, c.ToString(), new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger));
     return count;
 }
 private FormatRenderer CreateLiteral(LiteralNode node)
 {
     return new LiteralRenderer(node.Literal);
 }
示例#42
0
        private Uri TryParseContext(ITokenQueue tokens)
        {
            IToken next = tokens.Dequeue();
            if (next.TokenType == Token.DOT)
            {
                return null;
            }
            else
            {
                INode context;
                switch (next.TokenType)
                {
                    case Token.BLANKNODEWITHID:
                        context = new BlankNode(null, next.Value.Substring(2));
                        break;
                    case Token.URI:
                        context = new UriNode(null, new Uri(next.Value));
                        break;
                    case Token.LITERAL:
                        //Check for Datatype/Language
                        IToken temp = tokens.Peek();
                        if (temp.TokenType == Token.LANGSPEC)
                        {
                            tokens.Dequeue();
                            context = new LiteralNode(null, next.Value, temp.Value);
                        }
                        else if (temp.TokenType == Token.DATATYPE)
                        {
                            tokens.Dequeue();
                            context = new LiteralNode(null, next.Value, new Uri(temp.Value.Substring(1, temp.Value.Length - 2)));
                        }
                        else
                        {
                            context = new LiteralNode(null, next.Value);
                        }
                        break;
                    default:
                        throw ParserHelper.Error("Unexpected Token '" + next.GetType().ToString() + "' encountered, expected a Blank Node/Literal/URI as the Context of the Triple", next);
                }

                //Ensure we then see a . to terminate the Quad
                next = tokens.Dequeue();
                if (next.TokenType != Token.DOT)
                {
                    throw ParserHelper.Error("Unexpected Token '" + next.GetType().ToString() + "' encountered, expected a Dot Token (Line Terminator) to terminate a Triple", next);
                }

                //Finally return the Context URI
                if (context.NodeType == NodeType.Uri)
                {
                    return ((IUriNode)context).Uri;
                }
                else if (context.NodeType == NodeType.Blank)
                {
                    return new Uri("nquads:bnode:" + context.GetHashCode());
                }
                else if (context.NodeType == NodeType.Literal)
                {
                    return new Uri("nquads:literal:" + context.GetHashCode());
                }
                else
                {
                    throw ParserHelper.Error("Cannot turn a Node of type '" + context.GetType().ToString() + "' into a Context URI for a Triple", next);
                }
            }
        }
示例#43
0
 /// <summary>
 /// Returns the LiteralNode with the given Value and given Data Type if it exists
 /// </summary>
 /// <param name="literal">The literal value of the Node to select</param>
 /// <param name="datatype">The Uri for the Data Type of the Literal to select</param>
 /// <returns>Either the LiteralNode Or null if no Node with the given Value and Data Type exists</returns>
 public override ILiteralNode GetLiteralNode(String literal, Uri datatype)
 {
     ILiteralNode test = new LiteralNode(this, literal, datatype);
     IEnumerable<ILiteralNode> ls = from l in this._nodes.LiteralNodes
                                   where l.Equals(test)
                                   select l;
     return ls.FirstOrDefault();
 }
示例#44
0
 public OperatorNode(LiteralNode left, LiteralNode right, string operatorString)
 {
     _left = left;
     _right = right;
     _operator = operatorString;
 }
 public LiteralNodeViewModel(LiteralNode graphItemObject, Invert.Core.GraphDesigner.DiagramViewModel diagramViewModel) : 
         base(graphItemObject, diagramViewModel) {
 }
示例#46
0
        /// <summary>
        /// Copies a Node so it can be used in another Graph since by default Triples cannot contain Nodes from more than one Graph
        /// </summary>
        /// <param name="original">Node to Copy</param>
        /// <param name="target">Graph to Copy into</param>
        /// <returns></returns>
        /// <remarks>
        /// <para>
        /// <strong>Warning:</strong> Copying Blank Nodes may lead to unforseen circumstances since no remapping of IDs between Graphs is done
        /// </para>
        /// </remarks>
        public static INode CopyNode(INode original, IGraph target)
        {
            //No need to copy if it's already in the relevant Graph
            if (ReferenceEquals(original.Graph, target)) return original;

            if (original.NodeType == NodeType.Uri)
            {
                IUriNode u = (IUriNode)original;
                IUriNode u2 = new UriNode(target, u.Uri);

                return u2;
            }
            else if (original.NodeType == NodeType.Literal)
            {
                ILiteralNode l = (ILiteralNode)original;
                ILiteralNode l2;
                if (l.Language.Equals(String.Empty))
                {
                    if (!(l.DataType == null))
                    {
                        l2 = new LiteralNode(target, l.Value, l.DataType);
                    }
                    else
                    {
                        l2 = new LiteralNode(target, l.Value);
                    }
                }
                else
                {
                    l2 = new LiteralNode(target, l.Value, l.Language);
                }

                return l2;
            }
            else if (original.NodeType == NodeType.Blank)
            {
                IBlankNode b = (IBlankNode)original;
                IBlankNode b2;

                b2 = new BlankNode(target, b.InternalID);
                return b2;
            }
            else if (original.NodeType == NodeType.Variable)
            {
                IVariableNode v = (IVariableNode)original;
                return new VariableNode(target, v.VariableName);
            }
            else
            {
                throw new RdfException("Unable to Copy '" + original.GetType().ToString() + "' Nodes between Graphs");
            }
        }