Java Code Examples for org.eclipse.rdf4j.query.algebra.evaluation.function.Function#getURI()

The following examples show how to use org.eclipse.rdf4j.query.algebra.evaluation.function.Function#getURI() . 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: FunctionArguments.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the double value
 *
 * @param func function
 * @param v    value
 * @return double
 * @throws ValueExprEvaluationException
 */
public static double getDouble(Function func, Value v) throws ValueExprEvaluationException {
	if (!(v instanceof Literal)) {
		throw new ValueExprEvaluationException("Invalid argument for " + func.getURI() + ": " + v);
	}

	try {
		return ((Literal) v).doubleValue();
	} catch (NumberFormatException e) {
		throw new ValueExprEvaluationException(e);
	}

}
 
Example 2
Source File: FunctionArguments.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the geo shape
 *
 * @param func    function
 * @param v       value
 * @param context
 * @return shape
 * @throws ValueExprEvaluationException
 */
public static Shape getShape(Function func, Value v, SpatialContext context) throws ValueExprEvaluationException {
	Literal wktLiteral = getLiteral(func, v, GEO.WKT_LITERAL);
	try {
		ShapeReader reader = context.getFormats().getWktReader();
		return reader.read(wktLiteral.getLabel());
	} catch (IOException | InvalidShapeException | ParseException e) {
		throw new ValueExprEvaluationException("Invalid argument for " + func.getURI() + ": " + wktLiteral, e);
	}
}
 
Example 3
Source File: FunctionArguments.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the literal of a specific data type
 *
 * @param func             function
 * @param v                value
 * @param expectedDatatype
 * @return literal
 * @throws ValueExprEvaluationException
 */
public static Literal getLiteral(Function func, Value v, IRI expectedDatatype) throws ValueExprEvaluationException {
	if (!(v instanceof Literal)) {
		throw new ValueExprEvaluationException("Invalid argument for " + func.getURI() + ": " + v);
	}
	Literal lit = (Literal) v;
	if (!expectedDatatype.equals(lit.getDatatype())) {
		throw new ValueExprEvaluationException(
				"Invalid datatype " + lit.getDatatype() + " for " + func.getURI() + ": " + v);
	}
	return lit;
}
 
Example 4
Source File: FunctionArguments.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the UoM IRI of the unit
 *
 * @param func function
 * @param v    value
 * @return UoM IRI
 * @throws ValueExprEvaluationException
 */
public static IRI getUnits(Function func, Value v) throws ValueExprEvaluationException {
	if (!(v instanceof IRI)) {
		throw new ValueExprEvaluationException("Invalid argument for " + func.getURI() + ": " + v);
	}
	IRI unitUri = (IRI) v;
	if (!unitUri.getNamespace().equals(GEOF.UOM_NAMESPACE)) {
		throw new ValueExprEvaluationException("Invalid unit of measurement URI for " + func.getURI() + ": " + v);
	}
	return unitUri;
}
 
Example 5
Source File: GeoFilterIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void showGeoFunctionsRegistered() {
    int count = 0;
    final Collection<Function> funcs = FunctionRegistry.getInstance().getAll();
    for (final Function fun : funcs) {
        final String uri = fun.getURI();
        if (uri.startsWith(GEO)) {
            count++;
            System.out.println(String.format("Geo Registered Function #%02d: %s", count, uri));
        }
    }

    // There are 35 geo functions registered, ensure that there are 35.
    assertEquals(35, count);
}
 
Example 6
Source File: FunctionArguments.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Get the geo point
 *
 * @param func       function
 * @param v          value
 * @param geoContext
 * @return point
 * @throws ValueExprEvaluationException
 */
public static Point getPoint(Function func, Value v, SpatialContext geoContext)
		throws ValueExprEvaluationException {
	Shape p = FunctionArguments.getShape(func, v, geoContext);
	if (!(p instanceof Point)) {
		throw new ValueExprEvaluationException("Invalid argument for " + func.getURI() + " (not a point): " + v);
	}
	return (Point) p;
}