Skip to content

Commit

Permalink
Feat: Added new question (with the calls)
Browse files Browse the repository at this point in the history
  • Loading branch information
UO283615 committed Apr 28, 2024
1 parent bab3260 commit 1d7617a
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
7 changes: 7 additions & 0 deletions questiongenerator/src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public static void main(String[] args) {
new MusicAuthorQuestion("es");
}

if (GeneralRepositoryStorer.doesntExist(AnswerCategory.GAMES_RELEASE)) {
new VideogamesReleaseDate("en");
new VideogamesReleaseDate("es");
}


// IMAGES
if(GeneralRepositoryStorer.doesntExist(AnswerCategory.STADIUM)) {
Expand All @@ -65,6 +70,8 @@ public static void main(String[] args) {
new CountryFlagQuestion("es");
}



/*
// VIDEOS not yet supported
if(GeneralRepositoryStorer.doesntExist(AnswerCategory.SONG.toString())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package templates;

import model.*;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class VideogamesReleaseDate extends QuestionTemplate {
List<String> videoGameLabels;

private static final String[] spanishStringsIni = {"¿Cuándo fue publicado ", "¿En qué fecha fue lanzado ", "¿Cuándo fue lanzado ", "¿En qué fecha fue publicado "};
private static final String[] englishStringsIni= {"When was ", "On what date was ", "When was ", "On what date was "};

private static final String[] spanishStringsFin = {"?", "?", "?", "?"};
private static final String[] englishStringsFin = {" released?", " released?", " launched?", " launched?"};

public VideogamesReleaseDate(String langCode) {
super(langCode);
}

@Override
public void setQuery() {
this.sparqlQuery = "SELECT ?gameLabel (MAX(?unitsSoldValue) as ?maxUnitsSold) (MIN(?publicationDate) as ?oldestPublicationDate)\n" +
"WHERE { " +
" ?game wdt:P31 wd:Q7889; " +
" wdt:P2664 ?unitsSoldValue. " +
" ?game wdt:P577 ?publicationDate. " +
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"" + langCode + "\". } " +
"} " +
"GROUP BY ?game ?gameLabel " +
"ORDER BY DESC(?maxUnitsSold) " +
"LIMIT 150 ";
}

@Override
public void processResults() {
videoGameLabels = new ArrayList<>();
List<Question> questions = new ArrayList<>();
List<Answer> answers = new ArrayList<>();

for (int i = 0; i < results.length()-10; i++) {

JSONObject result = results.getJSONObject(i);

String videoGameLabel = "";
String publishDateLabel = "";

try {
JSONObject videoGameLabelObject = result.getJSONObject("gameLabel");
videoGameLabel = videoGameLabelObject.getString("value");

JSONObject publishDateLabelObject = result.getJSONObject("oldestPublicationDate");
publishDateLabel = publishDateLabelObject.getString("value");

publishDateLabel = publishDateLabel.substring(0, 4);

} catch (Exception e) {
continue;
}

if (needToSkip(videoGameLabel, publishDateLabel))
continue;

Answer a = new Answer(publishDateLabel, AnswerCategory.GAMES_RELEASE, langCode);
answers.add(a);

if (langCode.equals("es"))
questions.add(new Question(a, "¿Qué compañía publicó " + videoGameLabel + "?", QuestionCategory.VIDEOGAMES, QuestionType.TEXT));
else
questions.add(new Question(a, "Who published " + videoGameLabel + "?", QuestionCategory.VIDEOGAMES, QuestionType.TEXT));
}

repository.saveAll(new ArrayList<>(answers));
repository.saveAll(new ArrayList<>(questions));
}

private boolean needToSkip(String videoGameLabel, String countryLabel) {
if (videoGameLabels.contains(videoGameLabel)) {
return true;
}
videoGameLabels.add(videoGameLabel);

if (QGHelper.isEntityName(videoGameLabel) || QGHelper.isEntityName(countryLabel))
return true;

return false;
}
}

0 comments on commit 1d7617a

Please sign in to comment.