integraal.binding.DefaultInteGraalBinding Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of brunner-integraal Show documentation
Show all versions of brunner-integraal Show documentation
InteGraal module for the BRunner project
package integraal.binding;
import java.io.FileNotFoundException;
import java.io.Serializable;
import java.text.ParseException;
import api.definition.ITask;
import api.definition.config.inputdata.IKBScenario;
import api.running.IService;
import api.running.IToolBinding;
import constants.BRunnerKeywords;
import fr.boreal.component_builder.api.IAlgorithmParameters;
import fr.boreal.component_builder.api.IInputDataScenario;
import fr.boreal.component_builder.api.InteGraalKeywords;
import integraal.services.concrete.InteGraal_CSVEncodingFromRLSFile;
import integraal.services.concrete.InteGraal_Explanations;
import integraal.services.concrete.InteGraal_KBChase;
import integraal.services.concrete.InteGraal_OMQAChase;
import integraal.services.concrete.InteGraal_OMQAHybridChaseAndRewriting;
import integraal.services.concrete.InteGraal_OMQARew;
import integraal.services.concrete.InteGraal_OMQRewriting;
import integraal.services.concrete.InteGraal_QA;
import tools.utils.EnumerationUtils;
/**
* A binding for InteGraal.
*/
public class DefaultInteGraalBinding implements IToolBinding, Serializable {
private static final long serialVersionUID = 8838950187567557219L;
@Override
public IService createServiceFrom(ITask task) throws FileNotFoundException, ParseException {
checkServiceKeyAndValue(task);
IInputDataScenario ids = BRunnerToInteGraalTranslator.translateScenario((IKBScenario) task.inputData());
IAlgorithmParameters iap = BRunnerToInteGraalTranslator.translateAlgorithmParameters(task.toolParams());
return switch (extractServiceType(task)) {
case KB_CHASE -> new InteGraal_KBChase(ids, iap);
case OMQ_REWRITING -> new InteGraal_OMQRewriting(ids, iap);
case QUERY_ANSWERING -> new InteGraal_QA(ids, iap);
case QUERY_ANSWERING_VIA_HYBRID_STRATEGY -> new InteGraal_OMQAHybridChaseAndRewriting(ids, iap);
case OMQA_REW -> new InteGraal_OMQARew(ids, iap);
case OMQA_CHASE -> new InteGraal_OMQAChase(ids, iap);
case QUERY_EXPLANATION -> new InteGraal_Explanations(ids, iap);
case RULE_COMPILATION ->
throw new UnsupportedOperationException("Unimplemented case: " + extractServiceType(task));
case CSV_RLS_ENCODING -> new InteGraal_CSVEncodingFromRLSFile(ids, iap);
default -> throw new IllegalArgumentException("Unexpected value: " + extractServiceType(task));
};
}
private InteGraalKeywords.Algorithm extractServiceType(ITask task) {
String serviceName = task.toolParams().getValues(BRunnerKeywords.InnerLevel.SERVICE.full).stream().findAny().get();
return EnumerationUtils.getEnumFromString(InteGraalKeywords.Algorithm.class, serviceName);
}
private void checkServiceKeyAndValue(ITask task) {
if (!task.toolParams().containsProperty(BRunnerKeywords.InnerLevel.SERVICE.full)) {
throw new IllegalArgumentException(
"missing " + BRunnerKeywords.InnerLevel.SERVICE.full + " in benchmark configuration file");
}
}
}