public static Node buildNode(Item item) { if ( item.isSymbol("true") ) return NodeConst.nodeTrue ; if ( item.isSymbol("false") ) return NodeConst.nodeFalse ; if ( item.isSymbolIgnoreCase("ANY") || item.isSymbol("_") ) return Node.ANY; if ( !item.isNode() ) BuilderLib.broken(item, "Not a node", item) ; return item.getNode() ; }
public boolean sameSymbol(String symbolStr) { return isSymbol() && getSymbol().equalsIgnoreCase(symbolStr) ; }
static boolean startsWithDistinct(ItemList x) { if ( x.size() > 0 && x.car().isSymbol(Tags.tagDistinct) ) return true ; return false ; }
public static void checkSymbol(Item item) { if ( item.isSymbol() ) return; broken(item, "Not a symbol: " + item.shortString()); }
public static String buildSymbol(Item item) { if ( !item.isSymbol() ) BuilderLib.broken(item, "Not a symbol", item) ; return item.getSymbol() ; }
public boolean sameSymbol(Item item) { if ( item.isSymbol() ) return sameSymbol(item.getSymbol()) ; return false ; }
public boolean isTagged() { if ( ! isTaggable() ) return false ; return list.get(0).isSymbol() ; } private boolean isTaggable()
public static List<Var> buildVarList(ItemList list) { if ( list.size() > 0 && list.getFirst().isSymbol(Tags.tagVars) ) list = list.cdr() ; List<Var> vars = new ArrayList<>() ; for (Item x : list) { Var v = buildVar(x) ; vars.add(v) ; } return vars ; }
public boolean isTagged(String tag) { if ( ! isTaggable() ) return false ; return getList().get(0).isSymbol(tag) ; } public boolean isTagged()
public long asInteger() { if ( isNode() ) { if ( getNode().isLiteral() ) // Ignore typing. return Integer.parseInt(getNode().getLiteralLexicalForm()) ; } if ( isSymbol() ) return Integer.parseInt(getSymbol()) ; throw new ItemException("Not a literal or string: "+this) ; }
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; }
public static void checkList(Item item, String msg) { if ( item.isList() ) return; if ( msg == null && item.isSymbol() ) msg = "Attempt to use a symbol where list expected: " + item.shortString(); if ( msg == null && item.isNode() ) msg = "Attempt to use a node where list expected: " + item.shortString(); if ( msg == null ) msg = "Not a list"; broken(item, msg); }
private static String parseSymbol(Reader reader, PrefixMapping pmap) { Item item = parseTerm(reader, pmap) ; if ( ! item.isSymbol() ) throw new SSEParseException("Not a symbol: "+item, item.getLine(), item.getColumn()) ; return item.getSymbol() ; }
public String shortString() { if ( isSymbol() ) return getSymbol(); if ( isNode() ) return FmtUtils.stringForNode(getNode()); return getList().shortString() ; } }
public String shortString() { if ( _size() == 0 ) return "()" ; if ( get(0).isSymbol() ) { if ( _size() == 1 ) return "("+get(0).getSymbol()+")"; else return "("+get(0).getSymbol()+" ...)"; } return "(...)" ; }
public static Op build(Item item) { if (item.isNode() ) BuilderLib.broken(item, "Attempt to build op structure from a plain node") ; if (item.isSymbol() ) BuilderLib.broken(item, "Attempt to build op structure from a bare symbol") ; if (!item.isTagged()) BuilderLib.broken(item, "Attempt to build op structure from a non-tagged item") ; return builderOp.build(item.getList()) ; }
private void testSymbol(String str) { Item item = parse(str) ; assertTrue(item.isSymbol()) ; assertEquals(item.getSymbol(), str) ; }
private Path build(Item item) { if (item.isNode() ) { if ( item.getNode().isURI() ) return new P_Link(item.getNode()) ; BuilderLib.broken(item, "Attempt to build path from a plain node") ; } if (item.isSymbol() ) BuilderLib.broken(item, "Attempt to build path from a bare symbol") ; return build(item.getList()) ; }