edu.cmu.sv.domain.ontology.query_fragments.ScaledShiftedSingleValueQueryFragment Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yoda Show documentation
Show all versions of yoda Show documentation
A library that allows rapid prototyping of dialog systems (language understanding, discourse modelling, dialog management, language generation).
package edu.cmu.sv.domain.ontology.query_fragments;
import edu.cmu.sv.domain.ontology.QueryFragment;
/**
* Created by David Cohen on 6/16/15.
*
* A parameterizable sparql fragment for computing a quality assuming that quality is encoded in the database as a
* single numeric value with a known, limited range.
*/
public class ScaledShiftedSingleValueQueryFragment implements QueryFragment{
String databaseProperty;
double minInput;
double maxInput;
boolean flip;
double scale;
public ScaledShiftedSingleValueQueryFragment(String databaseProperty, double minInput, double maxInput, boolean flip) {
this.databaseProperty = databaseProperty;
this.minInput = minInput;
this.maxInput = maxInput;
this.flip = flip;
scale = 1.0 / (maxInput - minInput);
}
@Override
public String getResolutionSparqlQueryFragment(String firstArgument, String secondArgument, String resultVariable) {
String ans = firstArgument+" base:"+databaseProperty+" ?i_"+databaseProperty+" . ";
ans += "BIND( ";
if (flip)
ans += "1.0 - ";
ans += "(";
ans += "( ?i_"+databaseProperty+" - "+minInput+" ) * "+scale+" )";
ans += " AS "+resultVariable;
ans += ") ";
return ans;
}
//// OLD EXAMPLE from Cleanliness:
// public class Cleanliness extends TransientQuality {
// static List> arguments = Arrays.asList();
//
// @Override
// public Function, String> getQualityCalculatorSPARQLQuery() {
// Function, String> queryGen = (List entityURIs) ->
// entityURIs.get(0)+" base:dust_level ?i_dust_level . "+
// "BIND( 1.0 - ( ?i_dust_level * 0.2 ) AS "+entityURIs.get(1)+") ";
// return queryGen;
//
// }
}