Skip to content

Commit

Permalink
Actually no need to change the parameters and all that unnecessary ge…
Browse files Browse the repository at this point in the history
…nerator codes. Big helps from Jorge.
  • Loading branch information
ErdemYabaci committed Apr 4, 2024
1 parent bc7b1ca commit 5bb4ceb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Question generate(String id) {
String rightAnswer = getRightAnswer(idi.getJsonClaims());

//get the wrong answers
List<String> answers = getWrongAnswers(rightAnswer, type);
List<String> answers = getWrongAnswers(rightAnswer);

answers.add(0, rightAnswer);
//create and return the question
Expand All @@ -93,7 +93,7 @@ protected String getQuestion(String name) {
}

protected abstract String getRightAnswer(Map<String, List<Statement>> claims);
protected abstract List<String> getWrongAnswers(String rightAnswer, QuestionType type);
protected abstract List<String> getWrongAnswers(String rightAnswer);


public String getPropertyId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@
import org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException;

import main.java.questionGenerator.entityGenerator.EntityGenerator;
import main.java.questionGenerator.generator.specificGenerators.CapitalGenerator;
import main.java.questionGenerator.generator.specificGenerators.LanguageGenerator;
import main.java.questionGenerator.generator.specificGenerators.PopulationGenerator;
import main.java.questionGenerator.generator.specificGenerators.SizeGenerator;
import main.java.questionGenerator.question.QuestionType;

public abstract class AnswersAreEntities extends AbstractGenerator {

private final String PROPERTY_TO_CHECK;
private final QuestionType type;

public AnswersAreEntities(String propertyId, QuestionType type, String propertyToCheck, String message) {
super(propertyId, type, message);
this.PROPERTY_TO_CHECK = propertyToCheck;
this.type = type;
}

@Override
Expand Down Expand Up @@ -93,59 +91,21 @@ protected String getIdFromLink(String url) {
String[] split2 = split1[0].split("/");
return split2[split2.length-1];
}

private AbstractGenerator generator;
private String languageCode;

private void setGenerator(QuestionType type) {
switch (type) {
case POPULATION: {
generator = new PopulationGenerator();
break;
}
case CAPITAL: {
generator = new CapitalGenerator();
break;

}
case SIZE: {
generator = new SizeGenerator();
break;
}
case LANGUAGE: {
generator = new LanguageGenerator();
break;
}
}
}

@Override
protected List<String> getWrongAnswers(String rightAnswer, QuestionType type) {
setGenerator(type);
generator.setLocalization(languageCode);
protected List<String> getWrongAnswers(String rightAnswer) {
List<String> entites = new ArrayList<>();
try {
entites = EntityGenerator.getEntities(type, 100);
} catch (IOException e) {
e.printStackTrace();
}
Random rnd = new Random();
List<String> chosen = new ArrayList<>();
int size = entites.size();
int number = 0;
while(number<50) {
int index = rnd.nextInt(size);
String entity = entites.get(index);
if(!chosen.contains(entity)) {
chosen.add(entity);
number++;
}
}
List<String> result = new ArrayList<>();
List<Integer> used = new ArrayList<>();
for(int i = 0; i < 3; i++){
int rndnum = rnd.nextInt(chosen.size());
String wrong = getAnswer(chosen.get(rndnum));
int rndnum = rnd.nextInt(entites.size());
String wrong = getAnswer(entites.get(rndnum));
if(wrong == null || wrong.equals(rightAnswer) || used.contains(rndnum))
i--;
else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public AnswersAreNotEntites(String propertyId, QuestionType type, String message
}

@Override
protected List<String> getWrongAnswers(String rightAnswer, QuestionType type) {
protected List<String> getWrongAnswers(String rightAnswer) {
int inumber = 0;
float fnumber = 0;
// Check if it is a float
Expand Down

0 comments on commit 5bb4ceb

Please sign in to comment.