Example #1
0
        protected void printNestedElementList(ISparqlPrinter p, INode predicate)
        {
            p.print(" {");
            p.println();
            IResource elementsRaw = getObject(predicate);

            if (elementsRaw != null)
            {
                IElementList elements = (IElementList)elementsRaw.As(typeof(ElementListImpl));
                p.setIndentation(p.getIndentation() + 1);
                elements.Print(p);
                p.setIndentation(p.getIndentation() - 1);
            }
            p.printIndentation(p.getIndentation());
            p.print("}");
        }
Example #2
0
        override public void Print(ISparqlPrinter p)
        {
            List <IElement> elements = getElements();

            int oldI = -1;

            for (int i = 0; i < elements.Count; i++)
            {
                if (i == oldI)
                {
                    break; // Prevent unknown endless loop conditions
                }
                oldI = i;
                IElement element = elements[i];
                p.printIndentation(p.getIndentation());
                if (element is IElementList && ((IElementList)element).getElements().Count > 1)
                {
                    p.print("{");
                    p.println();
                    p.setIndentation(p.getIndentation() + 1);
                    element.Print(p);
                    p.setIndentation(p.getIndentation() - 1);
                    p.printIndentation(p.getIndentation());
                    p.print("} ");
                }
                else
                {
                    if (element is ITriplePattern)
                    {
                        i = printTriplePattern(elements, i, p);
                    }
                    else
                    {
                        element.Print(p);
                    }
                }
                if (!(element is IElementList) || ((IElementList)element).getElements().Count > 1)
                {
                    p.print(" .");
                }
                p.println();
            }
        }
Example #3
0
        override public void Print(ISparqlPrinter p)
        {
            p.print("{");
            p.println();
            IQuery query = getQuery();

            if (query != null)
            {
                p.setIndentation(p.getIndentation() + 1);
                query.Print(p);
                p.setIndentation(p.getIndentation() - 1);
            }
            else
            {
                p.print("<Exception: Missing sub-query>");
            }
            p.println();
            p.printIndentation(p.getIndentation());
            p.print("}");
        }
Example #4
0
        override public void Print(ISparqlPrinter p)
        {
            List <IElement> elements = getElements();

            for (IEnumerator <IElement> it = elements.GetEnumerator(); it.MoveNext();)
            {
                IElement element = it.Current;
                p.print("{");
                p.println();
                p.setIndentation(p.getIndentation() + 1);
                element.Print(p);
                p.setIndentation(p.getIndentation() - 1);
                p.printIndentation(p.getIndentation());
                p.print("}");
                if (it.MoveNext())
                {
                    p.println();
                    p.printIndentation(p.getIndentation());
                    p.printKeyword("UNION");
                    p.println();
                    p.printIndentation(p.getIndentation());
                }
            }
        }
Example #5
0
        protected bool printTemplates(ISparqlPrinter p, INode predicate, String keyword, bool force, IResource graphIRI)
        {
            IResource resource = getResource(predicate);

            if (resource == null)
            {
                return(false);
            }
            List <IResource> nodes = resource.AsList();

            if (nodes.Count > 0 || force)
            {
                if (keyword != null)
                {
                    p.printIndentation(p.getIndentation());
                    p.printKeyword(keyword);
                }
                p.print(" {");
                p.println();
                if (graphIRI != null)
                { // Legacy triple
                    p.setIndentation(p.getIndentation() + 1);
                    p.printIndentation(p.getIndentation());
                    p.printKeyword("GRAPH");
                    p.print(" ");
                    printVarOrResource(p, graphIRI);
                    p.print(" {");
                    p.println();
                }
                foreach (IResource node in nodes)
                {
                    p.printIndentation(p.getIndentation() + 1);
                    if (node.canAs(SP.ClassNamedGraph))
                    {
                        INamedGraph namedGraph = (INamedGraph)node.As(typeof(NamedGraphImpl));
                        p.setIndentation(p.getIndentation() + 1);
                        p.setNamedBNodeMode(true);
                        namedGraph.Print(p);
                        p.setNamedBNodeMode(false);
                        p.setIndentation(p.getIndentation() - 1);
                    }
                    else
                    {
                        ITripleTemplate template = (ITripleTemplate)node.As(typeof(TripleTemplateImpl));
                        template.Print(p);
                    }
                    p.print(" .");
                    p.println();
                }
                if (graphIRI != null)
                {
                    p.printIndentation(p.getIndentation());
                    p.setIndentation(p.getIndentation() - 1);
                    p.print("}");
                    p.println();
                }
                p.printIndentation(p.getIndentation());
                p.print("}");
                return(true);
            }
            else
            {
                return(false);
            }
        }