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

org.aksw.jenax.sparql.fragment.api.MappedFragment Maven / Gradle / Ivy

There is a newer version: 5.0.0-1
Show newest version
package org.aksw.jenax.sparql.fragment.api;

import java.util.AbstractMap.SimpleEntry;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import org.apache.jena.graph.Node;
import org.apache.jena.sparql.core.Var;
import org.apache.jena.sparql.graph.NodeTransform;

/** A relation with an additional mapping of variables to custom objects */
public class MappedFragment
    extends FragmentWrapperBase
{
    protected Map mapping;

    protected MappedFragment(Fragment delegate, Map mapping) {
        super(delegate);
        this.mapping = mapping;
    }

    public static  MappedFragment of(Fragment delegate, Map mapping) {
        return new MappedFragment<>(delegate, mapping);
    }

    public Map getMapping() {
        return mapping;
    }

    @Override
    public Fragment applyNodeTransform(NodeTransform nodeTransform) {
        Fragment newDelegate = getDelegate().applyNodeTransform(nodeTransform);
        Map newMapping = mapping.entrySet().stream()
            .map(e -> {
                Node newVar = nodeTransform.apply(e.getKey());
                return new SimpleEntry<>((Var)newVar, e.getValue());
            })
            .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
        return new MappedFragment<>(newDelegate, newMapping);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy