Skip to content

Commit

Permalink
#250, #344 - added option to upload dataset and answer file
Browse files Browse the repository at this point in the history
  • Loading branch information
TortugaAttack committed Jul 14, 2020
1 parent 0b4b28c commit d526c11
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public Annotator getAnnotator(ExperimentType experimentType) throws GerbilExcept
}

protected Annotator loadAnnotator(ExperimentType experimentType) throws Exception {
datasetConfig.setQuestionLanguage(this.questionLang);
Dataset dataset = datasetConfig.getDataset(experimentType);
if (dataset == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,38 @@ public abstract class AbstractDatasetConfiguration extends AbstractAdapterConfig
protected EntityCheckerManager entityCheckerManager;
protected SameAsRetriever globalRetriever;
protected String questionLang;
protected String questionLabel;

public AbstractDatasetConfiguration(String datasetName, boolean couldBeCached,
public AbstractDatasetConfiguration(String datasetName,boolean couldBeCached,
ExperimentType applicableForExperiment, EntityCheckerManager entityCheckerManager,
SameAsRetriever globalRetriever) {
super(datasetName, couldBeCached, applicableForExperiment);
this.questionLabel=datasetName;
this.entityCheckerManager = entityCheckerManager;
this.globalRetriever = globalRetriever;
}


public AbstractDatasetConfiguration(String datasetName, String questionLabel, boolean couldBeCached,
ExperimentType applicableForExperiment, EntityCheckerManager entityCheckerManager,
SameAsRetriever globalRetriever) {
super(datasetName, couldBeCached, applicableForExperiment);
this.questionLabel=questionLabel;
this.entityCheckerManager = entityCheckerManager;
this.globalRetriever = globalRetriever;
}

public void setQuestionLang(String questionLang){
this.questionLang = questionLang;
}

public String getQuestionLabel() {
return questionLabel;
}

public void setQuestionLabel(String questionLabel) {
this.questionLabel = questionLabel;
}

@Override
public Dataset getDataset(ExperimentType experimentType) throws GerbilException {
// for (int i = 0; i < applicableForExperiments.length; ++i) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/aksw/gerbil/dataset/Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ public interface Dataset extends Closeable {
public void setQuestionLanguage(String qLang);

public String getQuestionLanguage();

public String getQuestionLabel();

public void setQuestionLabel(String questionLabel);
}
18 changes: 18 additions & 0 deletions src/main/java/org/aksw/gerbil/dataset/impl/AbstractDataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
public abstract class AbstractDataset implements Dataset {

protected String name;
protected String questionLabel;
protected ClosePermitionGranter granter;
protected String qLang;

Expand All @@ -33,6 +34,23 @@ public AbstractDataset() {

public AbstractDataset(String name) {
this.name = name;
this.questionLabel=name;
}


public AbstractDataset(String name, String questionLabel) {
this.name = name;
this.questionLabel=questionLabel;
}

@Override
public String getQuestionLabel() {
return questionLabel;
}

@Override
public void setQuestionLabel(String questionLabel) {
this.questionLabel = questionLabel;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.aksw.gerbil.qa.QALDStreamUtils;
import org.aksw.gerbil.qa.QAUtils;
import org.aksw.gerbil.transfer.nif.Document;
import org.aksw.gerbil.web.config.AdapterManager;
import org.aksw.qa.commons.datastructure.IQuestion;
import org.aksw.qa.commons.load.LoaderController;
import org.aksw.qa.commons.load.json.EJQuestionFactory;
Expand All @@ -40,8 +41,8 @@ public FileBasedQALDDataset(String file){
this.file=file;
initLanguage();
}
public FileBasedQALDDataset(String name, String file){
super(name);
public FileBasedQALDDataset(String name, String questionLabel, String file){
super(name, questionLabel);
this.file=file;
initLanguage();
}
Expand All @@ -52,14 +53,14 @@ public FileBasedQALDDataset(String file, QALDStreamType fileType) {
initLanguage();
}

public FileBasedQALDDataset(String name, String file, QALDStreamType fileType) {
super(name);
public FileBasedQALDDataset(String name, String questionLabel, String file, QALDStreamType fileType) {
super(name, questionLabel);
this.file = file;
this.fileType = fileType;
initLanguage();
}
public FileBasedQALDDataset(String name, String file, String questionLanguage) {
super(name);
public FileBasedQALDDataset(String name, String questionLabel, String file, String questionLanguage) {
super(name, questionLabel);
this.file = file;
this.fileType = fileType;
this.qLang=questionLanguage;
Expand All @@ -86,7 +87,7 @@ public void init() throws GerbilException {
try {
fin = new FileInputStream(file);
if(fileType!=null){
instances = QALDStreamUtils.parseDocument(fin, fileType, getName());
instances = QALDStreamUtils.parseDocument(fin, fileType, getQuestionLabel());
}
else{
List<IQuestion> questions;
Expand All @@ -96,7 +97,7 @@ public void init() throws GerbilException {
//XML
questions = LoaderController.loadXML(fin, null, qLang);
}
instances = generateInstancesFromQuestions(getName(), questions, qLang);
instances = generateInstancesFromQuestions(getQuestionLabel(), questions, qLang);
}
} catch (Exception e) {
IOUtils.closeQuietly(fin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ public QALDFileDatasetConfig(String name, String file, boolean couldBeCached, Ex
this.file = file;
}


public QALDFileDatasetConfig(String name, String questionLabel, String file, boolean couldBeCached, ExperimentType applicableForExperiment,
EntityCheckerManager entityCheckerManager, SameAsRetriever globalRetriever) {
super(name, questionLabel, couldBeCached, applicableForExperiment, entityCheckerManager, globalRetriever);
this.file = file;
}

@Override
protected Dataset loadDataset() throws Exception {
FileBasedQALDDataset dataset = new FileBasedQALDDataset(getName(), file);
FileBasedQALDDataset dataset = new FileBasedQALDDataset(getName(), getQuestionLabel(), file, questionLang);
dataset.setQuestionLanguage(questionLang);
dataset.init();
return dataset;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/aksw/gerbil/execute/ExperimentTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ protected void prepareAnnotatorResults(List<? extends List<? extends Meaning>> r
case Sc2KB:
case OKE_Task1: // falls through
case OKE_Task2:
case QA:

case ETyping: {
if (annotatorSameAsRetriever != null) {
for (List<? extends Meaning> result : results) {
Expand All @@ -257,6 +257,7 @@ protected void prepareAnnotatorResults(List<? extends List<? extends Meaning>> r
}
return;
}
case QA:
case ERec:// falls through
default:
// nothing to do
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/aksw/gerbil/web/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public ModelAndView index() {
for (String answerFile : answerFiles) {
configs[count] = new ExperimentTaskConfiguration(adapterManager.getAnnotatorConfig(answerFile, type, qLang),
adapterManager.getDatasetConfig(answerFile, type, qLang), type, getMatching(matching), qLang);

LOGGER.debug("Created config: {}", configs[count]);
++count;
}
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/org/aksw/gerbil/web/config/AdapterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public class AdapterManager {
private static final String NIF_WS_PREFIX = "NIFWS_";
private static final String NIF_WS_SUFFIX = " (WS)";
private static final String AF_PREFIX = "AF_";
private static final String UPLOADED_AF_SUFFIX = " (uploaded)";
private static final String AFDS_PREFIX = "AFDS_";
public static final String UPLOADED_AF_SUFFIX = " (uploaded)";
private static final String UPLOADED_FILES_PATH_PROPERTY_KEY = "org.aksw.gerbil.UploadPath";
private static final String UPLOADED_DATASET_SUFFIX = " (uploaded)";
private static final String UPLOADED_DATASET_PREFIX = "NIFDS_";
Expand Down Expand Up @@ -164,8 +165,8 @@ public AnnotatorConfiguration getAnnotatorConfig(String name, ExperimentType typ
try {
return new InstanceListBasedConfigurationImpl(name, false,
new DatasetConfigurationImpl(datasetName, false,
FileBasedQALDDataset.class.getConstructor(String.class, String.class, String.class),
new Object[] { datasetName, uploadedFilesPath + fileName, questionLanguage},
FileBasedQALDDataset.class.getConstructor(String.class, String.class, String.class, String.class),
new Object[] { datasetName, datasetName.replace(AFDS_PREFIX, ""), uploadedFilesPath + fileName, questionLanguage},
ExperimentType.QA, null, null),
type, questionLanguage);
} catch (Exception e) {
Expand Down Expand Up @@ -207,8 +208,9 @@ public DatasetConfiguration getDatasetConfig(String name, ExperimentType type, S
}
String uri = uploadedFilesPath + name.substring(brackets[0] + 1, brackets[1]);
// remove dataset prefix from the name
name = name.substring(UPLOADED_DATASET_PREFIX.length(), brackets[0]) + UPLOADED_DATASET_SUFFIX;
return new QALDFileDatasetConfig(name, uri, false, type, entityCheckerManager, globalRetriever);
String questionLabel = name.substring(UPLOADED_DATASET_PREFIX.length(), brackets[0]);
name = questionLabel + UPLOADED_DATASET_SUFFIX;
return new QALDFileDatasetConfig(name, questionLabel, uri, false, type, entityCheckerManager, globalRetriever);
}
if (name.startsWith(AF_PREFIX)) {
// This describes a QA answer file
Expand All @@ -223,6 +225,11 @@ public DatasetConfiguration getDatasetConfig(String name, ExperimentType type, S
String datasetName = name.substring(brackets[0] + 1, brackets[1]);
return getDatasetConfig(datasetName, type, questionLanguage);
}
if(name.startsWith(AFDS_PREFIX)){
String formatted= name.replace(AFDS_PREFIX, "");
return getDatasetConfig("NIFDS_"+formatted+"("+formatted+")", type, questionLanguage);

}
}
LOGGER.error("Got an unknown annotator name\"" + name + "\". Returning null.");
return null;
Expand Down
Loading

0 comments on commit d526c11

Please sign in to comment.