Example #1
0
        protected void printStringFrom(ISparqlPrinter context)
        {
            IEnumerable <INode> froms = getFrom();

            if (froms.Count() == 0)
            {
                froms = context.Dataset.DefaultGraphs;
            }
            foreach (IResource from in froms)
            {
                context.println();
                context.printKeyword("FROM");
                context.printURIResource(from);
            }
            froms = getFromNamed();
            if (froms.Count() == 0)
            {
                froms = context.Dataset.DefaultGraphs;
            }
            foreach (IResource fromNamed in froms)
            {
                context.println();
                context.printKeyword("FROM NAMED");
                context.printURIResource(fromNamed);
            }
        }
Example #2
0
        public override void printSPINRDF(ISparqlPrinter p)
        {
            printComment(p);
            printPrefixes(p);

            IResource iri = getResource(SP.PropertyGraphIRI);

            IResource with = getResource(SP.PropertyWith);

            if (with != null)
            {
                p.printIndentation(p.getIndentation());
                p.printKeyword("WITH");
                p.print(" ");
                p.printURIResource(with);
                p.println();
            }

            // TODO add a INSERT/CONSTRUCT pattern before the delete is effective
            if (printTemplates(p, SP.PropertyDeletePattern, "DELETE", hasProperty(SP.PropertyDeletePattern), iri))
            {
                p.print("\n");
            }
            if (printTemplates(p, SP.PropertyInsertPattern, "INSERT", hasProperty(SP.PropertyInsertPattern), iri))
            {
                p.print("\n");
            }

            IEnumerable <INode> usings = getUsing();

            if (usings.Count() == 0)
            {
                usings = p.Dataset.DefaultGraphs;
            }
            foreach (IResource _using in usings)
            {
                p.printKeyword("USING");
                p.print(" ");
                p.printURIResource(_using);
                p.println();
            }

            usings = getUsingNamed();
            if (usings.Count() == 0)
            {
                usings = p.Dataset.ActiveGraphs;
            }
            foreach (IResource usingNamed in usings)
            {
                p.printKeyword("USING");
                p.print(" ");
                p.printKeyword("NAMED");
                p.print(" ");
                p.printURIResource(usingNamed);
                p.println();
            }
            p.CurrentSparqlContext = SparqlContext.QueryContext;
            printWhere(p);
        }
Example #3
0
        protected void printGraphIRIs(ISparqlPrinter p, String keyword)
        {
            List <String> graphIRIs = new List <String>();

            {
                IEnumerator <Triple> it = listProperties(SP.PropertyGraphIRI).GetEnumerator();
                while (it.MoveNext())
                {
                    Triple s = it.Current;
                    if (s.Object is IUriNode)
                    {
                        graphIRIs.Add(((IUriNode)s.Object).Uri.ToString());
                    }
                }
                graphIRIs.Sort();
            }
            foreach (String graphIRI in graphIRIs)
            {
                p.print(" ");
                if (keyword != null)
                {
                    p.printKeyword(keyword);
                    p.print(" ");
                }
                p.printURIResource(Resource.Get(RDFUtil.CreateUriNode(UriFactory.Create(graphIRI)), getModel()));
            }
        }
Example #4
0
 override public void printSPINRDF(ISparqlPrinter p)
 {
     p.printKeyword("CREATE");
     p.print(" ");
     printSilent(p);
     p.printKeyword("GRAPH");
     p.print(" ");
     p.printURIResource(getResource(SP.PropertyGraphIRI));
 }
Example #5
0
        override public void Print(ISparqlPrinter p)
        {
            IVariable asVar = getAs();

            if (asVar != null)
            {
                p.print("(");
            }

            INode  aggType = this.getObject(RDF.PropertyType);
            String aggName = Aggregations.getName(aggType);

            p.printKeyword(aggName);
            p.print("(");

            if (isDistinct())
            {
                p.print("DISTINCT ");
            }

            Triple exprS = this.getProperty(SP.PropertyExpression);

            if (exprS != null && !(exprS.Object is ILiteralNode))
            {
                IResource r    = Resource.Get(exprS.Object, getModel());
                IResource expr = SPINFactory.asExpression(r);
                if (expr is IPrintable)
                {
                    ((IPrintable)expr).Print(p);
                }
                else
                {
                    p.printURIResource(r);
                }
            }
            else
            {
                p.print("*");
            }
            String separator = getString(SP.PropertySeparator);

            if (separator != null)
            {
                p.print("; ");
                p.printKeyword("SEPARATOR");
                p.print("=''"); //"='" + DatasetUtil.escapeString(separator) + "'");
            }
            if (asVar != null)
            {
                p.print(") ");
                p.printKeyword("AS");
                p.print(" ");
                p.print(asVar.ToString());
            }
            p.print(")");
        }
Example #6
0
        override public void printSPINRDF(ISparqlPrinter p)
        {
            p.printKeyword("LOAD");
            p.print(" ");
            printSilent(p);
            IResource document = getResource(SP.PropertyDocument);

            p.printURIResource(document);
            IResource into = getResource(SP.PropertyInto);

            if (into != null)
            {
                p.print(" ");
                p.printKeyword("INTO");
                p.print(" ");
                p.printKeyword("GRAPH");
                p.print(" ");
                p.printURIResource(into);
            }
        }
        private void printFunctionQName(ISparqlPrinter p, IResource function)
        {
            String symbol = getSymbol(function);

            if (symbol != null)
            {
                p.print(symbol);
            }
            else
            {
                //TODO ??????????
                p.printURIResource(function);
            }
        }
Example #8
0
        override public void Print(ISparqlPrinter p)
        {
            p.printKeyword("SERVICE");
            IVariable var = getServiceVariable();

            if (var != null)
            {
                p.print(" ");
                p.printVariable(var.getName());
            }
            else
            {
                Uri uri = getServiceURI();
                if (uri != null)
                {
                    p.print(" ");
                    p.printURIResource(Resource.Get(RDFUtil.CreateUriNode(uri), getModel()));
                }
            }
            printNestedElementList(p);
        }
Example #9
0
        public static void printVarOrResource(ISparqlPrinter p, IResource resource)
        {
            IVariable variable = SPINFactory.asVariable(resource);

            if (variable != null)
            {
                variable.Print(p);
            }
            else if (resource.isUri())
            {
                p.printURIResource(resource);
            }
            else if (p.isNamedBNodeMode())
            {
                // TODO is this correct ?
                p.print(resource.ToString());
            }
            else
            {
                p.print("[]");
            }
        }
Example #10
0
        protected void printGraphDefaultNamedOrAll(ISparqlPrinter p)
        {
            IResource graph = this.getResource(SP.PropertyGraphIRI);

            if (graph != null)
            {
                p.printKeyword("GRAPH");
                p.print(" ");
                p.printURIResource(graph);
            }
            else if (hasProperty(SP.PropertyDefault, RDFUtil.TRUE))
            {
                p.printKeyword("DEFAULT");
            }
            else if (hasProperty(SP.PropertyNamed, RDFUtil.TRUE))
            {
                p.printKeyword("NAMED");
            }
            else if (hasProperty(SP.PropertyAll, RDFUtil.TRUE))
            {
                p.printKeyword("ALL");
            }
        }
Example #11
0
        override public void Print(ISparqlPrinter p)
        {
            p.printKeyword("VALUES");
            p.print(" ");
            List <String> varNames = getVarNames();

            if (varNames.Count == 1)
            {
                p.printVariable(varNames[0]);
            }
            else
            {
                p.print("(");
                IEnumerator <String> vit = varNames.GetEnumerator();
                while (vit.MoveNext())
                {
                    p.printVariable(vit.Current);
                    if (vit.MoveNext())
                    {
                        p.print(" ");
                    }
                }
                p.print(")");
            }
            p.print(" {");
            p.println();
            foreach (Dictionary <String, IResource> binding in getBindings())
            {
                p.printIndentation(p.getIndentation() + 1);
                if (varNames.Count != 1)
                {
                    p.print("(");
                }
                IEnumerator <String> vit = varNames.GetEnumerator();
                while (vit.MoveNext())
                {
                    String    varName = vit.Current;
                    IResource value   = binding[varName];
                    if (value == null)
                    {
                        p.printKeyword("UNDEF");
                    }
                    else if (value.isUri())
                    {
                        p.printURIResource(value);
                    }
                    else
                    {
                        TupleImpl.print(getModel(), Resource.Get(value, getModel()), p);
                    }
                    if (vit.MoveNext())
                    {
                        p.print(" ");
                    }
                }
                if (varNames.Count != 1)
                {
                    p.print(")");
                }
                p.println();
            }
            p.printIndentation(p.getIndentation());
            p.print("}");
        }