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

org.aksw.jenax.arq.aggregation.BestLiteralConfig Maven / Gradle / Ivy

The newest version!
package org.aksw.jenax.arq.aggregation;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import org.aksw.jenax.arq.util.var.Vars;
import org.apache.jena.graph.Node;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.sparql.core.Var;

public class BestLiteralConfig {

    protected LiteralPreference literalPreference;
    protected Var subjectVar;
    protected Var predicateVar;
    protected Var objectVar;

    public BestLiteralConfig(LiteralPreference literalPreference) {
        this(literalPreference, Vars.s, Vars.p, Vars.o);
    }

    public BestLiteralConfig(
            LiteralPreference literalPreference,
            Var subjectVar,
            Var predicateVar,
            Var objectVar) {
        this.literalPreference = literalPreference;
        this.subjectVar = subjectVar;
        this.predicateVar = predicateVar;
        this.objectVar = objectVar;
    }

    public LiteralPreference getLiteralPreference() {
        return literalPreference;
    }

    public Var getSubjectVar() {
        return subjectVar;
    }

    public Var getPredicateVar() {
        return predicateVar;
    }

    public Var getObjectVar() {
        return objectVar;
    }

    /**
     * Convenience method
     *
     */
    public List getLangs() {
        List result = this.literalPreference.getLangs();
        return result;
    }

    /**
     * Convenience method
     *
     */
    public List getPredicates() {
        List result = this.literalPreference.getPredicates();
        return result;
    }

    public static BestLiteralConfig fromProperty(Property property) {
        BestLiteralConfig result = new BestLiteralConfig(new LiteralPreference(
                null, Collections.singletonList(property.asNode()), false));
        return result;
    }

    @Override
    public String toString() {
        String result = Arrays.asList(
                "BestLabelConfig", getLangs(), getPredicates(),
                getSubjectVar(), getPredicateVar(), getObjectVar())
                .stream().map(Objects::toString).collect(Collectors.joining(", "));
        return result;
    }
}