Java Code Examples for org.apache.jena.sparql.syntax.ElementGroup#getElements()

The following examples show how to use org.apache.jena.sparql.syntax.ElementGroup#getElements() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConjunctiveQuery.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
protected List<Element> flatten(Element g) {
	List<Element> ret = new ArrayList<Element>();
	Stack<Element> stack = new Stack<Element>();
	stack.push(g);
	while (!stack.isEmpty()) {
		Element e = stack.pop();
		if (e instanceof ElementGroup) {
			ElementGroup eg = (ElementGroup) e;
			for (Element ne:eg.getElements()) {
				stack.push(ne);
			}
		} else {
			ret.add(e);
		}
	}
	return ret;
	
}
 
Example 2
Source File: QueryPatternNormalizer.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(ElementGroup el) {
    final ElementGroup res = new ElementGroup();
    for (final Element element : el.getElements()) {
        element.visit(this);
        res.addElement(result);
    }
    result = res;
}
 
Example 3
Source File: QueryPatternSimplification.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void visit(ElementGroup group) {
	//remove nested groups
	ElementGroup ret = new ElementGroup();
	ElementPathBlock pathBlock = new ElementPathBlock();
	for (Element elt: group.getElements()) {
		elt.visit(this);
		if (result instanceof ElementGroup) {
			ElementGroup subgroup = (ElementGroup) result;
			// add the subgroup content directly
			add(ret, pathBlock, subgroup);
		} else if (result instanceof ElementPathBlock) {
			if (pathBlock.isEmpty()) {
				ret.addElement(pathBlock);
			}
			add(pathBlock, (ElementPathBlock) result);
		} else if (result instanceof ElementTriplesBlock) {
			if (pathBlock.isEmpty()) {
				ret.addElement(pathBlock);
			}
			add(pathBlock, (ElementTriplesBlock) result);
			
		} else {
			ret.addElement(result);
		}
		
	}
	if (ret.getElements().size() == 1) {
		result = ret.getElements().get(0);
	} else {
		result = ret;
	}
}
 
Example 4
Source File: RuleSystemToUnionQuery.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void visit(ElementGroup group) {
	ElementGroup ret = new ElementGroup();
	for (Element elt: group.getElements() ) {
		elt.visit(this);
		ret.addElement(result);
	}
	result = ret;
}
 
Example 5
Source File: FindAllVariables.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void visit(ElementGroup e) {
	for (Element ge : e.getElements()) {
		ge.visit(this);
	}
	
}
 
Example 6
Source File: TriplePatternExtractor.java    From NLIWOD with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void visit(final ElementGroup el) {
	for (Element e : el.getElements()) {
		e.visit(this);
	}
}
 
Example 7
Source File: SPARQLExtFormatterElement.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(ElementGroup el) {
    out.print("{");
    int initialRowNumber = out.getRow();
    out.incIndent(INDENT);
    if (!GROUP_FIRST_ON_SAME_LINE) {
        out.newline();
    }

    int row1 = out.getRow();
    out.pad();

    boolean first = true;
    Element lastElt = null;

    for (Element subElement : el.getElements()) {
        // Some adjacent elements need a DOT:
        // ElementTriplesBlock, ElementPathBlock
        if (!first) {
            // Need to move on after the last thing printed.
            // Check for necessary DOT as separator
            if (GROUP_SEP_DOT || needsDotSeparator(lastElt, subElement)) {
                out.print(" . ");
            }
            out.newline();
        }
        subElement.visit(this);
        first = false;
        lastElt = subElement;
    }
    out.decIndent(INDENT);

    // Where to put the closing "}"
    int row2 = out.getRow();
    if (row1 != row2) {
        out.newline();
    }

    // Finally, close the group.
    if (out.getRow() == initialRowNumber) {
        out.print(" ");
    }
    out.print("}");
}