Skip to content

Commit

Permalink
Fixed problems with the QA evaluation. Removed relying on a matching …
Browse files Browse the repository at this point in the history
…searcher that matches emerging entities since that is untypical behavior in QA.
  • Loading branch information
MichaelRoeder committed Sep 5, 2024
1 parent ab8e720 commit f42aa4f
Show file tree
Hide file tree
Showing 8 changed files with 580 additions and 316 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.ArrayList;
import java.util.List;

import org.aksw.gerbil.config.GerbilConfiguration;
import org.aksw.gerbil.dataset.Dataset;
import org.aksw.gerbil.dataset.InitializableDataset;
import org.aksw.gerbil.dataset.impl.AbstractDataset;
Expand All @@ -17,7 +16,6 @@
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 @@ -33,25 +31,27 @@
public class FileBasedQALDDataset extends AbstractDataset implements InitializableDataset {

private static final String QUESTION_LANGUAGE_KEY = "org.aksw.gerbil.dataset.question.language";
protected List<Document> instances;
protected List<Document> instances;
protected String file;
protected QALDStreamType fileType;

public FileBasedQALDDataset(String file){
this.file=file;
initLanguage();
public FileBasedQALDDataset(String file) {
this.file = file;
initLanguage();
}
public FileBasedQALDDataset(String name, String file){

public FileBasedQALDDataset(String name, String file) {
super(name);
this.file=file;
this.file = file;
initLanguage();
}
public FileBasedQALDDataset(String name, String questionLabel, String file){
super(name, questionLabel);
this.file=file;
initLanguage();

public FileBasedQALDDataset(String name, String questionLabel, String file) {
super(name, questionLabel);
this.file = file;
initLanguage();
}

public FileBasedQALDDataset(String file, QALDStreamType fileType) {
this.file = file;
this.fileType = fileType;
Expand All @@ -64,17 +64,16 @@ public FileBasedQALDDataset(String name, String questionLabel, String file, QALD
this.fileType = fileType;
initLanguage();
}

public FileBasedQALDDataset(String name, String questionLabel, String file, String questionLanguage) {
super(name, questionLabel);
this.file = file;
this.fileType = fileType;
this.qLang=questionLanguage;
}

private void initLanguage(){
this.qLang = "en";
this.qLang = questionLanguage;
}

private void initLanguage() {
this.qLang = "en";
}

@Override
public int size() {
Expand All @@ -91,42 +90,38 @@ public void init() throws GerbilException {
FileInputStream fin = null;
try {
fin = new FileInputStream(file);
if(fileType!=null){
instances = QALDStreamUtils.parseDocument(fin, fileType, getQuestionLabel());
}
else{
List<IQuestion> questions;
//JSON
questions = EJQuestionFactory.getQuestionsFromJson(ExtendedQALDJSONLoader.readJson(new File(file)));
if(questions==null){
//XML
questions = LoaderController.loadXML(fin, null, qLang);
}
instances = generateInstancesFromQuestions(getQuestionLabel(), questions, qLang);
if (fileType != null) {
instances = QALDStreamUtils.parseDocument(fin, fileType, getQuestionLabel());
} else {
List<IQuestion> questions;
// JSON
questions = EJQuestionFactory.getQuestionsFromJson(ExtendedQALDJSONLoader.readJson(new File(file)));
if (questions == null) {
// XML
questions = LoaderController.loadXML(fin, null, qLang);
}
instances = generateInstancesFromQuestions(getQuestionLabel(), questions, qLang);
}
} catch (Exception e) {
IOUtils.closeQuietly(fin);
throw new GerbilException("Couldn't load the given QALD file.", e, ErrorTypes.DATASET_LOADING_ERROR);
IOUtils.closeQuietly(fin);
throw new GerbilException("Couldn't load the given QALD file.", e, ErrorTypes.DATASET_LOADING_ERROR);
}
IOUtils.closeQuietly(fin);
}


private static List<Document> generateInstancesFromQuestions(String adapterName, List<IQuestion> questions, String questionLanguage){
String questionUriPrefix;
try {
questionUriPrefix = "http://qa.gerbil.aksw.org/"
+ URLEncoder.encode(adapterName, "UTF-8") + "/question#";
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException(
"Severe error while trying to encode adapter name.", e);
}

List<Document> instances = new ArrayList<Document>(questions.size());
for (IQuestion question : questions) {
instances.add(QAUtils.translateQuestion(question, questionUriPrefix
+ question.getId(), questionLanguage));
}
return instances;
private static List<Document> generateInstancesFromQuestions(String adapterName, List<IQuestion> questions,
String questionLanguage) {
String questionUriPrefix;
try {
questionUriPrefix = "http://qa.gerbil.aksw.org/" + URLEncoder.encode(adapterName, "UTF-8") + "/question#";
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException("Severe error while trying to encode adapter name.", e);
}

List<Document> instances = new ArrayList<Document>(questions.size());
for (IQuestion question : questions) {
instances.add(QAUtils.translateQuestion(question, questionUriPrefix + question.getId(), questionLanguage));
}
return instances;
}
}
Loading

0 comments on commit f42aa4f

Please sign in to comment.