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); } }
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); }
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); } }
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(); } }
protected void printValues(ISparqlPrinter p) { IValues values = getValues(); if (values != null) { p.println(); values.Print(p); } }
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("}"); }
override public void printSPINRDF(ISparqlPrinter context) { printComment(context); printPrefixes(context); context.printIndentation(context.getIndentation()); context.printKeyword("CONSTRUCT"); context.print(" {"); context.println(); foreach (ITripleTemplate template in getTemplates()) { context.printIndentation(context.getIndentation() + 1); template.Print(context); context.print(" ."); context.println(); } context.printIndentation(context.getIndentation()); context.print("}"); printStringFrom(context); context.println(); printWhere(context); printSolutionModifiers(context); printValues(context); }
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()); } } }
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(); } } }
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("}"); }
override public void printSPINRDF(ISparqlPrinter context) { printComment(context); printPrefixes(context); context.printIndentation(context.getIndentation()); context.printKeyword("ASK"); printStringFrom(context); context.print(" "); if (context.getIndentation() > 0) { // Avoid unnecessary whitespace after ASK -> put on extra row context.println(); } printWhere(context); printValues(context); }
private void printHaving(ISparqlPrinter p) { List <IResource> havings = getList(SP.PropertyHaving); if (havings.Count > 0) { IEnumerator <IResource> it = havings.GetEnumerator(); p.println(); p.printIndentation(p.getIndentation()); p.printKeyword("HAVING"); while (it.MoveNext()) { p.print(" "); printNestedExpressionString(p, it.Current); } } }
private void printGroupBy(ISparqlPrinter p) { List <IResource> groupBy = getList(SP.PropertyGroupBy); if (groupBy.Count > 0) { IEnumerator <IResource> it = groupBy.GetEnumerator(); p.println(); p.printIndentation(p.getIndentation()); p.printKeyword("GROUP BY"); while (it.MoveNext()) { p.print(" "); IResource node = it.Current; printNestedExpressionString(p, node); } } }
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); }
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("}"); }
override public void printSPINRDF(ISparqlPrinter p) { printComment(p); printPrefixes(p); p.printIndentation(p.getIndentation()); p.printKeyword("SELECT"); p.print(" "); if (isDistinct()) { p.printKeyword("DISTINCT"); p.print(" "); } if (isReduced()) { p.printKeyword("REDUCED"); p.print(" "); } List <IResource> vars = getResultVariables(); if (vars.Count == 0) { p.print("*"); } else { for (IEnumerator <IResource> vit = vars.GetEnumerator(); vit.MoveNext();) { IResource var = vit.Current; if (var is IVariable) { if (getModel().ContainsTriple(var, SP.PropertyExpression, null)) { printProjectExpression(p, (IVariable)var); } else { ((IVariable)var).Print(p); } } else if (var is IAggregation) { ((IPrintable)var).Print(p); } else { p.print("("); ((IPrintable)var).Print(p); p.print(")"); } if (vit.MoveNext()) { p.print(" "); } } } printStringFrom(p); p.println(); printWhere(p); printGroupBy(p); printHaving(p); printSolutionModifiers(p); printValues(p); }
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); } }