All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hex.genmodel.algos.targetencoder.ColumnsMapping Maven / Gradle / Ivy

There is a newer version: 3.46.0.5
Show newest version
package hex.genmodel.algos.targetencoder;

import java.io.Serializable;

public class ColumnsMapping implements Serializable {
    private String[] _from;
    private String[] _to;

    public ColumnsMapping(String[] from, String[] to) {
        _from = from;
        _to = to;
    }

    public String[] from() {
        return _from;
    }

    public String[] to() {
        return _to;
    }
}

class ColumnsToSingleMapping extends ColumnsMapping {

    private String[] _toDomain;
    private long[] _toDomainAsNum;

    public ColumnsToSingleMapping(String[] from, String to, String[] toDomain) {
        super(from, new String[]{to});
        _toDomain = toDomain;
        _toDomainAsNum = stringArrayToLong(toDomain);
    }

    public String toSingle() {
        return to()[0];
    }

    public String[] toDomain() {
        return _toDomain;
    }
    
    public long[] toDomainAsNum() {
        return _toDomainAsNum;
    }
    
    private static long[] stringArrayToLong(String[] arr) {
        if (arr == null) return null;
        try {
            long[] res = new long[arr.length];
            for (int i=0; i < arr.length; i++) {
                res[i] = Long.parseLong(arr[i]);
            }
            return res;
        } catch (NumberFormatException nfe) {
            return null;
        }
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy