Search in sources :

Example 1 with FloatArrayTypeProvider

use of org.vitrivr.cineast.core.data.providers.primitive.FloatArrayTypeProvider in project cineast by vitrivr.

the class SpatialImporter method parseEntry.

private Optional<Map<String, PrimitiveTypeProvider>> parseEntry(String key, String[] data) {
    String lat = data[LSCUtilities.META_LAT_COL];
    String lon = data[LSCUtilities.META_LON_COL];
    if (LSCUtilities.isAnyMetaBlank(lat, lon)) {
        LOGGER.warn("Either lat or long for {} is blank. Ignoring.", key);
        return Optional.empty();
    }
    boolean ignore = false;
    float fLat = Float.NaN, fLon = Float.NaN;
    try {
        fLat = Float.parseFloat(lat);
    } catch (NumberFormatException e) {
        LOGGER.warn("Could not parse latitute for {}, as it was {}", key, lat, e);
        ignore = true;
    }
    try {
        fLon = Float.parseFloat(lon);
    } catch (NumberFormatException e) {
        LOGGER.warn("Could not parse longitutde for {}, as it was {}", key, lon, e);
        ignore = true;
    }
    if (ignore) {
        return Optional.empty();
    }
    Location location = Location.of(fLat, fLon);
    FloatArrayTypeProvider vector = new FloatArrayTypeProvider(ReadableFloatVector.toArray(location));
    final HashMap<String, PrimitiveTypeProvider> map = new HashMap<>();
    // id
    map.put("id", PrimitiveTypeProvider.fromObject(LSCUtilities.pathToSegmentId(key)));
    // feature
    map.put("feature", vector);
    return Optional.of(map);
}
Also used : HashMap(java.util.HashMap) FloatArrayTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.FloatArrayTypeProvider) PrimitiveTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider) Location(org.vitrivr.cineast.core.data.Location)

Example 2 with FloatArrayTypeProvider

use of org.vitrivr.cineast.core.data.providers.primitive.FloatArrayTypeProvider in project cineast by vitrivr.

the class StringFloatArrayPair method convert.

@Override
public Map<String, PrimitiveTypeProvider> convert(StringFloatArrayPair data) {
    HashMap<String, PrimitiveTypeProvider> map = new HashMap<>(2);
    map.put("id", new StringTypeProvider(data.id));
    map.put("feature", new FloatArrayTypeProvider(data.vector));
    return map;
}
Also used : StringTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider) HashMap(java.util.HashMap) FloatArrayTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.FloatArrayTypeProvider) PrimitiveTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider)

Aggregations

HashMap (java.util.HashMap)2 FloatArrayTypeProvider (org.vitrivr.cineast.core.data.providers.primitive.FloatArrayTypeProvider)2 PrimitiveTypeProvider (org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider)2 Location (org.vitrivr.cineast.core.data.Location)1 StringTypeProvider (org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider)1