Ejemplo n.º 1
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()));
            }
        }
Ejemplo n.º 2
0
 override public void Print(ISparqlPrinter p)
 {
     print(getSubject(), p);
     p.print(" ");
     print(getPredicate(), p, true);
     p.print(" ");
     print(getObject(), p);
 }
Ejemplo n.º 3
0
 override public void printSPINRDF(ISparqlPrinter p)
 {
     p.printKeyword("CREATE");
     p.print(" ");
     printSilent(p);
     p.printKeyword("GRAPH");
     p.print(" ");
     p.printURIResource(getResource(SP.PropertyGraphIRI));
 }
Ejemplo n.º 4
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(")");
        }
Ejemplo n.º 5
0
 private void printRDFList(ISparqlPrinter p, List <IResource> members)
 {
     p.print("(");
     foreach (IResource node in members)
     {
         p.print(" ");
         TupleImpl.print(getModel(), node, p);
     }
     p.print(" )");
 }
Ejemplo n.º 6
0
        // Special treatment of nested rdf:Lists
        private int printTriplePattern(List <IElement> elements, int i, ISparqlPrinter p)
        {
            ITriplePattern main = (ITriplePattern)elements[i];

            // Print subject
            List <IResource> leftList = new List <IResource>();

            i = addListMembers(elements, i, leftList);
            if (leftList.Count == 0)
            {
                TupleImpl.print(getModel(), main.getSubject(), p);
            }
            else
            {
                printRDFList(p, leftList);
                main = (ITriplePattern)elements[i];
            }
            p.print(" ");

            // Print predicate
            if (RDFUtil.sameTerm(RDF.PropertyType, main.getPredicate()))
            {
                p.print("a");
            }
            else
            {
                TupleImpl.print(getModel(), main.getPredicate(), p);
            }
            p.print(" ");

            // Print object
            if (nextIsMatchingVarPattern(main, elements, i))
            {
                List <IResource> rightList = new List <IResource>();
                i = addListMembers(elements, i + 1, rightList);
                if (rightList.Count == 0)
                {
                    TupleImpl.print(getModel(), main.getObject(), p);
                    if (leftList.Count != 0)
                    {
                        i--;
                    }
                }
                else
                {
                    printRDFList(p, rightList);
                    i--;
                }
            }
            else
            {
                TupleImpl.print(getModel(), main.getObject(), p);
            }
            return(i);
        }
Ejemplo n.º 7
0
        private void printProjectExpression(ISparqlPrinter p, IVariable var)
        {
            p.print("((");
            IResource  expr       = var.getResource(SP.PropertyExpression);
            IPrintable expression = (IPrintable)SPINFactory.asExpression(expr);

            expression.Print(p);
            p.print(") ");
            p.printKeyword("AS");
            p.print(" ");
            p.print(var.ToString());
            p.print(")");
        }
Ejemplo n.º 8
0
        override public void Print(ISparqlPrinter p)
        {
            String name = getName();

            if (name.StartsWith("?"))
            {
                p.print("_:");
                p.print(name.Substring(1));
            }
            else
            {
                p.printVariable(name);
            }
        }
Ejemplo n.º 9
0
        protected void printComment(ISparqlPrinter context)
        {
            String str = getComment();

            if (str != null)
            {
                String[] rows = str.Split('\n');
                for (int i = 0; i < rows.Length; i++)
                {
                    context.print("# ");
                    context.print(rows[i]);
                    context.println();
                }
            }
        }
Ejemplo n.º 10
0
        override public void Print(ISparqlPrinter context)
        {
            context.printKeyword("FILTER");
            context.print(" ");
            IResource expression = getExpression();

            if (expression == null)
            {
                context.print("<Exception: Missing expression>");
            }
            else
            {
                printNestedExpressionString(context, expression, true);
            }
        }
Ejemplo n.º 11
0
 override public void Print(ISparqlPrinter p)
 {
     p.printKeyword("GRAPH");
     p.print(" ");
     printVarOrResource(p, getNameNode());
     printNestedElementList(p);
 }
Ejemplo n.º 12
0
        private void printPath(IResource path, ISparqlPrinter p)
        {
            ISparqlPath arqPath = createPath(path);

            if (p.getUsePrefixes())
            {
                //TODO INamespaceMapper prefixMapping = path.getModel().getPrefixMapping();
                String str = arqPath.ToString(); //PathWriter.asString(arqPath, null/*TODO new Prologue(prefixMapping)*/);
                p.print(str);
            }
            else
            {
                String str = arqPath.ToString();//PathWriter.asString(arqPath);
                p.print(str);
            }
        }
Ejemplo n.º 13
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("}");
        }
Ejemplo n.º 14
0
 override public void printSPINRDF(ISparqlPrinter p)
 {
     p.printKeyword("DELETE");
     p.print(" ");
     p.printKeyword("DATA");
     printTemplates(p, SP.PropertyData, null, true, null);
 }
Ejemplo n.º 15
0
 override public void printSPINRDF(ISparqlPrinter p)
 {
     p.printKeyword("CLEAR");
     p.print(" ");
     printSilent(p);
     printGraphDefaultNamedOrAll(p);
 }
Ejemplo n.º 16
0
 protected void printSilent(ISparqlPrinter p)
 {
     if (isSilent())
     {
         p.printKeyword("SILENT");
         p.print(" ");
     }
 }
        void printFunction(ISparqlPrinter p, IResource function, List <IResource> args)
        {
            printFunctionQName(p, function);
            p.print("(");
            IEnumerator <IResource> it = args.GetEnumerator();

            while (it.MoveNext())
            {
                IResource param = it.Current;
                printNestedExpressionString(p, param);
                if (it.MoveNext())
                {
                    p.print(", ");
                }
            }
            p.print(")");
        }
Ejemplo n.º 18
0
        protected void printSolutionModifiers(ISparqlPrinter context)
        {
            List <IResource> orderBy = getList(SP.PropertyOrderBy);

            if (orderBy.Count > 0)
            {
                context.println();
                context.printIndentation(context.getIndentation());
                context.printKeyword("ORDER BY");
                foreach (IResource node in orderBy)
                {
                    if (!node.isLiteral())
                    {
                        if (node.hasProperty(RDF.PropertyType, SP.ClassAsc))
                        {
                            context.print(" ");
                            context.printKeyword("ASC");
                            context.print(" ");
                            IResource expression = node.getResource(SP.PropertyExpression);
                            printOrderByExpression(context, expression);
                        }
                        else if (node.hasProperty(RDF.PropertyType, SP.ClassDesc))
                        {
                            context.print(" ");
                            context.printKeyword("DESC");
                            context.print(" ");
                            IResource expression = node.getResource(SP.PropertyExpression);
                            printOrderByExpression(context, expression);
                        }
                        else
                        {
                            context.print(" ");
                            printOrderByExpression(context, node);
                        }
                    }
                }
            }
            long?limit = getLimit();

            if (limit != null)
            {
                context.println();
                context.printIndentation(context.getIndentation());
                context.printKeyword("LIMIT");
                context.print(" " + limit);
            }
            long?offset = getOffset();

            if (offset != null)
            {
                context.println();
                context.printIndentation(context.getIndentation());
                context.print("OFFSET");
                context.print(" " + offset);
            }
        }
Ejemplo n.º 19
0
        override public void Print(ISparqlPrinter context)
        {
            context.printKeyword("BIND");
            context.print(" (");
            IResource expression = getExpression();

            if (expression != null)
            {
                printNestedExpressionString(context, expression);
            }
            else
            {
                context.print("<Exception: Missing expression>");
            }
            context.print(" ");
            context.printKeyword("AS");
            context.print(" ");
            IVariable variable = getVariable();

            if (variable != null)
            {
                context.print(variable.ToString());
            }
            else
            {
                context.print("<Exception: Missing variable>");
            }
            context.print(")");
        }
Ejemplo n.º 20
0
        //public void visit(IElementVisitor visitor)
        //{
        //    visitor.visit(this);
        //}


        override public void Print(ISparqlPrinter p)
        {
            print(getSubject(), p);
            p.print(" ");

            IResource pathS = getObject(SP.PropertyPath);

            if (pathS == null || pathS.isLiteral())
            {
                p.print("<Missing path>");
            }
            else
            {
                printPath(pathS, p);
            }
            p.print(" ");
            print(getObject(), p);
        }
Ejemplo n.º 21
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();
            }
        }
Ejemplo n.º 22
0
 override public void printSPINRDF(ISparqlPrinter p)
 {
     printComment(p);
     printPrefixes(p);
     p.printIndentation(p.getIndentation());
     p.printKeyword("DELETE");
     p.print(" ");
     p.printKeyword("WHERE");
     printNestedElementList(p, SP.PropertyWhere);
 }
Ejemplo n.º 23
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);
            }
        }
Ejemplo n.º 24
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("}");
        }
Ejemplo n.º 25
0
        private void printOrderByExpression(ISparqlPrinter sb, IResource node)
        {
            // TODO check for real test
            if (node is INode)
            {
                IResource     resource = (IResource)node;
                IFunctionCall call     = SPINFactory.asFunctionCall(resource);
                if (call != null)
                {
                    sb.print("(");
                    ISparqlPrinter pc = sb.clone();
                    pc.setNested(true);
                    call.Print(pc);
                    sb.print(")");
                    return;
                }
            }

            printNestedExpressionString(sb, node, true);
        }
Ejemplo n.º 26
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);
        }
Ejemplo n.º 27
0
 public static void print(SpinProcessor model, IResource node, ISparqlPrinter p, bool abbrevRDFType)
 {
     // TODO find the good tests ?????
     if (!node.isLiteral())
     {
         if (abbrevRDFType && RDFUtil.sameTerm(RDF.PropertyType, node))
         {
             p.print("a");
         }
         else
         {
             printVarOrResource(p, node);
         }
     }
     else
     {
         //TODO INamespaceMapper pm = p.getUsePrefixes() ? model.getGraph().getPrefixMapping() : SPINExpressions.emptyPrefixMapping;
         String str = node.getSource().ToString();// TODO is this correct ? // FmtUtils.stringForNode(node, null/*TODO pm*/);
         p.print(str);
     }
 }
Ejemplo n.º 28
0
        override public void printSPINRDF(ISparqlPrinter context)
        {
            printComment(context);
            printPrefixes(context);
            context.printKeyword("DESCRIBE");
            context.print(" ");
            List <IResource> nodes = getResultNodes();

            if (nodes.Count == 0)
            {
                context.print("*");
            }
            else
            {
                for (IEnumerator <IResource> nit = nodes.GetEnumerator(); nit.MoveNext();)
                {
                    IResource node = nit.Current;
                    if (node is IVariable)
                    {
                        context.print(node.ToString());
                    }
                    else
                    {
                        printVarOrResource(context, node);
                    }
                    if (nit.MoveNext())
                    {
                        context.print(" ");
                    }
                }
            }
            printStringFrom(context);
            if (getWhereElements().Count != 0)
            {
                context.println();
                printWhere(context);
            }
            printSolutionModifiers(context);
            printValues(context);
        }
Ejemplo n.º 29
0
        override public void Print(ISparqlPrinter p)
        {
            String text = getString(SP.PropertyText);

            if (text != null)
            {
                p.print(text);
            }
            else
            {
                printSPINRDF(p);
            }
        }
Ejemplo n.º 30
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("[]");
            }
        }