private void addPatternsSmall(Item predicate, double numProp) { double wSP = weightSP_small ; double wPO = weightPO_small ; wPO = Math.min(numProp, wPO) ; wSP = Math.min(numProp, wSP) ; if ( predicate.isNode() && NodeConst.nodeRDFType.equals(predicate.getNode()) ) wPO = weightTypeO_small ; addPatterns(predicate, numProp, wSP, wPO) ; }
@Override public void visit(Item item, Node node) { result = ( other.isNode() && other.getNode().equals(node) ) ; }
public static void checkNode(Item item) { if ( item.isNode() ) return; broken(item, "Not a node: " + item.shortString()); }
public boolean isNodeBNode() { return isNode() && getNode().isBlank() ; }
public double getDouble() { if ( ! isNode() ) throw new ItemException("Not a node, can't be a double: "+this) ; if ( ! getNode().isLiteral() ) throw new ItemException("Not a literal, can't be a double: "+this) ; return ((Number)(getNode().getLiteralValue())).doubleValue() ; }
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 int getLong() { if ( ! isNode() ) throw new ItemException("Not a node, can't be an integer: "+this) ; if ( ! getNode().isLiteral() ) throw new ItemException("Not a literal, can't be a integer: "+this) ; return ((Number)(getNode().getLiteralValue())).intValue() ; }
public long getInteger() { if ( ! isNode() ) throw new ItemException("Not a node, can't be an integer: "+this) ; if ( ! getNode().isLiteral() ) throw new ItemException("Not a literal, can't be a integer: "+this) ; //Integer.parseInt(getNode().getLiteralLexicalForm()) ; return ((Number)(getNode().getLiteralValue())).longValue() ; }
public int getInt() { if ( ! isNode() ) throw new ItemException("Not a node, can't be an integer: "+this) ; if ( ! getNode().isLiteral() ) throw new ItemException("Not a literal, can't be a integer: "+this) ; return ((Number)(getNode().getLiteralValue())).intValue() ; }
public static Var buildVar(Item item) { if ( ! item.isNode() || !Var.isVar(item.getNode()) ) BuilderLib.broken(item, "Not a variable", item) ; // if ( ! Var.isNamedVar(item.getNode()) ) // BuilderBase.broken(item, "Not a named variable", item) ; return Var.alloc(item.getNode()) ; }
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 Node parseNode(Reader reader, PrefixMapping pmap) { Item item = parseTerm(reader, pmap) ; if ( item.isSymbol() ) { String str = item.getSymbol() ; if ( "true".equalsIgnoreCase(str) ) return NodeConst.nodeTrue ; if ( "false".equalsIgnoreCase(str) ) return NodeConst.nodeFalse ; throw new SSEParseException("Not a node: "+item, item.getLine(), item.getColumn()) ; } if ( ! item.isNode() ) throw new SSEParseException("Not a node: "+item, item.getLine(), item.getColumn()) ; return item.getNode() ; }
static final private PropFuncArg readPropFuncArg(Item item) { if ( item.isNode() ) return new PropFuncArg(BuilderNode.buildNode(item)) ; if ( item.isList() ) return new PropFuncArg(BuilderNode.buildNodeList(item)) ; BuilderLib.broken(item, "Expected a property function argument (node or list of nodes") ; return null ; }
public static boolean isSet(Item item) { if ( item.isNode() ) { if ( item.getNode().isConcrete() ) return true ; } if (item.equals(TERM) ) return true ; if (item.equals(URI) ) return true ; if (item.equals(BNODE) ) return true ; if (item.equals(LITERAL) ) return true ; return false ; }
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 String shortString() { if ( isSymbol() ) return getSymbol(); if ( isNode() ) return FmtUtils.stringForNode(getNode()); return getList().shortString() ; } }
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()) ; }
public void visit(ItemVisitor visitor) { if ( isList() ) visitor.visit(this, getList()) ; else if ( isNode() ) visitor.visit(this, getNode()) ; else if ( isSymbol() ) visitor.visit(this, getSymbol()) ; else if ( isNil() ) visitor.visitNil() ; else System.err.println("broken item") ; }
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); }
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()) ; }