use of org.apache.commons.lang3.Range in project metron by apache.
the class WindowProcessorTest method testDenseWindow.
@Test
public void testDenseWindow() {
for (String text : new String[] { "from 2 hours ago to 30 minutes ago", "starting from 2 hours until 30 minutes", "starting from 2 hours ago until 30 minutes ago", "starting from 30 minutes ago until 2 hours ago", "from 30 minutes ago to 2 hours ago " }) {
Window w = WindowProcessor.process(text);
/*
A dense window starting 2 hour ago and continuing until 30 minutes ago
*/
Date now = new Date();
List<Range<Long>> intervals = w.toIntervals(now.getTime());
Assert.assertEquals(1, intervals.size());
assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(2), intervals.get(0).getMinimum());
assertEquals(now.getTime() - TimeUnit.MINUTES.toMillis(30), intervals.get(0).getMaximum());
}
}
use of org.apache.commons.lang3.Range in project webanno by webanno.
the class TypeSystemAnalysis method isSlotFeature.
private boolean isSlotFeature(TypeSystem aTS, Feature aFeature) {
// Slot features are multi-valued
if (!FSUtil.isMultiValuedFeature(aTS, aFeature)) {
return false;
}
// The component type is the link type - it must be present
Type linkType = aFeature.getRange().getComponentType();
if (linkType == null) {
return false;
}
// The range of the slot feature is its link type which must inherit from TOP
if (!aTS.getTopType().equals(aTS.getParent(linkType))) {
return false;
}
// The link feature must have exactly two features (link-with-role)
if (linkType.getFeatures().size() != 2) {
return false;
}
Optional<Feature> roleFeature = linkType.getFeatures().stream().filter(f -> f.getRange().getName().equals(CAS.TYPE_NAME_STRING)).findFirst();
if (!roleFeature.isPresent()) {
return false;
}
Optional<Feature> linkFeature = linkType.getFeatures().stream().filter(f -> !f.getRange().isPrimitive()).findFirst();
if (!linkFeature.isPresent()) {
return false;
}
// Hm, ok, so this looks like a slot feature.
return true;
}
use of org.apache.commons.lang3.Range in project sirix by sirixdb.
the class AbstractSunburstGUI method style.
/**
* Style menu.
*/
protected void style() {
final Group ctrl = mControlP5.addGroup("menu", 15, 25, 35);
ctrl.setColorLabel(mParent.color(255));
ctrl.setColorBackground(mParent.color(100));
ctrl.close();
mParent.colorMode(PConstants.RGB, 255, 255, 255);
final int backgroundColor = 0x99ffffff;
int i = 0;
for (final Slider slider : mSliders) {
slider.setGroup(ctrl);
slider.setId(i);
final Label label = slider.getCaptionLabel();
label.toUpperCase(true);
label.setColor(mParent.color(0));
label.setColorBackground(backgroundColor);
final ControllerStyle style = label.getStyle();
style.padding(4, 0, 1, 3);
style.marginTop = -4;
style.marginLeft = 0;
style.marginRight = -14;
slider.plugTo(mControl);
i++;
}
i = 0;
for (final Range range : mRanges) {
range.setGroup(ctrl);
range.setId(i);
final Label label = range.getCaptionLabel();
label.toUpperCase(true);
label.setColor(mParent.color(0));
label.setColorBackground(backgroundColor);
final ControllerStyle style = label.getStyle();
style.padding(4, 0, 1, 3);
style.marginTop = -4;
range.plugTo(mControl);
i++;
}
i = 0;
for (final Toggle toggle : mToggles) {
toggle.setGroup(ctrl);
toggle.setId(i);
final Label label = toggle.getCaptionLabel();
label.setColor(mParent.color(0));
label.setColorBackground(backgroundColor);
final ControllerStyle style = label.getStyle();
style.padding(4, 3, 1, 3);
style.marginTop = -19;
style.marginLeft = 18;
style.marginRight = 5;
toggle.plugTo(mControl);
i++;
}
mParent.colorMode(PConstants.HSB, 360, 100, 100);
mParent.textLeading(14);
mParent.textAlign(PConstants.LEFT, PConstants.TOP);
mParent.cursor(PConstants.CROSS);
}
use of org.apache.commons.lang3.Range in project drill by axbaretto.
the class LocalFunctionRegistry method registerOperatorsWithInference.
private void registerOperatorsWithInference(DrillOperatorTable operatorTable, Map<String, Collection<DrillFuncHolder>> registeredFunctions) {
final Map<String, DrillSqlOperator.DrillSqlOperatorBuilder> map = Maps.newHashMap();
final Map<String, DrillSqlAggOperator.DrillSqlAggOperatorBuilder> mapAgg = Maps.newHashMap();
for (Entry<String, Collection<DrillFuncHolder>> function : registeredFunctions.entrySet()) {
final ArrayListMultimap<Pair<Integer, Integer>, DrillFuncHolder> functions = ArrayListMultimap.create();
final ArrayListMultimap<Integer, DrillFuncHolder> aggregateFunctions = ArrayListMultimap.create();
final String name = function.getKey().toUpperCase();
boolean isDeterministic = true;
boolean isNiladic = false;
for (DrillFuncHolder func : function.getValue()) {
final int paramCount = func.getParamCount();
if (func.isAggregating()) {
aggregateFunctions.put(paramCount, func);
} else {
final Pair<Integer, Integer> argNumberRange;
if (registeredFuncNameToArgRange.containsKey(name)) {
argNumberRange = registeredFuncNameToArgRange.get(name);
} else {
argNumberRange = Pair.of(func.getParamCount(), func.getParamCount());
}
functions.put(argNumberRange, func);
}
if (!func.isDeterministic()) {
isDeterministic = false;
}
if (func.isNiladic()) {
isNiladic = true;
}
}
for (Entry<Pair<Integer, Integer>, Collection<DrillFuncHolder>> entry : functions.asMap().entrySet()) {
final Pair<Integer, Integer> range = entry.getKey();
final int max = range.getRight();
final int min = range.getLeft();
if (!map.containsKey(name)) {
map.put(name, new DrillSqlOperator.DrillSqlOperatorBuilder().setName(name));
}
final DrillSqlOperator.DrillSqlOperatorBuilder drillSqlOperatorBuilder = map.get(name);
drillSqlOperatorBuilder.addFunctions(entry.getValue()).setArgumentCount(min, max).setDeterministic(isDeterministic).setNiladic(isNiladic);
}
for (Entry<Integer, Collection<DrillFuncHolder>> entry : aggregateFunctions.asMap().entrySet()) {
if (!mapAgg.containsKey(name)) {
mapAgg.put(name, new DrillSqlAggOperator.DrillSqlAggOperatorBuilder().setName(name));
}
final DrillSqlAggOperator.DrillSqlAggOperatorBuilder drillSqlAggOperatorBuilder = mapAgg.get(name);
drillSqlAggOperatorBuilder.addFunctions(entry.getValue()).setArgumentCount(entry.getKey(), entry.getKey());
}
}
for (final Entry<String, DrillSqlOperator.DrillSqlOperatorBuilder> entry : map.entrySet()) {
operatorTable.addOperatorWithInference(entry.getKey(), entry.getValue().build());
}
for (final Entry<String, DrillSqlAggOperator.DrillSqlAggOperatorBuilder> entry : mapAgg.entrySet()) {
operatorTable.addOperatorWithInference(entry.getKey(), entry.getValue().build());
}
}
use of org.apache.commons.lang3.Range in project narchy by automenta.
the class Optimize method run.
public Result<X> run(int maxIterations, int repeats, FloatFunction<Supplier<X>> eval) {
assert (repeats >= 1);
final int dim = tweaks.size();
double[] mid = new double[dim];
// double[] sigma = new double[n];
double[] min = new double[dim];
double[] max = new double[dim];
double[] inc = new double[dim];
// double[] range = new double[dim];
X example = subject.get();
int i = 0;
for (Tweak w : tweaks) {
TweakFloat s = (TweakFloat) w;
// initial guess: get from sample, otherwise midpoint of min/max range
Object guess = s.get(example);
mid[i] = guess != null ? ((float) guess) : ((s.getMax() + s.getMin()) / 2f);
min[i] = (s.getMin());
max[i] = (s.getMax());
inc[i] = s.getInc();
// range[i] = max[i] - min[i];
// sigma[i] = Math.abs(max[i] - min[i]) * 0.75f; //(s.getInc());
i++;
}
FasterList<DoubleObjectPair<double[]>> experiments = new FasterList<>(maxIterations);
final double[] maxScore = { Double.NEGATIVE_INFINITY };
ObjectiveFunction func = new ObjectiveFunction(point -> {
double score;
try {
double sum = 0;
for (int r = 0; r < repeats; r++) {
Supplier<X> x = () -> subject(point);
sum += eval.floatValueOf(x);
}
score = sum / repeats;
} catch (Exception e) {
logger.error("{} {} {}", this, point, e);
score = Float.NEGATIVE_INFINITY;
}
if (trace)
csv.out(ArrayUtils.add(point, (int) 0, score));
maxScore[0] = Math.max(maxScore[0], score);
// System.out.println(
// n4(score) + " / " + n4(maxScore[0]) + "\t" + n4(point)
// );
experiments.add(pair(score, point));
experimentIteration(point, score);
return score;
});
if (trace)
csv = new CSVOutput(System.out, Stream.concat(Stream.of("score"), tweaks.stream().map(t -> t.id)).toArray(String[]::new));
experimentStart();
try {
solve(dim, func, mid, min, max, inc, maxIterations);
} catch (Throwable t) {
logger.info("solve {} {}", func, t);
}
return new Result<>(experiments, tweaks);
}
Aggregations