Java Code Examples for org.apache.jena.graph.Node#getName()

The following examples show how to use org.apache.jena.graph.Node#getName() . 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: TriplesToRuleSystem.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * converts a {@link Node} into an {l@ink Expr}
 * @param n
 * @return
 */
protected Expr	toExpr(Node n) {
	if (n.isVariable()) {
		return new VariableExpr(n.getName());
	} else if (n.isURI()) {
		try {
			return new ConstantExpr(new URI(n.getURI()));
		} catch (URISyntaxException e) {
			throw new RuntimeException(e);
		}
	} else if (n.isLiteral()) {
		Literal l = (Literal) n;
		return new ConstantExpr(l.getValue());
	} else {
		throw new RuntimeException("Unsuported node type in query : "+n);
	}
}
 
Example 2
Source File: RuleSystemToQueries.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
protected static E_Equals toEqualsFilter(Expr left, Expr right) {
	Node ln = toNode(left);
	org.apache.jena.sparql.expr.Expr le = ln.isVariable()? new ExprVar(ln.getName()) : new NodeValueNode(ln);
	Node rn = toNode(right);
	org.apache.jena.sparql.expr.Expr re = rn.isVariable()? new ExprVar(rn.getName()) : new NodeValueNode(rn);
	return new E_Equals(le, re);
}
 
Example 3
Source File: RuleSystemToQueries.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
protected static E_Equals toIRIEqualsFilter(Expr left, Expr right) {
	Node ln = toNode(left);
	org.apache.jena.sparql.expr.Expr le = ln.isVariable()? new ExprVar(ln.getName()) : new NodeValueNode(ln);
	Node rn = toNode(right);
	org.apache.jena.sparql.expr.Expr re = rn.isVariable()? new ExprVar(rn.getName()) : new NodeValueNode(rn);
	return new E_Equals(new E_Str(le), new E_Str(re));
}
 
Example 4
Source File: RuleSystemToQueries.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
protected static E_NotEquals toNotEqualsFilter(Expr left, Expr right) {
	Node ln = toNode(left);
	org.apache.jena.sparql.expr.Expr le = ln.isVariable()? new ExprVar(ln.getName()) : new NodeValueNode(ln);
	Node rn = toNode(right);
	org.apache.jena.sparql.expr.Expr re = rn.isVariable()? new ExprVar(rn.getName()) : new NodeValueNode(rn);
	return new E_NotEquals(le, re);
}
 
Example 5
Source File: RuleSystemToQueries.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
protected static E_NotEquals toIRINotEqualsFilter(Expr left, Expr right) {
	Node ln = toNode(left);
	org.apache.jena.sparql.expr.Expr le = ln.isVariable()? new ExprVar(ln.getName()) : new NodeValueNode(ln);
	Node rn = toNode(right);
	org.apache.jena.sparql.expr.Expr re = rn.isVariable()? new ExprVar(rn.getName()) : new NodeValueNode(rn);
	return new E_NotEquals(new E_Str(le), new E_Str(re));
}
 
Example 6
Source File: ResolutionEngineForJena.java    From quetzal with Eclipse Public License 2.0 4 votes vote down vote up
/***
 * Takes a SELECT query and unroll it into a more complex SPARQL query under
 * rules
 * 
 * @param query
 */
public Query unfold(Query query) {

	ResolutionVisitor visitor = new ResolutionVisitor(rules);
	Op body = Algebra.compile(query);

	OpVariableVistor<String> collector = new OpVariableVistor<String>(body,
			true) {
		@Override
		protected String processVar(Node v) {
			return v.getName();
		}
	};
	OpWalker.walk(body, collector);

	Set<String> bindingNames = new HashSet<String>(collector.getResult());

	visitor.setBindingNames(bindingNames);

	Op newQuery = body;
	newQuery = Transformer.transform(visitor, body);

	
	VarExprList expr = new VarExprList();	
//	E_StrConcat trace = getRuleTracingConcat(newQuery);
	E_StrConcat trace = null;
	
	if (trace!=null) {
		expr.add(Var.alloc("trace"),trace);		
		newQuery = OpExtend.extend(newQuery, expr);
		newQuery = OpJoin.create(newQuery, OpTable.unit());
		
		if (SPARQLRewriterForJena.GENERATE_TRACE_SUMMARY) {
			
			VarExprList groupVars = new VarExprList();
			groupVars.add(Var.alloc("trace"));
			AggCount count = new AggCount();
			ExprAggregator aggregators = new ExprAggregator(Var.alloc("trace.sum"), count);
			List<ExprAggregator> list = new LinkedList<ExprAggregator>();
			list.add(aggregators);
			
			Op groupBy = new OpGroup(newQuery, groupVars, list);
			
			VarExprList expr2 = new VarExprList();	
			expr2.add(Var.alloc("sum"), new ExprVar("trace.sum"));			
			groupBy = OpExtend.extend(groupBy, expr2);
			List<Var> vars = new LinkedList<Var>();
			vars.add(Var.alloc("sum"));
			vars.add(Var.alloc("trace"));
			OpProject project = new OpProject(groupBy, vars);
			newQuery = project;
			
			
		}

	}
	
	
	
	
	
	Query q = OpAsQuery.asQuery(newQuery);
	q.setDistinct(true);	// KAVITHA: Not setting distinct on the consequent leaves duplicates
	return q;

}
 
Example 7
Source File: PropertyPathRewrite.java    From quetzal with Eclipse Public License 2.0 4 votes vote down vote up
protected Expr getExpr(Node n) {
	return n.isVariable()? new ExprVar(n.getName()) : new NodeValueNode(n);
}