All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.tkurz.sparqlmm.function.temporal.relation.OverlapsFunction Maven / Gradle / Ivy

Go to download

SPARQL-MM is a multimedia-extension for SPARQL 1.1 (www.w3.org/TR/sparql11-query/‎) implemented for Sesame (http://www.openrdf.org/).

There is a newer version: 2.0
Show newest version
package com.github.tkurz.sparqlmm.function.temporal.relation;

import com.github.tkurz.media.ontology.exception.NotComparableException;
import com.github.tkurz.media.ontology.function.TemporalFunction;
import com.github.tkurz.media.ontology.type.TemporalEntity;
import com.github.tkurz.sparqlmm.Constants;
import com.github.tkurz.sparqlmm.doc.FunctionDoc;
import com.github.tkurz.sparqlmm.utils.FunctionHelper;
import org.openrdf.model.Value;
import org.openrdf.model.ValueFactory;
import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
import org.openrdf.query.algebra.evaluation.function.Function;

/**
 * ...
 * 

* Author: Thomas Kurz ([email protected]) */ @FunctionDoc(title = "Overlaps", properties = {TemporalEntity.class, TemporalEntity.class}, reference = FunctionDoc.Reference.temporal, description = "returns true if p1.start < p2.start < p1.end < p2.end or p2.start < p.start < p.end < p.end, else false.") public class OverlapsFunction implements Function { /** * return the URI */ public String getURI() { return Constants.NAMESPACE + "overlaps"; } @Override public Value evaluate(ValueFactory valueFactory, Value... values) throws ValueExprEvaluationException { try { //check preconditions if(values.length != 2 || !FunctionHelper.isComparable(values)) return FunctionHelper.BOOL_LITERAL_FALSE; //check if values are correct TemporalEntity[] entities = FunctionHelper.toTemporalEntities(values); //evaluate return valueFactory.createLiteral(TemporalFunction.overlaps(entities[0], entities[1])); } catch (IllegalArgumentException | NotComparableException e) { return FunctionHelper.BOOL_LITERAL_FALSE; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy