be.ugent.rml.Initializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rmlmapper Show documentation
Show all versions of rmlmapper Show documentation
The RMLMapper executes RML rules to generate high quality Linked Data from multiple originally (semi-)structured data sources.
package be.ugent.rml;
import be.ugent.rml.functions.FunctionLoader;
import be.ugent.rml.store.QuadStore;
import be.ugent.rml.term.NamedNode;
import be.ugent.rml.term.Term;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Initializer {
private final MappingFactory factory;
private QuadStore rmlStore;
private FunctionLoader functionLoader;
private List triplesMaps;
private HashMap mappings;
public Initializer(QuadStore rmlStore, FunctionLoader functionLoader) throws Exception {
this.rmlStore = rmlStore;
//we get all the TriplesMaps from the mapping
this.triplesMaps = this.getAllTriplesMaps();
this.mappings = new HashMap();
if (functionLoader == null) {
this.functionLoader = new FunctionLoader();
} else {
this.functionLoader = functionLoader;
}
this.factory = new MappingFactory(this.functionLoader);
extractMappings();
}
private void extractMappings() throws Exception {
for (Term triplesMap : triplesMaps) {
this.mappings.put(triplesMap, factory.createMapping(triplesMap, rmlStore));
}
}
private List getAllTriplesMaps() {
List maps = Utils.getSubjectsFromQuads(this.rmlStore.getQuads(null, new NamedNode(NAMESPACES.RML + "logicalSource"), null));
//filter outer Triples Maps that are used for functions
ArrayList temp = new ArrayList<>();
for(Term map: maps) {
if (this.rmlStore.getQuads(null, new NamedNode(NAMESPACES.FNML + "functionValue"), map).isEmpty()) {
temp.add(map);
}
}
maps = temp;
if (maps.isEmpty()) {
throw new Error("No Triples Maps found. The mapping document you should at least have one Triples Map.");
} else {
return maps;
}
}
public HashMap getMappings() {
return this.mappings;
}
public List getTriplesMaps() {
return this.triplesMaps;
}
public FunctionLoader getFunctionLoader() {
return this.functionLoader;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy