/** * Get the current value of a particular CSS statement. * * @param key statement key. * @return current value or null. */ public String getStatement(String key) { for (Pair<String, String> pair : statements) { if (pair.getFirst().equals(key)) { return pair.getSecond(); } } return null; }
/** * Get the current value of a particular CSS statement. * * @param key statement key. * @return current value or null. */ public String getStatement(String key) { for (Pair<String, String> pair : statements) { if (pair.getFirst().equals(key)) { return pair.getSecond(); } } return null; }
/** * Append CSS definition to a stream * * @param buf String buffer to append to. */ public void appendCSSDefinition(StringBuilder buf) { buf.append("\n."); buf.append(name); buf.append('{'); for (Pair<String, String> pair : statements) { buf.append(pair.getFirst()); buf.append(':'); buf.append(pair.getSecond()); buf.append(";\n"); } buf.append("}\n"); }
/** * Render CSS class to inline formatting * * @return string rendition of CSS for inline use */ public String inlineCSS() { StringBuilder buf = new StringBuilder(); for (Pair<String, String> pair : statements) { buf.append(pair.getFirst()); buf.append(':'); buf.append(pair.getSecond()); buf.append(';'); } return buf.toString(); } }
/** * Render CSS class to inline formatting * * @return string rendition of CSS for inline use */ public String inlineCSS() { StringBuilder buf = new StringBuilder(); for (Pair<String, String> pair : statements) { buf.append(pair.getFirst()); buf.append(':'); buf.append(pair.getSecond()); buf.append(';'); } return buf.toString(); } }
/** * Append CSS definition to a stream * * @param buf String buffer to append to. */ public void appendCSSDefinition(StringBuilder buf) { buf.append("\n."); buf.append(name); buf.append('{'); for (Pair<String, String> pair : statements) { buf.append(pair.getFirst()); buf.append(':'); buf.append(pair.getSecond()); buf.append(";\n"); } buf.append("}\n"); }
/** * Find a matching handler for the given object * * @param o object to find handler for * @return handler for the object. null if no handler was found. */ public H getHandler(Object o) { if(o == null) { return null; } // note that we start at the end of the list. ListIterator<Pair<Class<?>, H>> iter = handlers.listIterator(handlers.size()); while(iter.hasPrevious()) { Pair<Class<?>, H> pair = iter.previous(); try { // if we can cast to the restriction class, use the given handler. pair.getFirst().cast(o); return pair.getSecond(); } catch(ClassCastException e) { // do nothing, but try previous in list } } return null; } }
/** * Find a matching handler for the given object * * @param o object to find handler for * @return handler for the object. null if no handler was found. */ public H getHandler(Object o) { if(o == null) { return null; } // note that we start at the end of the list. ListIterator<Pair<Class<?>, H>> iter = handlers.listIterator(handlers.size()); while(iter.hasPrevious()) { Pair<Class<?>, H> pair = iter.previous(); try { // if we can cast to the restriction class, use the given handler. pair.getFirst().cast(o); return pair.getSecond(); } catch(ClassCastException e) { // do nothing, but try previous in list } } return null; } }
/** * Find a matching handler for the given object * * @param o object to find handler for * @return handler for the object. null if no handler was found. */ public H getHandler(Object o) { if(o == null) { return null; } // note that we start at the end of the list. ListIterator<Pair<Class<?>, H>> iter = handlers.listIterator(handlers.size()); while(iter.hasPrevious()) { Pair<Class<?>, H> pair = iter.previous(); try { // if we can cast to the restriction class, use the given handler. pair.getFirst().cast(o); return pair.getSecond(); } catch(ClassCastException e) { // do nothing, but try previous in list } } return null; } }
/** * Validate a set of CSS statements. * * TODO: checks are currently not very extensive. * * @param statements Statements to check * @return true if valid */ public static boolean checkCSSStatements(Collection<Pair<String,String>> statements) { for (Pair<String, String> pair : statements) { if (!checkCSSStatement(pair.getFirst(), pair.getSecond())) { return false; } } return true; }
/** * Validate a set of CSS statements. * * TODO: checks are currently not very extensive. * * @param statements Statements to check * @return true if valid */ public static boolean checkCSSStatements(Collection<Pair<String,String>> statements) { for (Pair<String, String> pair : statements) { if (!checkCSSStatement(pair.getFirst(), pair.getSecond())) { return false; } } return true; }
/** * Serialize a pair, component-wise */ @Override @SuppressWarnings("unchecked") public void write(TextWriterStream out, String label, Pair<?,?> object) throws IOException { if (object != null) { Object first = object.getFirst(); if (first != null) { TextWriterWriterInterface<Object> tw = (TextWriterWriterInterface<Object>) out.getWriterFor(first); if (tw == null) { throw new IOException("No handler for database object itself: " + first.getClass().getSimpleName()); } tw.write(out, label, first); } Object second = object.getSecond(); if (second != null) { TextWriterWriterInterface<Object> tw = (TextWriterWriterInterface<Object>) out.getWriterFor(second); if (tw == null) { throw new IOException("No handler for database object itself: " + second.getClass().getSimpleName()); } tw.write(out, label, second); } } } }
/** * Serialize a pair, component-wise */ @Override @SuppressWarnings("unchecked") public void write(TextWriterStream out, String label, Pair<?,?> object) throws UnableToComplyException, IOException { if (object != null) { Object first = object.getFirst(); if (first != null) { TextWriterWriterInterface<Object> tw = (TextWriterWriterInterface<Object>) out.getWriterFor(first); if (tw == null) { throw new UnableToComplyException("No handler for database object itself: " + first.getClass().getSimpleName()); } tw.write(out, label, first); } Object second = object.getSecond(); if (second != null) { TextWriterWriterInterface<Object> tw = (TextWriterWriterInterface<Object>) out.getWriterFor(second); if (tw == null) { throw new UnableToComplyException("No handler for database object itself: " + second.getClass().getSimpleName()); } tw.write(out, label, second); } } } }
/** * Performs the Generalized LOF_SCORE algorithm on the given database by * calling {@code #doRunInTime(Database)} and adds a {@link LOFKNNListener} to * the preprocessors. */ @Override public OutlierResult run(Database database, Relation<O> relation) { StepProgress stepprog = LOG.isVerbose() ? new StepProgress("OnlineLOF", 3) : null; Pair<Pair<KNNQuery<O>, KNNQuery<O>>, Pair<RKNNQuery<O>, RKNNQuery<O>>> queries = getKNNAndRkNNQueries(database, relation, stepprog); KNNQuery<O> kNNRefer = queries.getFirst().getFirst(); KNNQuery<O> kNNReach = queries.getFirst().getSecond(); RKNNQuery<O> rkNNRefer = queries.getSecond().getFirst(); RKNNQuery<O> rkNNReach = queries.getSecond().getSecond(); LOFResult<O> lofResult = super.doRunInTime(relation.getDBIDs(), kNNRefer, kNNReach, stepprog); lofResult.setRkNNRefer(rkNNRefer); lofResult.setRkNNReach(rkNNReach); // add listener KNNListener l = new LOFKNNListener(lofResult); ((MaterializeKNNPreprocessor<O>) ((PreprocessorKNNQuery<O>) lofResult.getKNNRefer()).getPreprocessor()).addKNNListener(l); ((MaterializeKNNPreprocessor<O>) ((PreprocessorKNNQuery<O>) lofResult.getKNNReach()).getPreprocessor()).addKNNListener(l); return lofResult.getResult(); }
/** * Performs the Generalized LOF_SCORE algorithm on the given database by * calling {@code #doRunInTime(Database)} and adds a {@link LOFKNNListener} to * the preprocessors. */ @Override public OutlierResult run(Database database, Relation<O> relation) { StepProgress stepprog = LOG.isVerbose() ? new StepProgress("OnlineLOF", 3) : null; Pair<Pair<KNNQuery<O>, KNNQuery<O>>, Pair<RKNNQuery<O>, RKNNQuery<O>>> queries = getKNNAndRkNNQueries(database, relation, stepprog); KNNQuery<O> kNNRefer = queries.getFirst().getFirst(); KNNQuery<O> kNNReach = queries.getFirst().getSecond(); RKNNQuery<O> rkNNRefer = queries.getSecond().getFirst(); RKNNQuery<O> rkNNReach = queries.getSecond().getSecond(); LOFResult<O> lofResult = super.doRunInTime(relation.getDBIDs(), kNNRefer, kNNReach, stepprog); lofResult.setRkNNRefer(rkNNRefer); lofResult.setRkNNReach(rkNNReach); // add listener KNNListener l = new LOFKNNListener(lofResult); ((MaterializeKNNPreprocessor<O>) ((PreprocessorKNNQuery<O>) lofResult.getKNNRefer()).getPreprocessor()).addKNNListener(l); ((MaterializeKNNPreprocessor<O>) ((PreprocessorKNNQuery<O>) lofResult.getKNNReach()).getPreprocessor()).addKNNListener(l); return lofResult.getResult(); }
/** * Performs the Generalized LOF_SCORE algorithm on the given database by * calling {@code #doRunInTime(Database)} and adds a {@link LOFKNNListener} to * the preprocessors. */ @Override public OutlierResult run(Database database, Relation<O> relation) { StepProgress stepprog = LOG.isVerbose() ? new StepProgress("OnlineLOF", 3) : null; Pair<Pair<KNNQuery<O>, KNNQuery<O>>, Pair<RKNNQuery<O>, RKNNQuery<O>>> queries = getKNNAndRkNNQueries(database, relation, stepprog); KNNQuery<O> kNNRefer = queries.getFirst().getFirst(); KNNQuery<O> kNNReach = queries.getFirst().getSecond(); RKNNQuery<O> rkNNRefer = queries.getSecond().getFirst(); RKNNQuery<O> rkNNReach = queries.getSecond().getSecond(); LOFResult<O> lofResult = super.doRunInTime(relation.getDBIDs(), kNNRefer, kNNReach, stepprog); lofResult.setRkNNRefer(rkNNRefer); lofResult.setRkNNReach(rkNNReach); // add listener KNNListener l = new LOFKNNListener(lofResult); ((MaterializeKNNPreprocessor<O>) ((PreprocessorKNNQuery<O>) lofResult.getKNNRefer()).getPreprocessor()).addKNNListener(l); ((MaterializeKNNPreprocessor<O>) ((PreprocessorKNNQuery<O>) lofResult.getKNNReach()).getPreprocessor()).addKNNListener(l); return lofResult.getResult(); }
/** * Performs the Generalized LOF algorithm on the given database by calling * {@link #doRunInTime}. * * @param database Database to query * @param relation Data to process * @return LOF outlier result */ public OutlierResult run(Database database, Relation<O> relation) { StepProgress stepprog = LOG.isVerbose() ? new StepProgress("LOF", 3) : null; Pair<KNNQuery<O>, KNNQuery<O>> pair = getKNNQueries(database, relation, stepprog); KNNQuery<O> kNNRefer = pair.getFirst(); KNNQuery<O> kNNReach = pair.getSecond(); return doRunInTime(relation.getDBIDs(), kNNRefer, kNNReach, stepprog).getResult(); }
/** * Performs the Generalized LOF algorithm on the given database by calling * {@link #doRunInTime}. * * @param database Database to query * @param relation Data to process * @return LOF outlier result */ public OutlierResult run(Database database, Relation<O> relation) { StepProgress stepprog = LOG.isVerbose() ? new StepProgress("LOF", 3) : null; Pair<KNNQuery<O>, KNNQuery<O>> pair = getKNNQueries(database, relation, stepprog); KNNQuery<O> kNNRefer = pair.getFirst(); KNNQuery<O> kNNReach = pair.getSecond(); return doRunInTime(relation.getDBIDs(), kNNRefer, kNNReach, stepprog).getResult(); }
/** * Performs the Generalized LOF algorithm on the given database by calling * {@link #doRunInTime}. * * @param database Database to query * @param relation Data to process * @return LOF outlier result */ public OutlierResult run(Database database, Relation<O> relation) { StepProgress stepprog = LOG.isVerbose() ? new StepProgress("LOF", 3) : null; Pair<KNNQuery<O>, KNNQuery<O>> pair = getKNNQueries(database, relation, stepprog); KNNQuery<O> kNNRefer = pair.getFirst(); KNNQuery<O> kNNReach = pair.getSecond(); return doRunInTime(relation.getDBIDs(), kNNRefer, kNNReach, stepprog).getResult(); }
private static <T, F extends Format<T>> F makeByOptOverview(Map<OptionID, List<Pair<Parameter<?>, Class<?>>>> byopt, F format) { format.init("ELKI command line parameter overview by option"); for(OptionID oid : sorted(byopt.keySet(), SORT_BY_OPTIONID)) { Parameter<?> firstopt = byopt.get(oid).get(0).getFirst(); T optdl = format.writeOptionD(format.topDList(), firstopt); // class restriction? Class<?> superclass = getRestrictionClass(oid, firstopt, byopt); format.appendClassRestriction(optdl, superclass); // default value format.appendDefaultValueIfSet(optdl, firstopt); // known values? format.appendKnownImplementationsIfNonempty(optdl, superclass); // nested definition list for options T classesul = format.makeUList(optdl, HEADER_PARAMETER_FOR); for(Pair<Parameter<?>, Class<?>> clinst : sorted(byopt.get(oid), SORT_BY_OPTIONID_PRIORITY)) { T classli = format.writeClassU(classesul, clinst.getSecond()); Class<?> ocls = getRestrictionClass(clinst.getFirst()); // TODO: re-add back reporting of *removed* class restrictions. if(ocls != null && !ocls.equals(superclass)) { format.appendClassRestriction(classli, ocls); } Parameter<?> param = clinst.getFirst(); // FIXME: re-add back if a subtype removes the default value if(param.getDefaultValue() != null && !param.getDefaultValue().equals(firstopt.getDefaultValue())) { format.appendDefaultValueIfSet(classli, param); } } } return format; }