/** * Gets the boolean value of the supplied literal. The fallback value is returned in case * {@link Literal#booleanValue()} throws a {@link NumberFormatException}. * * @param l * The literal to get the boolean value for. * @param fallback * The value to fall back to in case no boolean value could gotten from the literal. * @return Either the literal's boolean value, or the fallback value. */ public static boolean getBooleanValue(Literal l, boolean fallback) { try { return l.booleanValue(); } catch (IllegalArgumentException e) { return fallback; } }
/** * Gets the boolean value of the supplied literal. The fallback value is returned in case * {@link Literal#booleanValue()} throws a {@link NumberFormatException}. * * @param l * The literal to get the boolean value for. * @param fallback * The value to fall back to in case no boolean value could gotten from the literal. * @return Either the literal's boolean value, or the fallback value. */ public static boolean getBooleanValue(Literal l, boolean fallback) { try { return l.booleanValue(); } catch (IllegalArgumentException e) { return fallback; } }
private boolean literalToBoolean(Value v) { if (!(v instanceof Literal)) { throw new IllegalArgumentException( "value [" + v + "] was not a literal, which is expected " + "for a parameter of type boolean or Boolean." ); } Literal literal = (Literal) v; return literal.booleanValue(); }
public static boolean booleanValue(Resource subj, IRI pred, TripleSource store) throws QueryEvaluationException { Value v = TripleSources.singleValue(subj, pred, store); if (v == null) { return false; } else if (v instanceof Literal) { try { return ((Literal)v).booleanValue(); } catch (IllegalArgumentException e) { throw new QueryEvaluationException( "Value for " + pred + " must be of datatype " + XMLSchema.BOOLEAN + ": " + subj); } } else { throw new QueryEvaluationException("Non-literal value for " + pred + ": " + subj); } }
public static boolean booleanValue(Resource subj, IRI pred, TripleSource store) throws QueryEvaluationException { Value v = TripleSources.singleValue(subj, pred, store); if (v == null) { return false; } else if (v instanceof Literal) { try { return ((Literal)v).booleanValue(); } catch (IllegalArgumentException e) { throw new QueryEvaluationException( "Value for " + pred + " must be of datatype " + XMLSchema.BOOLEAN + ": " + subj); } } else { throw new QueryEvaluationException("Non-literal value for " + pred + ": " + subj); } }
@Override public void parse(Model m, Resource implNode) throws SailConfigException { super.parse(m, implNode); try { Models.objectLiteral(m.filter(implNode, SpinSailSchema.AXIOM_CLOSURE_NEEDED, null)).ifPresent( lit -> setAxiomClosureNeeded(lit.booleanValue())); } catch (ModelException e) { throw new SailConfigException(e.getMessage(), e); } } }
@Override public void parse(Model m, Resource implNode) throws SailConfigException { super.parse(m, implNode); try { Models.objectLiteral(m.filter(implNode, SpinSailSchema.AXIOM_CLOSURE_NEEDED, null)).ifPresent( lit -> setAxiomClosureNeeded(lit.booleanValue())); } catch (ModelException e) { throw new SailConfigException(e.getMessage(), e); } } }
private Object getObjectValue(Literal object) { IRI datatype = object.getDatatype(); if (datatype.equals(XMLSchema.INT) || datatype.equals(XMLSchema.INTEGER) || datatype.equals(XMLSchema.LONG)){ return object.longValue(); } else if (datatype.equals(XMLSchema.DECIMAL) || datatype.equals(XMLSchema.DOUBLE) || datatype.equals(XMLSchema.FLOAT)) { return object.doubleValue(); } else if (datatype.equals(XMLSchema.BOOLEAN)) { return object.booleanValue(); } else { // it's a string, and it can be tagged with language info. // if a language filter has been defined we apply it here final Optional<String> language = object.getLanguage(); if(langFilter == null || !language.isPresent() || (language.isPresent() && langFilter.equals(language.get()))){ return object.stringValue(); } return null; //string is filtered } }
private Object getObjectValue(Literal object) { IRI datatype = object.getDatatype(); if (datatype.equals(XMLSchema.INT) || datatype.equals(XMLSchema.INTEGER) || datatype.equals(XMLSchema.LONG)){ return object.longValue(); } else if (datatype.equals(XMLSchema.DECIMAL) || datatype.equals(XMLSchema.DOUBLE) || datatype.equals(XMLSchema.FLOAT)) { return object.doubleValue(); } else if (datatype.equals(XMLSchema.BOOLEAN)) { return object.booleanValue(); } else { // it's a string, and it can be tagged with language info. // if a language filter has been defined we apply it here final Optional<String> language = object.getLanguage(); if(langFilter == null || !language.isPresent() || (language.isPresent() && langFilter.equals(language.get()))){ return object.stringValue(); } return null; //string is filtered } }
lit -> setIncludeInferred(lit.booleanValue()));
lit -> setIncludeInferred(lit.booleanValue()));
protected Literal convert(ValueFactory valueFactory, Value value) throws ValueExprEvaluationException { if (value instanceof Literal) { Literal literal = (Literal)value; IRI datatype = literal.getDatatype(); if (XMLDatatypeUtil.isNumericDatatype(datatype)) { // FIXME: floats and doubles must be processed separately, see // http://www.w3.org/TR/xpath-functions/#casting-from-primitive-to-primitive try { BigDecimal decimalValue = literal.decimalValue(); return valueFactory.createLiteral(decimalValue.toPlainString(), XMLSchema.DECIMAL); } catch (NumberFormatException e) { throw typeError(literal, e); } } else if (datatype.equals(XMLSchema.BOOLEAN)) { try { return valueFactory.createLiteral(literal.booleanValue() ? "1.0" : "0.0", XMLSchema.DECIMAL); } catch (IllegalArgumentException e) { throw typeError(literal, e); } } } throw typeError(value, null); }
protected Literal convert(ValueFactory valueFactory, Value value) throws ValueExprEvaluationException { if (value instanceof Literal) { Literal literal = (Literal)value; IRI datatype = literal.getDatatype(); if (XMLDatatypeUtil.isNumericDatatype(datatype)) { // FIXME: floats and doubles must be processed separately, see // http://www.w3.org/TR/xpath-functions/#casting-from-primitive-to-primitive try { BigDecimal decimalValue = literal.decimalValue(); return valueFactory.createLiteral(decimalValue.toPlainString(), XMLSchema.DECIMAL); } catch (NumberFormatException e) { throw typeError(literal, e); } } else if (datatype.equals(XMLSchema.BOOLEAN)) { try { return valueFactory.createLiteral(literal.booleanValue() ? "1.0" : "0.0", XMLSchema.DECIMAL); } catch (IllegalArgumentException e) { throw typeError(literal, e); } } } throw typeError(value, null); }
protected Literal convert(ValueFactory valueFactory, Value value) throws ValueExprEvaluationException { if (value instanceof Literal) { Literal literal = (Literal)value; IRI datatype = literal.getDatatype(); if (XMLDatatypeUtil.isNumericDatatype(datatype)) { // FIXME: doubles must be processed separately, see // http://www.w3.org/TR/xpath-functions/#casting-from-primitive-to-primitive try { double doubleValue = literal.doubleValue(); return valueFactory.createLiteral(doubleValue); } catch (NumberFormatException e) { throw new ValueExprEvaluationException(e.getMessage(), e); } } else if (datatype.equals(XMLSchema.BOOLEAN)) { try { return valueFactory.createLiteral(literal.booleanValue() ? 1.0 : 0.0); } catch (IllegalArgumentException e) { throw typeError(literal, e); } } } throw typeError(value, null); }
protected Literal convert(ValueFactory valueFactory, Value value) throws ValueExprEvaluationException { if (value instanceof Literal) { Literal literal = (Literal)value; IRI datatype = literal.getDatatype(); if (XMLDatatypeUtil.isNumericDatatype(datatype)) { // FIXME: doubles must be processed separately, see // http://www.w3.org/TR/xpath-functions/#casting-from-primitive-to-primitive try { double doubleValue = literal.doubleValue(); return valueFactory.createLiteral(doubleValue); } catch (NumberFormatException e) { throw new ValueExprEvaluationException(e.getMessage(), e); } } else if (datatype.equals(XMLSchema.BOOLEAN)) { try { return valueFactory.createLiteral(literal.booleanValue() ? 1.0 : 0.0); } catch (IllegalArgumentException e) { throw typeError(literal, e); } } } throw typeError(value, null); }
setPersist((persistValue).booleanValue());
setPersist((persistValue).booleanValue());
protected Literal convert(ValueFactory valueFactory, Value value) throws ValueExprEvaluationException { if (value instanceof Literal) { Literal literal = (Literal)value; IRI datatype = literal.getDatatype(); if (XMLDatatypeUtil.isNumericDatatype(datatype)) { // FIXME: doubles must be processed separately, see // http://www.w3.org/TR/xpath-functions/#casting-from-primitive-to-primitive try { float floatValue = literal.floatValue(); return valueFactory.createLiteral(floatValue); } catch (NumberFormatException e) { throw typeError(literal, e); } } else if (datatype.equals(XMLSchema.BOOLEAN)) { try { return valueFactory.createLiteral(literal.booleanValue() ? 1f : 0f); } catch (IllegalArgumentException e) { throw typeError(literal, e); } } } throw typeError(value, null); }
protected Literal convert(ValueFactory valueFactory, Value value) throws ValueExprEvaluationException { if (value instanceof Literal) { Literal literal = (Literal)value; IRI datatype = literal.getDatatype(); if (XMLDatatypeUtil.isNumericDatatype(datatype)) { // FIXME: doubles must be processed separately, see // http://www.w3.org/TR/xpath-functions/#casting-from-primitive-to-primitive try { float floatValue = literal.floatValue(); return valueFactory.createLiteral(floatValue); } catch (NumberFormatException e) { throw typeError(literal, e); } } else if (datatype.equals(XMLSchema.BOOLEAN)) { try { return valueFactory.createLiteral(literal.booleanValue() ? 1f : 0f); } catch (IllegalArgumentException e) { throw typeError(literal, e); } } } throw typeError(value, null); }
@Override public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length < 1 || args.length > 2) { throw new ValueExprEvaluationException("Incorrect number of arguments"); } if (!(args[0] instanceof Resource)) { throw new ValueExprEvaluationException("First argument must be the root of a SPIN RDF query"); } if (args.length == 2 && !(args[1] instanceof Literal)) { throw new ValueExprEvaluationException("Second argument must be a string"); } Resource q = (Resource)args[0]; boolean useHtml = (args.length == 2) ? ((Literal)args[1]).booleanValue() : false; String sparqlString; try { ParsedOperation op = parser.parse(q, getCurrentQueryPreparer().getTripleSource()); sparqlString = new SPARQLQueryRenderer().render((ParsedQuery)op); } catch (Exception e) { throw new ValueExprEvaluationException(e); } return valueFactory.createLiteral(sparqlString); } }