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

de.julielab.geneexpbase.scoring.ScorerAvg Maven / Gradle / Ivy

package de.julielab.geneexpbase.scoring;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Calculates the average scorer of a number of scorers specified in the constructor.
 */
public class ScorerAvg extends Scorer {
    private final Collection chain;
    private final String info;

    public ScorerAvg(Scorer... scorers) {
        this(List.of(scorers));
    }

    public ScorerAvg(Collection scorers) {
        this.chain = scorers;
        info = chain.stream().map(Scorer::info).collect(Collectors.joining());
    }

    @Override
    public double getScore(String term1, String term2) throws RuntimeException {
        if (chain != null && !chain.isEmpty())
            return chain.stream().mapToDouble(s -> s.getScore(term1, term2)).average().getAsDouble();
        return 0;
    }

    @Override
    public String info() {
        return info;
    }

    @Override
    public int getScorerType() {
        return -1;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy