use of org.apache.jena.sparql.sse.Item in project jena by apache.
the class BuilderExpr method buildItem.
public Expr buildItem(Item item) {
Expr expr = null;
if (item.isList()) {
ItemList list = item.getList();
if (list.size() == 0)
BuilderLib.broken(item, "Empty list for expression");
Item head = list.get(0);
if (head.isNode()) {
if (head.getNode().isVariable() && list.size() == 1) {
// The case of (?z)
return new ExprVar(Var.alloc(head.getNode()));
}
return buildFunctionCall(list);
} else if (head.isList())
BuilderLib.broken(item, "Head is a list");
else if (head.isSymbol()) {
if (item.isTagged(Tags.tagExpr)) {
BuilderLib.checkLength(2, list, "Wrong length: " + item.shortString());
item = list.get(1);
return buildItem(item);
}
return buildKnownFunction(list);
}
throw new ARQInternalErrorException();
}
if (item.isNode()) {
if (Var.isVar(item.getNode()))
return new ExprVar(Var.alloc(item.getNode()));
return NodeValue.makeNode(item.getNode());
}
if (item.isSymbolIgnoreCase(Tags.tagTrue))
return NodeValue.TRUE;
if (item.isSymbolIgnoreCase(Tags.tagFalse))
return NodeValue.FALSE;
BuilderLib.broken(item, "Not a list or a node or recognized symbol: " + item);
return null;
}
use of org.apache.jena.sparql.sse.Item in project jena by apache.
the class BuilderGraph method buildGraph.
public static Graph buildGraph(Graph graph, ItemList list) {
if (!list.isEmpty() && list.get(0).isSymbol()) {
if (list.get(0).isSymbol(Tags.tagGraph))
list = list.cdr();
}
for (Item item : list) {
BuilderLib.checkList(item);
Triple triple = buildTriple(item.getList());
graph.add(triple);
}
return graph;
}
use of org.apache.jena.sparql.sse.Item in project jena by apache.
the class BuilderGraph method loadGraph.
private static void loadGraph(Graph graph, ItemList list) {
BuilderLib.checkLength(2, list, Tags.tagLoad);
Item item = list.get(1);
if (!item.isNode())
BuilderLib.broken(item, "Expected: (" + Tags.tagLoad + " 'filename')");
String s = NodeUtils.stringLiteral(item.getNode());
if (s == null)
BuilderLib.broken(item, "Expected: (" + Tags.tagLoad + " 'filename')");
Model model = ModelFactory.createModelForGraph(graph);
FileManager.get().readModel(model, s);
}
use of org.apache.jena.sparql.sse.Item in project jena by apache.
the class ParseHandlerForm method listFinish.
@Override
public void listFinish(int line, int column) {
ItemList list = currentList();
if (!frameStack.isCurrent(list)) {
// Nothing special - proceed as normal.
super.listFinish(line, column);
return;
}
if (inDecl)
throwException("Inconsistent form: Still in DECL at end of the form", line, column);
// For later: no exception: ensure this is cleared.
inDecl = false;
finishForm(list);
// Frame
Frame f = frameStack.pop();
// Drop the form list.
popList();
//setCurrentItem(null) ; // Clear, in case top level item is a form of nothing.
// Form output skipped if no result registered.
Item item = f.result;
// If all forms at least evaluate to nil.
// if ( item == null )
// item = Item.createNil(list.getLine(), list.getColumn()) ;
// And emit a result as a listAdd.
// Must go through our listAdd() here to handle nested forms.
// item==null : remove nil code above to allow forms that have no output.
// if ( item != null )
listAdd(item);
}
use of org.apache.jena.sparql.sse.Item in project jena by apache.
the class ParseHandlerPlain method emitVar.
@Override
public void emitVar(int line, int column, String varName) {
Var var = null;
switch(varName) {
case "":
// "?"
var = varAlloc.allocVar();
break;
case ARQConstants.allocVarAnonMarker:
// "??" -- Allocate a non-distinguished variable
var = varAllocND.allocVar();
break;
case ARQConstants.allocVarMarker:
// "?." -- Allocate a named variable
var = varAllocIntern.allocVar();
break;
default:
var = Var.alloc(varName);
break;
}
Item item = Item.createNode(var, line, column);
listAdd(item);
}
Aggregations