Exemple #1
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(" )");
 }
Exemple #2
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);
        }
        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("}");
        }
Exemple #4
0
 internal void print(IResource node, ISparqlPrinter p, bool abbrevRDFType)
 {
     TupleImpl.print(getModel(), node, p, abbrevRDFType);
 }
Exemple #5
0
 internal void print(IResource node, ISparqlPrinter p)
 {
     TupleImpl.print(getModel(), node, p);
 }