use of de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException in project elki by elki-project.
the class CheckELKIServices method checkServices.
/**
* Retrieve all properties and check them.
*
* @param update Folder to update service files in
*/
public void checkServices(String update) {
TreeSet<String> props = new TreeSet<>();
Enumeration<URL> us;
try {
us = getClass().getClassLoader().getResources(ELKIServiceLoader.RESOURCE_PREFIX);
} catch (IOException e) {
throw new AbortException("Error enumerating service folders.", e);
}
while (us.hasMoreElements()) {
URL u = us.nextElement();
try {
if (("jar".equals(u.getProtocol()))) {
JarURLConnection con = (JarURLConnection) u.openConnection();
try (JarFile jar = con.getJarFile()) {
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
String prop = entries.nextElement().getName();
if (prop.startsWith(ELKIServiceLoader.RESOURCE_PREFIX)) {
props.add(prop.substring(ELKIServiceLoader.RESOURCE_PREFIX.length()));
} else if (prop.startsWith(ELKIServiceLoader.FILENAME_PREFIX)) {
props.add(prop.substring(ELKIServiceLoader.FILENAME_PREFIX.length()));
}
}
}
continue;
}
if ("file".equals(u.getProtocol())) {
props.addAll(Arrays.asList(new File(u.toURI()).list()));
}
} catch (IOException | URISyntaxException e) {
throw new AbortException("Error enumerating service folders.", e);
}
}
for (String prop : props) {
if (LOG.isVerbose()) {
LOG.verbose("Checking property: " + prop);
}
checkService(prop, update);
}
}
use of de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException in project elki by elki-project.
the class CheckELKIServices method main.
/**
* Main method.
*
* @param argv Command line arguments
*/
public static void main(String[] argv) {
String update = null;
if (argv.length == 2 && "-update".equals(argv[0])) {
update = argv[1];
LOG.info("Updating service files in folder: " + update);
} else if (argv.length != 0) {
throw new AbortException("Incorrect command line parameters.");
}
new CheckELKIServices().checkServices(update);
}
use of de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException in project elki by elki-project.
the class ELKIServiceLoader method load.
/**
* Load the service file.
*/
public static void load(Class<?> parent, ClassLoader cl) {
char[] buf = new char[0x4000];
try {
String fullName = RESOURCE_PREFIX + parent.getName();
Enumeration<URL> configfiles = cl.getResources(fullName);
while (configfiles.hasMoreElements()) {
URL nextElement = configfiles.nextElement();
URLConnection conn = nextElement.openConnection();
conn.setUseCaches(false);
try (InputStreamReader is = new InputStreamReader(conn.getInputStream(), "UTF-8")) {
int start = 0, cur = 0, valid = is.read(buf, 0, buf.length);
char c;
while (cur < valid) {
// Find newline or end
while (cur < valid && (c = buf[cur]) != '\n' && c != '\r') {
cur++;
}
if (cur == valid && is.ready()) {
// Move consumed buffer contents:
if (start > 0) {
System.arraycopy(buf, start, buf, 0, valid - start);
valid -= start;
cur -= start;
start = 0;
} else if (valid == buf.length) {
throw new IOException("Buffer size exceeded. Maximum line length in service files is: " + buf.length + " in file: " + fullName);
}
valid = is.read(buf, valid, buf.length - valid);
continue;
}
parseLine(parent, buf, start, cur, nextElement);
while (cur < valid && ((c = buf[cur]) == '\n' || c == '\r')) {
cur++;
}
start = cur;
}
} catch (IOException x) {
throw new AbortException("Error reading configuration file", x);
}
}
} catch (IOException x) {
throw new AbortException("Could not load service configuration files.", x);
}
}
use of de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException in project elki by elki-project.
the class ArffParser method loadDenseInstance.
private Object[] loadDenseInstance(StreamTokenizer tokenizer, int[] dimsize, TypeInformation[] etyp, int outdim) throws IOException {
Object[] data = new Object[outdim];
for (int out = 0; out < outdim; out++) {
if (TypeUtil.NUMBER_VECTOR_FIELD.equals(etyp[out])) {
// For multi-column vectors, read successive columns
double[] cur = new double[dimsize[out]];
for (int k = 0; k < dimsize[out]; k++) {
if (tokenizer.ttype == '?') {
cur[k] = Double.NaN;
} else if (tokenizer.ttype == StreamTokenizer.TT_WORD) {
try {
cur[k] = ParseUtil.parseDouble(tokenizer.sval);
} catch (NumberFormatException e) {
throw new AbortException("Expected number value, got: " + tokenizer.sval);
}
} else {
throw new AbortException("Expected word token, got: " + tokenizer.toString());
}
nextToken(tokenizer);
}
data[out] = denseFactory.newNumberVector(cur);
} else if (TypeUtil.LABELLIST.equals(etyp[out])) {
// Build a label list out of successive labels
labels.clear();
for (int k = 0; k < dimsize[out]; k++) {
if (tokenizer.ttype != StreamTokenizer.TT_WORD) {
throw new AbortException("Expected word token, got: " + tokenizer.toString());
}
labels.add(tokenizer.sval);
nextToken(tokenizer);
}
data[out] = LabelList.make(labels);
} else if (TypeUtil.EXTERNALID.equals(etyp[out])) {
if (tokenizer.ttype != StreamTokenizer.TT_WORD) {
throw new AbortException("Expected word token, got: " + tokenizer.toString());
}
data[out] = new ExternalID(tokenizer.sval);
nextToken(tokenizer);
} else if (TypeUtil.CLASSLABEL.equals(etyp[out])) {
if (tokenizer.ttype != StreamTokenizer.TT_WORD) {
throw new AbortException("Expected word token, got: " + tokenizer.toString());
}
// TODO: support other class label types.
ClassLabel lbl = new SimpleClassLabel(tokenizer.sval);
data[out] = lbl;
nextToken(tokenizer);
} else {
throw new AbortException("Unsupported type for column " + "->" + out + ": " + ((etyp[out] != null) ? etyp[out].toString() : "null"));
}
}
return data;
}
use of de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException in project elki by elki-project.
the class ArffParser method setupBundleHeaders.
/**
* Setup the headers for the object bundle.
*
* @param names Attribute names
* @param targ Target columns
* @param etyp ELKI type information
* @param dimsize Number of dimensions in the individual types
* @param bundle Output bundle
* @param sparse Flag to create sparse vectors
*/
private void setupBundleHeaders(ArrayList<String> names, int[] targ, TypeInformation[] etyp, int[] dimsize, MultipleObjectsBundle bundle, boolean sparse) {
for (int in = 0, out = 0; in < targ.length; out++) {
int nin = in + 1;
for (; nin < targ.length; nin++) {
if (targ[nin] != targ[in]) {
break;
}
}
if (TypeUtil.NUMBER_VECTOR_FIELD.equals(etyp[out])) {
String[] labels = new String[dimsize[out]];
// Collect labels:
for (int i = 0; i < dimsize[out]; i++) {
labels[i] = names.get(out + i);
}
if (!sparse) {
VectorFieldTypeInformation<DoubleVector> type = new VectorFieldTypeInformation<>(DoubleVector.FACTORY, dimsize[out], labels);
bundle.appendColumn(type, new ArrayList<DoubleVector>());
} else {
VectorFieldTypeInformation<SparseDoubleVector> type = new VectorFieldTypeInformation<>(SparseDoubleVector.FACTORY, dimsize[out], labels);
bundle.appendColumn(type, new ArrayList<SparseDoubleVector>());
}
} else if (TypeUtil.LABELLIST.equals(etyp[out])) {
StringBuilder label = new StringBuilder(names.get(out));
for (int i = 1; i < dimsize[out]; i++) {
label.append(' ').append(names.get(out + i));
}
bundle.appendColumn(new SimpleTypeInformation<>(LabelList.class, label.toString()), new ArrayList<LabelList>());
} else if (TypeUtil.EXTERNALID.equals(etyp[out])) {
bundle.appendColumn(new SimpleTypeInformation<>(ExternalID.class, names.get(out)), new ArrayList<ExternalID>());
} else if (TypeUtil.CLASSLABEL.equals(etyp[out])) {
bundle.appendColumn(new SimpleTypeInformation<>(ClassLabel.class, names.get(out)), new ArrayList<ClassLabel>());
} else {
throw new AbortException("Unsupported type for column " + in + "->" + out + ": " + ((etyp[out] != null) ? etyp[out].toString() : "null"));
}
assert (out == bundle.metaLength() - 1);
in = nin;
}
}
Aggregations