From fa3da39b8fb2eb82ac85b112ad7af9b9b8ee89df Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Thu, 18 Apr 2024 22:13:45 +0200 Subject: [PATCH 01/22] Feat: Added Pokemon questions --- .../src/main/java/model/AnswerCategory.java | 2 +- .../src/main/java/model/QuestionCategory.java | 2 +- .../templates/WhosThatPokemonQuestion.java | 85 +++++++++++++++++++ 3 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 questiongenerator/src/main/java/templates/WhosThatPokemonQuestion.java diff --git a/questiongenerator/src/main/java/model/AnswerCategory.java b/questiongenerator/src/main/java/model/AnswerCategory.java index 9af4f704..eaf2de22 100644 --- a/questiongenerator/src/main/java/model/AnswerCategory.java +++ b/questiongenerator/src/main/java/model/AnswerCategory.java @@ -1,6 +1,6 @@ package model; public enum AnswerCategory { - CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING + CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON } diff --git a/questiongenerator/src/main/java/model/QuestionCategory.java b/questiongenerator/src/main/java/model/QuestionCategory.java index d39d26dc..a536abfb 100644 --- a/questiongenerator/src/main/java/model/QuestionCategory.java +++ b/questiongenerator/src/main/java/model/QuestionCategory.java @@ -2,5 +2,5 @@ public enum QuestionCategory { //HISTORY, GEOGRAPHY, SCIENCE, MATH, LITERATURE, ART, SPORTS, MUSIC, MOVIES, TV, POLITICS, OTHER - GEOGRAPHY, SPORTS, MUSIC, ART, VIDEOGAMES + GEOGRAPHY, SPORTS, MUSIC, ART, VIDEOGAMES, POKEMON } diff --git a/questiongenerator/src/main/java/templates/WhosThatPokemonQuestion.java b/questiongenerator/src/main/java/templates/WhosThatPokemonQuestion.java new file mode 100644 index 00000000..2ca43542 --- /dev/null +++ b/questiongenerator/src/main/java/templates/WhosThatPokemonQuestion.java @@ -0,0 +1,85 @@ +package templates; + +import model.*; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public class WhosThatPokemonQuestion extends QuestionTemplate { + + + List pokemonLabels; + + private static final String CONCAT = "%& #"; + + private static final String[] spanishStrings = {"¿Quién es este Pokémon?", "¿Cuál es este Pokémon?", "¿Qué Pokémon es este?", "¿Cómo se llama este Pokémon?"}; + private static final String[] englishStrings = {"Who's that Pokémon?", "What Pokémon is this?", "What's the name of this Pokémon?", "Who is this Pokémon?"}; + + public WhosThatPokemonQuestion(String langCode) { + super(langCode); + } + + @Override + public void setQuery() { + this.sparqlQuery = "SELECT ?pokemonLabel ?pokemonIndex " + + "WHERE { " + + " ?pokemon wdt:P1441 wd:Q864; " + + " wdt:P1685 ?pokemonIndex. " + + " SERVICE wikibase:label { bd:serviceParam wikibase:language \"" + langCode + "\". } " + + "} "; + } + + @Override + public void processResults() { + pokemonLabels = new ArrayList<>(); + List questions = new ArrayList<>(); + List answers = new ArrayList<>(); + + String spanishString = ""; + String englishString = ""; + + for (int i = 0; i < results.length(); i++) { + JSONObject result = results.getJSONObject(i); + String pokemonLabel = result.getJSONObject("pokemonLabel").getString("value"); + String pokemonIndex = result.getJSONObject("pokemonIndex").getString("value"); + + if (needToSkip(pokemonLabel, pokemonIndex)) { + continue; + } + + int pokedexNum = Integer.parseInt(pokemonIndex); + + Answer a = new Answer(pokemonLabel, AnswerCategory.WTPOKEMON, langCode); + answers.add(a); + + if (langCode.equals("es")){ + spanishString = spanishStrings[i%4] + CONCAT + "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/" + pokedexNum + ".png"; + questions.add(new Question(a, spanishString, QuestionCategory.POKEMON, QuestionType.TEXT)); + } + else{ + englishString = englishStrings[i%4] + CONCAT + "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/" + pokedexNum + ".png"; + questions.add(new Question(a, englishString, QuestionCategory.POKEMON, QuestionType.TEXT)); + } + } + + repository.saveAll(new ArrayList<>(answers)); + repository.saveAll(new ArrayList<>(questions)); + } + + private boolean needToSkip(String pokemonLabel, String pokemonIndex){ + if (pokemonLabels.contains(pokemonLabel)) { + return true; + } + pokemonLabels.add(pokemonLabel); + + // If pokemonIndex is not a number, skip + try { + Integer.parseInt(pokemonIndex); + } catch (NumberFormatException e) { + return true; + } + + return false; + } +} From f4a71d2862f5b80062adc95b022a90565b57358e Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Thu, 18 Apr 2024 22:18:18 +0200 Subject: [PATCH 02/22] Chore: improved code quality --- .../repositories/GeneralRepositoryStorer.java | 2 -- .../main/java/templates/PaintingQuestion.java | 17 ++++------------ .../src/main/java/templates/QGHelper.java | 20 +++++++++++++++++++ .../main/java/templates/StadiumQuestion.java | 5 ++--- .../templates/WhosThatPokemonQuestion.java | 6 ++---- 5 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 questiongenerator/src/main/java/templates/QGHelper.java diff --git a/questiongenerator/src/main/java/repositories/GeneralRepositoryStorer.java b/questiongenerator/src/main/java/repositories/GeneralRepositoryStorer.java index 1ef56146..88490702 100644 --- a/questiongenerator/src/main/java/repositories/GeneralRepositoryStorer.java +++ b/questiongenerator/src/main/java/repositories/GeneralRepositoryStorer.java @@ -14,8 +14,6 @@ */ public class GeneralRepositoryStorer { - public static final String LINKCONCAT = "#* &%"; - public void saveAll(List storableList) { EntityManagerFactory emf = Jpa.getEntityManagerFactory(); EntityManager entityManager = emf.createEntityManager(); diff --git a/questiongenerator/src/main/java/templates/PaintingQuestion.java b/questiongenerator/src/main/java/templates/PaintingQuestion.java index eafac578..f30f0332 100644 --- a/questiongenerator/src/main/java/templates/PaintingQuestion.java +++ b/questiongenerator/src/main/java/templates/PaintingQuestion.java @@ -2,7 +2,6 @@ import model.*; import org.json.JSONObject; -import repositories.GeneralRepositoryStorer; import java.util.ArrayList; import java.util.List; @@ -63,9 +62,9 @@ public void processResults() { answers.add(a); if (langCode.equals("es")) - questions.add(new Question(a, "¿Cuál es este cuadro?" + GeneralRepositoryStorer.LINKCONCAT + imageLink, QuestionCategory.ART, QuestionType.IMAGE)); + questions.add(new Question(a, "¿Cuál es este cuadro?" + QGHelper.LINKCONCAT + imageLink, QuestionCategory.ART, QuestionType.IMAGE)); else - questions.add(new Question(a, "Which painting is this?" + GeneralRepositoryStorer.LINKCONCAT + imageLink, QuestionCategory.ART, QuestionType.IMAGE)); + questions.add(new Question(a, "Which painting is this?" + QGHelper.LINKCONCAT + imageLink, QuestionCategory.ART, QuestionType.IMAGE)); } repository.saveAll(new ArrayList<>(answers)); @@ -78,16 +77,8 @@ private boolean needToSkip(String paintingLabel) { } paintingLabels.add(paintingLabel); - boolean isEntityName = true; // Check if it is like Q232334 - if (paintingLabel.startsWith("Q") ){ - for (int i=1; i(answers)); diff --git a/questiongenerator/src/main/java/templates/WhosThatPokemonQuestion.java b/questiongenerator/src/main/java/templates/WhosThatPokemonQuestion.java index 2ca43542..487af369 100644 --- a/questiongenerator/src/main/java/templates/WhosThatPokemonQuestion.java +++ b/questiongenerator/src/main/java/templates/WhosThatPokemonQuestion.java @@ -11,8 +11,6 @@ public class WhosThatPokemonQuestion extends QuestionTemplate { List pokemonLabels; - private static final String CONCAT = "%& #"; - private static final String[] spanishStrings = {"¿Quién es este Pokémon?", "¿Cuál es este Pokémon?", "¿Qué Pokémon es este?", "¿Cómo se llama este Pokémon?"}; private static final String[] englishStrings = {"Who's that Pokémon?", "What Pokémon is this?", "What's the name of this Pokémon?", "Who is this Pokémon?"}; @@ -54,11 +52,11 @@ public void processResults() { answers.add(a); if (langCode.equals("es")){ - spanishString = spanishStrings[i%4] + CONCAT + "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/" + pokedexNum + ".png"; + spanishString = spanishStrings[i%4] + QGHelper.LINKCONCAT + "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/" + pokedexNum + ".png"; questions.add(new Question(a, spanishString, QuestionCategory.POKEMON, QuestionType.TEXT)); } else{ - englishString = englishStrings[i%4] + CONCAT + "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/" + pokedexNum + ".png"; + englishString = englishStrings[i%4] + QGHelper.LINKCONCAT + "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/" + pokedexNum + ".png"; questions.add(new Question(a, englishString, QuestionCategory.POKEMON, QuestionType.TEXT)); } } From f7eb3b8f32c86517d6db13b8ff943ec9f12b45c3 Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Thu, 18 Apr 2024 23:25:50 +0200 Subject: [PATCH 03/22] Chore: Improved the image managing, now https calls and checking extensions --- questiongenerator/src/main/java/Main.java | 5 +++++ .../main/java/templates/PaintingQuestion.java | 9 +++++++-- .../src/main/java/templates/QGHelper.java | 10 ++++++++++ .../main/java/templates/StadiumQuestion.java | 17 +++++------------ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/questiongenerator/src/main/java/Main.java b/questiongenerator/src/main/java/Main.java index 6d0a7b54..be0b3c22 100644 --- a/questiongenerator/src/main/java/Main.java +++ b/questiongenerator/src/main/java/Main.java @@ -37,6 +37,11 @@ public static void main(String[] args) { new PaintingQuestion("es"); } + if (GeneralRepositoryStorer.doesntExist(AnswerCategory.WTPOKEMON)) { + new WhosThatPokemonQuestion("en"); + new WhosThatPokemonQuestion("es"); + } + /* // VIDEOS diff --git a/questiongenerator/src/main/java/templates/PaintingQuestion.java b/questiongenerator/src/main/java/templates/PaintingQuestion.java index f30f0332..f02a58a4 100644 --- a/questiongenerator/src/main/java/templates/PaintingQuestion.java +++ b/questiongenerator/src/main/java/templates/PaintingQuestion.java @@ -49,7 +49,7 @@ public void processResults() { JSONObject imageObject = result.getJSONObject("image"); String imageLink = imageObject.getString("value"); - if (needToSkip(paintingLabel)) + if (needToSkip(paintingLabel, imageLink)) continue; String answerText = ""; @@ -61,6 +61,7 @@ public void processResults() { Answer a = new Answer(answerText, AnswerCategory.PAINTING, langCode); answers.add(a); + imageLink = imageLink.replace("http://", "https://"); if (langCode.equals("es")) questions.add(new Question(a, "¿Cuál es este cuadro?" + QGHelper.LINKCONCAT + imageLink, QuestionCategory.ART, QuestionType.IMAGE)); else @@ -71,7 +72,7 @@ public void processResults() { repository.saveAll(new ArrayList<>(questions)); } - private boolean needToSkip(String paintingLabel) { + private boolean needToSkip(String paintingLabel, String imageLink) { if (paintingLabels.contains(paintingLabel)) { return true; } @@ -81,6 +82,10 @@ private boolean needToSkip(String paintingLabel) { return true; } + if (QGHelper.notAllowedExtension(imageLink)){ + return true; + } + return false; } } diff --git a/questiongenerator/src/main/java/templates/QGHelper.java b/questiongenerator/src/main/java/templates/QGHelper.java index 832ad6e6..cec474df 100644 --- a/questiongenerator/src/main/java/templates/QGHelper.java +++ b/questiongenerator/src/main/java/templates/QGHelper.java @@ -2,6 +2,7 @@ public class QGHelper { public final static String LINKCONCAT = "%& #"; + public final static String[] allowedExtensions = {"png", "jpg", "jpeg", "gif"}; public static boolean isEntityName(String label){ boolean isEntityName = true; // Check if it is like Q232334 @@ -17,4 +18,13 @@ public static boolean isEntityName(String label){ } return false; } + + public static boolean notAllowedExtension(String link){ + for (String s : allowedExtensions){ + if (link.endsWith(s)){ + return false; + } + } + return true; + } } diff --git a/questiongenerator/src/main/java/templates/StadiumQuestion.java b/questiongenerator/src/main/java/templates/StadiumQuestion.java index 4fd1a130..030eafbf 100644 --- a/questiongenerator/src/main/java/templates/StadiumQuestion.java +++ b/questiongenerator/src/main/java/templates/StadiumQuestion.java @@ -47,13 +47,14 @@ public void processResults() { JSONObject imageObject = result.getJSONObject("image"); String imageLink = imageObject.getString("value"); - if (needToSkip(stadiumLabel)) + if (needToSkip(stadiumLabel, imageLink)) continue; Answer a = new Answer(stadiumLabel, AnswerCategory.STADIUM, langCode); answers.add(a); + imageLink = imageLink.replace("http://", "https://"); if (langCode.equals("es")) questions.add(new Question(a, "¿Cuál es este estadio?" + QGHelper.LINKCONCAT + imageLink, QuestionCategory.SPORTS, QuestionType.IMAGE)); else @@ -64,22 +65,14 @@ public void processResults() { repository.saveAll(new ArrayList<>(questions)); } - private boolean needToSkip(String stadiumLabel) { + private boolean needToSkip(String stadiumLabel, String imageLink) { if (stadiumLabels.contains(stadiumLabel)) { return true; } stadiumLabels.add(stadiumLabel); - boolean isEntityName = true; // Check if it is like Q232334 - if (stadiumLabel.startsWith("Q") ){ - for (int i=1; i Date: Thu, 18 Apr 2024 23:33:38 +0200 Subject: [PATCH 04/22] Feat: Added video game genre questions --- questiongenerator/src/main/java/Main.java | 5 + .../src/main/java/model/AnswerCategory.java | 2 +- .../templates/VideogamesGenreQuestion.java | 95 +++++++++++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 questiongenerator/src/main/java/templates/VideogamesGenreQuestion.java diff --git a/questiongenerator/src/main/java/Main.java b/questiongenerator/src/main/java/Main.java index be0b3c22..128e2c06 100644 --- a/questiongenerator/src/main/java/Main.java +++ b/questiongenerator/src/main/java/Main.java @@ -25,6 +25,11 @@ public static void main(String[] args) { new VideogamesPublisherQuestion("es"); } + if (GeneralRepositoryStorer.doesntExist(AnswerCategory.GAMES_GENRE)) { + new VideogamesGenreQuestion("en"); + new VideogamesGenreQuestion("es"); + } + // IMAGES if(GeneralRepositoryStorer.doesntExist(AnswerCategory.STADIUM)) { diff --git a/questiongenerator/src/main/java/model/AnswerCategory.java b/questiongenerator/src/main/java/model/AnswerCategory.java index eaf2de22..926f9294 100644 --- a/questiongenerator/src/main/java/model/AnswerCategory.java +++ b/questiongenerator/src/main/java/model/AnswerCategory.java @@ -1,6 +1,6 @@ package model; public enum AnswerCategory { - CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON + CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_GENRE } diff --git a/questiongenerator/src/main/java/templates/VideogamesGenreQuestion.java b/questiongenerator/src/main/java/templates/VideogamesGenreQuestion.java new file mode 100644 index 00000000..7e75c013 --- /dev/null +++ b/questiongenerator/src/main/java/templates/VideogamesGenreQuestion.java @@ -0,0 +1,95 @@ +package templates; + +import model.*; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public class VideogamesGenreQuestion extends QuestionTemplate { + List videoGameLabels; + + private static final String[] spanishStringsIni = {"¿A qué género pertenece ", "¿Cuál es el género de ", "¿Qué tipo de género es ", "¿En qué género se clasifica "}; + private static final String[] englishStringsIni= {"What genre is ", "What is the genre of ", "What genre of game is ", "What genre categorizes "}; + + private static final String[] spanishStringsFin = {"?", "?", "?", "?"}; + private static final String[] englishStringsFin = {"?", "?", "?", "?"}; + + public VideogamesGenreQuestion(String langCode) { + super(langCode); + } + + @Override + public void setQuery() { + this.sparqlQuery = "SELECT ?gameLabel (MAX(?unitsSoldValue) as ?maxUnitsSold) (SAMPLE(?genreLabel) as ?genre) " + + "WHERE { " + + " ?game wdt:P31 wd:Q7889; " + + " wdt:P2664 ?unitsSoldValue. " + + " OPTIONAL { " + + " ?game wdt:P136 ?genreItem. " + + " ?genreItem rdfs:label ?genreLabel. " + + " FILTER(LANG(?genreLabel) IN (\"en\", \"es\")) " + + " } " + + " 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 questions = new ArrayList<>(); + List answers = new ArrayList<>(); + + for (int i = 0; i < results.length()-10; i++) { + + JSONObject result = results.getJSONObject(i); + + String videoGameLabel = ""; + String genreLabel = ""; + + try { + JSONObject videoGameLabelObject = result.getJSONObject("gameLabel"); + videoGameLabel = videoGameLabelObject.getString("value"); + + JSONObject genreLabelObject = result.getJSONObject("genre"); + genreLabel = genreLabelObject.getString("value"); + } catch (Exception e) { + continue; + } + + if (needToSkip(videoGameLabel, genreLabel)) + continue; + + Answer a = new Answer(genreLabel, AnswerCategory.GAMES_GENRE, langCode); + answers.add(a); + + String questionString = ""; + + if (langCode.equals("es")) + questionString = spanishStringsIni[i%4] + videoGameLabel + spanishStringsFin[i%4]; + else + questionString = englishStringsIni[i%4] + videoGameLabel + englishStringsFin[i%4]; + + questions.add(new Question(a, questionString, QuestionCategory.VIDEOGAMES, QuestionType.TEXT)); + } + } + + private boolean needToSkip(String videoGameLabel, String genreLabel) { + if (videoGameLabels.contains(videoGameLabel)) { + return true; + } + videoGameLabels.add(videoGameLabel); + + if (QGHelper.isEntityName(videoGameLabel)){ + return true; + } + if (QGHelper.isEntityName(genreLabel)){ + return true; + } + + return false; + } +} From a3bce9925bcc64504bce22d0e34744bd71c12d05 Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Thu, 18 Apr 2024 23:38:42 +0200 Subject: [PATCH 05/22] Feat: Added videogames country of origin questions --- questiongenerator/src/main/java/Main.java | 5 + .../src/main/java/model/AnswerCategory.java | 2 +- .../src/main/java/templates/QGHelper.java | 3 + .../templates/VideogamesCountryQuestion.java | 97 +++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 questiongenerator/src/main/java/templates/VideogamesCountryQuestion.java diff --git a/questiongenerator/src/main/java/Main.java b/questiongenerator/src/main/java/Main.java index 128e2c06..47f75001 100644 --- a/questiongenerator/src/main/java/Main.java +++ b/questiongenerator/src/main/java/Main.java @@ -30,6 +30,11 @@ public static void main(String[] args) { new VideogamesGenreQuestion("es"); } + if (GeneralRepositoryStorer.doesntExist(AnswerCategory.GAMES_COUNTRY)) { + new VideogamesCountryQuestion("en"); + new VideogamesCountryQuestion("es"); + } + // IMAGES if(GeneralRepositoryStorer.doesntExist(AnswerCategory.STADIUM)) { diff --git a/questiongenerator/src/main/java/model/AnswerCategory.java b/questiongenerator/src/main/java/model/AnswerCategory.java index 926f9294..22098476 100644 --- a/questiongenerator/src/main/java/model/AnswerCategory.java +++ b/questiongenerator/src/main/java/model/AnswerCategory.java @@ -1,6 +1,6 @@ package model; public enum AnswerCategory { - CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_GENRE + CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE } diff --git a/questiongenerator/src/main/java/templates/QGHelper.java b/questiongenerator/src/main/java/templates/QGHelper.java index cec474df..5f99cb5f 100644 --- a/questiongenerator/src/main/java/templates/QGHelper.java +++ b/questiongenerator/src/main/java/templates/QGHelper.java @@ -4,6 +4,9 @@ public class QGHelper { public final static String LINKCONCAT = "%& #"; public final static String[] allowedExtensions = {"png", "jpg", "jpeg", "gif"}; + private QGHelper() { + } + public static boolean isEntityName(String label){ boolean isEntityName = true; // Check if it is like Q232334 if (label.startsWith("Q") ){ diff --git a/questiongenerator/src/main/java/templates/VideogamesCountryQuestion.java b/questiongenerator/src/main/java/templates/VideogamesCountryQuestion.java new file mode 100644 index 00000000..e30786b0 --- /dev/null +++ b/questiongenerator/src/main/java/templates/VideogamesCountryQuestion.java @@ -0,0 +1,97 @@ +package templates; + +import model.*; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public class VideogamesCountryQuestion extends QuestionTemplate { + + private static final String[] spanishStringsIni = {"¿En que país se desarrolló ", "¿Dónde fue desarrollado ", "¿En qué país se creó ", "¿Dónde se creó "}; + private static final String[] englishStringsIni= {"In which country was ", "Where was ", "In what country was ", "Where was "}; + + private static final String[] spanishStringsFin = {"?", "?", "?", "?"}; + private static final String[] englishStringsFin = {" developed?", " developed?", " created?", " created?"}; + + List videoGameLabels; + + public VideogamesCountryQuestion(String langCode) { + super(langCode); + } + + @Override + public void setQuery() { + this.sparqlQuery = "SELECT ?gameLabel (MAX(?unitsSoldValue) as ?maxUnitsSold) (SAMPLE(?countryLabel) as ?country) " + + "WHERE { " + + " ?game wdt:P31 wd:Q7889; " + + " wdt:P2664 ?unitsSoldValue. " + + " OPTIONAL {\n" + + " ?game wdt:P495 ?countryItem. " + + " ?countryItem rdfs:label ?countryLabel. " + + " FILTER(LANG(?countryLabel) IN (\"en\", \"es\")) " + + " } " + + " 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 questions = new ArrayList<>(); + List answers = new ArrayList<>(); + + for (int i = 0; i < results.length()-10; i++) { + + JSONObject result = results.getJSONObject(i); + + String videoGameLabel = ""; + String countryLabel = ""; + + try { + JSONObject videoGameLabelObject = result.getJSONObject("gameLabel"); + videoGameLabel = videoGameLabelObject.getString("value"); + + JSONObject countryLabelObject = result.getJSONObject("country"); + countryLabel = countryLabelObject.getString("value"); + } catch (Exception e) { + continue; + } + + if (needToSkip(videoGameLabel, countryLabel)) + continue; + + Answer a = new Answer(countryLabel, AnswerCategory.GAMES_COUNTRY, langCode); + answers.add(a); + + String questionString = ""; + + if (langCode.equals("es")) + questionString = spanishStringsIni[i%4] + videoGameLabel + spanishStringsFin[i%4]; + else + questionString = englishStringsIni[i%4] + videoGameLabel + englishStringsFin[i%4]; + + questions.add(new Question(a, questionString, 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)) + return true; + if (QGHelper.isEntityName(countryLabel)) + return true; + + return false; + } +} From 14b6f607e6ad4b0f84a572078c92a169e0225beb Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Thu, 18 Apr 2024 23:38:58 +0200 Subject: [PATCH 06/22] Chore: Fixed bug not adding questions to DB --- .../src/main/java/templates/VideogamesGenreQuestion.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/questiongenerator/src/main/java/templates/VideogamesGenreQuestion.java b/questiongenerator/src/main/java/templates/VideogamesGenreQuestion.java index 7e75c013..fb5b144f 100644 --- a/questiongenerator/src/main/java/templates/VideogamesGenreQuestion.java +++ b/questiongenerator/src/main/java/templates/VideogamesGenreQuestion.java @@ -75,6 +75,9 @@ public void processResults() { questions.add(new Question(a, questionString, QuestionCategory.VIDEOGAMES, QuestionType.TEXT)); } + + repository.saveAll(new ArrayList<>(answers)); + repository.saveAll(new ArrayList<>(questions)); } private boolean needToSkip(String videoGameLabel, String genreLabel) { From fbe1274b2bfa3c47c7e7557575b2e83280771021 Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Thu, 18 Apr 2024 23:39:46 +0200 Subject: [PATCH 07/22] Chore: Reduced the number of lines --- .../VideogamesPublisherQuestion.java | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/questiongenerator/src/main/java/templates/VideogamesPublisherQuestion.java b/questiongenerator/src/main/java/templates/VideogamesPublisherQuestion.java index d5982caa..1ab55619 100644 --- a/questiongenerator/src/main/java/templates/VideogamesPublisherQuestion.java +++ b/questiongenerator/src/main/java/templates/VideogamesPublisherQuestion.java @@ -77,29 +77,11 @@ private boolean needToSkip(String videoGameLabel, String publisherLabel) { } videoGameLabels.add(videoGameLabel); - boolean isEntityName = isEntityName(videoGameLabel); - if (isEntityName){ + if (QGHelper.isEntityName(videoGameLabel)) return true; - } - isEntityName = isEntityName(publisherLabel); - if (isEntityName){ + if (QGHelper.isEntityName(publisherLabel)) return true; - } - return false; - } - private boolean isEntityName(String label){ - boolean isEntityName = true; // Check if it is like Q232334 - if (label.startsWith("Q") ){ - for (int i=1; i Date: Thu, 18 Apr 2024 23:50:36 +0200 Subject: [PATCH 08/22] Feat: Added Basketball venue questions --- questiongenerator/src/main/java/Main.java | 7 +- .../src/main/java/model/AnswerCategory.java | 2 +- .../templates/BasketballVenueQuestion.java | 77 +++++++++++++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 questiongenerator/src/main/java/templates/BasketballVenueQuestion.java diff --git a/questiongenerator/src/main/java/Main.java b/questiongenerator/src/main/java/Main.java index 47f75001..db39c386 100644 --- a/questiongenerator/src/main/java/Main.java +++ b/questiongenerator/src/main/java/Main.java @@ -35,6 +35,11 @@ public static void main(String[] args) { new VideogamesCountryQuestion("es"); } + if (GeneralRepositoryStorer.doesntExist(AnswerCategory.BASKETBALL_VENUE)) { + new BasketballVenueQuestion("en"); + new BasketballVenueQuestion("es"); + } + // IMAGES if(GeneralRepositoryStorer.doesntExist(AnswerCategory.STADIUM)) { @@ -54,7 +59,7 @@ public static void main(String[] args) { /* - // VIDEOS + // VIDEOS not yet supported if(GeneralRepositoryStorer.doesntExist(AnswerCategory.SONG.toString())) { new SongQuestion("en"); new SongQuestion("es"); diff --git a/questiongenerator/src/main/java/model/AnswerCategory.java b/questiongenerator/src/main/java/model/AnswerCategory.java index 22098476..7de719bb 100644 --- a/questiongenerator/src/main/java/model/AnswerCategory.java +++ b/questiongenerator/src/main/java/model/AnswerCategory.java @@ -1,6 +1,6 @@ package model; public enum AnswerCategory { - CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE + CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE, BASKETBALL_VENUE } diff --git a/questiongenerator/src/main/java/templates/BasketballVenueQuestion.java b/questiongenerator/src/main/java/templates/BasketballVenueQuestion.java new file mode 100644 index 00000000..f12d27cd --- /dev/null +++ b/questiongenerator/src/main/java/templates/BasketballVenueQuestion.java @@ -0,0 +1,77 @@ +package templates; + +import model.*; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public class BasketballVenueQuestion extends QuestionTemplate { + + private List teamLabels; + + private static final String[] spanishStringsIni = {"¿Cómo se llama el estadio de ", "¿Dónde juega el equipo ", "¿Cuál es el estadio del equipo ", "¿Dónde se juegan los partidos del equipo "}; + private static final String[] englishStringsIni= {"What is the venue of ", "What is the stadium of ", "Which name receives the venue of ", "Where does "}; + + private static final String[] spanishStringsFin = {"?", "?", "?", "?"}; + private static final String[] englishStringsFin = {"?", "?", "?", " play?"}; + + public BasketballVenueQuestion(String langCode) { + super(langCode); + } + + @Override + public void setQuery() { + this.sparqlQuery = "SELECT ?teamLabel ?venueLabel " + + "WHERE { " + + " ?team wdt:P31 wd:Q13393265; " + + " wdt:P118 ?league; " + + " wdt:P115 ?venue. " + + " VALUES ?league {wd:Q1126104 wd:Q155223} " + + " SERVICE wikibase:label { bd:serviceParam wikibase:language \"" + langCode + "\". } " + + "} "; + } + + @Override + public void processResults() { + teamLabels = new ArrayList<>(); + List questions = new ArrayList<>(); + List answers = new ArrayList<>(); + + for (int i = 0; i < results.length(); i++) { + JSONObject result = results.getJSONObject(i); + String teamLabel = result.getJSONObject("teamLabel").getString("value"); + String venueLabel = result.getJSONObject("venueLabel").getString("value"); + + if (needToSkip(teamLabel, venueLabel)) { + continue; + } + + Answer a = new Answer(venueLabel, AnswerCategory.BASKETBALL_VENUE, langCode); + answers.add(a); + + String questionString = ""; + + if (langCode.equals("es")) + questionString = spanishStringsIni[i%4] + teamLabel + spanishStringsFin[i%4]; + else + questionString = englishStringsIni[i%4] + teamLabel + englishStringsFin[i%4]; + + questions.add(new Question(a, questionString, QuestionCategory.SPORTS, QuestionType.TEXT)); + } + repository.saveAll(new ArrayList<>(answers)); + repository.saveAll(new ArrayList<>(questions)); + } + + private boolean needToSkip(String teamLabel, String venueLabel){ + if (teamLabels.contains(teamLabel)) { + return true; + } + teamLabels.add(teamLabel); + + if (QGHelper.isEntityName(teamLabel) || QGHelper.isEntityName(venueLabel)) + return true; + + return false; + } +} From 4fd786b9f5506e2d605f4a54287a688c4c22eced Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Thu, 18 Apr 2024 23:52:01 +0200 Subject: [PATCH 09/22] Chore: Code quality changes --- .../src/main/java/templates/VideogamesCountryQuestion.java | 5 ++--- .../src/main/java/templates/VideogamesGenreQuestion.java | 7 ++----- .../main/java/templates/VideogamesPublisherQuestion.java | 4 +--- .../src/main/java/templates/WhosThatPokemonQuestion.java | 4 ++++ 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/questiongenerator/src/main/java/templates/VideogamesCountryQuestion.java b/questiongenerator/src/main/java/templates/VideogamesCountryQuestion.java index e30786b0..0e53b7df 100644 --- a/questiongenerator/src/main/java/templates/VideogamesCountryQuestion.java +++ b/questiongenerator/src/main/java/templates/VideogamesCountryQuestion.java @@ -87,11 +87,10 @@ private boolean needToSkip(String videoGameLabel, String countryLabel) { } videoGameLabels.add(videoGameLabel); - if (QGHelper.isEntityName(videoGameLabel)) - return true; - if (QGHelper.isEntityName(countryLabel)) + if (QGHelper.isEntityName(videoGameLabel) || QGHelper.isEntityName(countryLabel)) return true; + return false; } } diff --git a/questiongenerator/src/main/java/templates/VideogamesGenreQuestion.java b/questiongenerator/src/main/java/templates/VideogamesGenreQuestion.java index fb5b144f..37c63781 100644 --- a/questiongenerator/src/main/java/templates/VideogamesGenreQuestion.java +++ b/questiongenerator/src/main/java/templates/VideogamesGenreQuestion.java @@ -86,12 +86,9 @@ private boolean needToSkip(String videoGameLabel, String genreLabel) { } videoGameLabels.add(videoGameLabel); - if (QGHelper.isEntityName(videoGameLabel)){ + if (QGHelper.isEntityName(videoGameLabel) || QGHelper.isEntityName(genreLabel)) return true; - } - if (QGHelper.isEntityName(genreLabel)){ - return true; - } + return false; } diff --git a/questiongenerator/src/main/java/templates/VideogamesPublisherQuestion.java b/questiongenerator/src/main/java/templates/VideogamesPublisherQuestion.java index 1ab55619..54026088 100644 --- a/questiongenerator/src/main/java/templates/VideogamesPublisherQuestion.java +++ b/questiongenerator/src/main/java/templates/VideogamesPublisherQuestion.java @@ -77,9 +77,7 @@ private boolean needToSkip(String videoGameLabel, String publisherLabel) { } videoGameLabels.add(videoGameLabel); - if (QGHelper.isEntityName(videoGameLabel)) - return true; - if (QGHelper.isEntityName(publisherLabel)) + if (QGHelper.isEntityName(videoGameLabel) || QGHelper.isEntityName(publisherLabel)) return true; return false; diff --git a/questiongenerator/src/main/java/templates/WhosThatPokemonQuestion.java b/questiongenerator/src/main/java/templates/WhosThatPokemonQuestion.java index 487af369..037bf9d4 100644 --- a/questiongenerator/src/main/java/templates/WhosThatPokemonQuestion.java +++ b/questiongenerator/src/main/java/templates/WhosThatPokemonQuestion.java @@ -78,6 +78,10 @@ private boolean needToSkip(String pokemonLabel, String pokemonIndex){ return true; } + if (QGHelper.isEntityName(pokemonLabel) || QGHelper.isEntityName(pokemonIndex)) + return true; + + return false; } } From 7a1a7565789896aa29be70b69c71a4761fcdd54b Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Thu, 18 Apr 2024 23:52:44 +0200 Subject: [PATCH 10/22] Chore: Added the categories to the API --- .../java/lab/en2b/quizapi/questions/answer/AnswerCategory.java | 2 +- .../lab/en2b/quizapi/questions/question/QuestionCategory.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/lab/en2b/quizapi/questions/answer/AnswerCategory.java b/api/src/main/java/lab/en2b/quizapi/questions/answer/AnswerCategory.java index 9e8154dc..cc8239b0 100644 --- a/api/src/main/java/lab/en2b/quizapi/questions/answer/AnswerCategory.java +++ b/api/src/main/java/lab/en2b/quizapi/questions/answer/AnswerCategory.java @@ -1,6 +1,6 @@ package lab.en2b.quizapi.questions.answer; public enum AnswerCategory { - CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING + CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE, BASKETBALL_VENUE } diff --git a/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionCategory.java b/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionCategory.java index d97db494..dfe7ccae 100644 --- a/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionCategory.java +++ b/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionCategory.java @@ -2,5 +2,5 @@ public enum QuestionCategory { //HISTORY, GEOGRAPHY, SCIENCE, MATH, LITERATURE, ART, SPORTS, MUSIC, MOVIES, TV, POLITICS, OTHER - GEOGRAPHY, SPORTS, MUSIC, ART, VIDEOGAMES + GEOGRAPHY, SPORTS, MUSIC, ART, VIDEOGAMES, POKEMON } From 732ae8469cc9f78648a052a499d98fc9d1154699 Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Fri, 19 Apr 2024 00:13:59 +0200 Subject: [PATCH 11/22] Feat: Added more diversity to the question templates --- .../main/java/templates/BallonDOrQuestion.java | 12 ++++++++++-- .../java/templates/CountryCapitalQuestion.java | 16 +++++++++++++--- .../main/java/templates/PaintingQuestion.java | 7 +++++-- .../src/main/java/templates/SongQuestion.java | 7 +++++-- .../src/main/java/templates/StadiumQuestion.java | 7 +++++-- .../templates/VideogamesPublisherQuestion.java | 15 +++++++++++++-- 6 files changed, 51 insertions(+), 13 deletions(-) diff --git a/questiongenerator/src/main/java/templates/BallonDOrQuestion.java b/questiongenerator/src/main/java/templates/BallonDOrQuestion.java index d040b785..35ccfb46 100644 --- a/questiongenerator/src/main/java/templates/BallonDOrQuestion.java +++ b/questiongenerator/src/main/java/templates/BallonDOrQuestion.java @@ -8,6 +8,12 @@ public class BallonDOrQuestion extends QuestionTemplate { + private static final String[] spanishStringsIni = {"¿Quién ganó el Balón de Oro en ", "¿Quién fue el ganador del Balón de Oro en ", "¿Quién obtuvo el Balón de Oro en ", "¿Quién se llevó el Balón de Oro en "}; + private static final String[] englishStringsIni= {"Who won the Ballon d'Or in ", "Who was the winner of the Ballon d'Or in ", "Who got the Ballon d'Or in ", "Who was given the Ballon d'Or in "}; + + private static final String[] spanishStringsFin = {"?", "?", "?", "?"}; + private static final String[] englishStringsFin = {"?", "?", "?", "?"}; + /** * It is not necessary to specify the language code for this question * @param langCode IGNORED, spanish and english languages are generated at the same time @@ -41,17 +47,19 @@ protected void processResults() { if (needToSkip(playerLabel, year)) continue; + // EXCEPTION FOR THIS TYPE OF QUESTION // English Answer a = new Answer(playerLabel, AnswerCategory.BALLON_DOR, "en"); answers.add(a); - questions.add(new Question(a, "Who won the Ballon d'Or in " + year + "?", QuestionCategory.SPORTS, QuestionType.TEXT)); + + questions.add(new Question(a, englishStringsIni[i%4] + year + englishStringsFin[i%4], QuestionCategory.SPORTS, QuestionType.TEXT)); // Spanish a = new Answer(playerLabel, AnswerCategory.BALLON_DOR, "es"); answers.add(a); - questions.add(new Question(a, "¿Quién ganó el Balón de Oro en " + year + "?", QuestionCategory.SPORTS, QuestionType.TEXT)); + questions.add(new Question(a, spanishStringsIni[i%4] + year + spanishStringsFin[i%4], QuestionCategory.SPORTS, QuestionType.TEXT)); } repository.saveAll(new ArrayList<>(answers)); diff --git a/questiongenerator/src/main/java/templates/CountryCapitalQuestion.java b/questiongenerator/src/main/java/templates/CountryCapitalQuestion.java index 6d965a1f..c9335f13 100644 --- a/questiongenerator/src/main/java/templates/CountryCapitalQuestion.java +++ b/questiongenerator/src/main/java/templates/CountryCapitalQuestion.java @@ -6,7 +6,6 @@ import model.AnswerCategory; import model.Question; import org.json.JSONObject; -import repositories.Storable; import java.util.ArrayList; import java.util.List; @@ -16,6 +15,12 @@ */ public class CountryCapitalQuestion extends QuestionTemplate { + private static final String[] spanishStringsIni = {"¿Cuál es la capital de ", "¿Dónde se encuentra la capital de ", "¿Qué ciudad es la capital de ", "¿Cuál es la ciudad capital de "}; + private static final String[] englishStringsIni= {"What is the capital of ", "Where is the capital of ", "Which city is the capital of ", "What is the capital city of "}; + + private static final String[] spanishStringsFin = {"?", "?", "?", "?"}; + private static final String[] englishStringsFin = {"?", "?", "?", "?"}; + /** * Only need to invoke the constructor, and it will automatically do the HTTP request and the response recovery. * @param langCode representation for the language to be used for the question. ("en" for English, "es" for Spanish) @@ -57,11 +62,16 @@ protected void processResults() { Answer a = new Answer(capitalLabel, AnswerCategory.CAPITAL_CITY, langCode); answers.add(a); + String questionString = ""; + + //Saving the question if (langCode.equals("es")) - questions.add(new Question(a, "¿Cuál es la capital de " + countryLabel + "?", QuestionCategory.GEOGRAPHY, QuestionType.TEXT)); + questionString = spanishStringsIni[i%4] + countryLabel + spanishStringsFin[i%4]; else - questions.add(new Question(a, "What is the capital of " + countryLabel + "?", QuestionCategory.GEOGRAPHY, QuestionType.TEXT)); + questionString = englishStringsIni[i%4] + countryLabel + englishStringsFin[i%4]; + + questions.add(new Question(a, questionString, QuestionCategory.GEOGRAPHY, QuestionType.TEXT)); } repository.saveAll(new ArrayList<>(answers)); diff --git a/questiongenerator/src/main/java/templates/PaintingQuestion.java b/questiongenerator/src/main/java/templates/PaintingQuestion.java index f02a58a4..71ea8ecd 100644 --- a/questiongenerator/src/main/java/templates/PaintingQuestion.java +++ b/questiongenerator/src/main/java/templates/PaintingQuestion.java @@ -8,6 +8,9 @@ public class PaintingQuestion extends QuestionTemplate { + private static final String[] spanishStringsIni = {"¿Cómo se llama este cuadro?", "¿Cuál es este cuadro?", "¿Qué pintura es esta?", "¿Cuál es el nombre de este cuadro?"}; + private static final String[] englishStringsIni= {"What is the name of this painting?", "Which painting is this?", "What painting is this?", "How's this painting called?"}; + List paintingLabels; public PaintingQuestion(String langCode) { @@ -63,9 +66,9 @@ public void processResults() { imageLink = imageLink.replace("http://", "https://"); if (langCode.equals("es")) - questions.add(new Question(a, "¿Cuál es este cuadro?" + QGHelper.LINKCONCAT + imageLink, QuestionCategory.ART, QuestionType.IMAGE)); + questions.add(new Question(a, spanishStringsIni[i%4] + QGHelper.LINKCONCAT + imageLink, QuestionCategory.ART, QuestionType.IMAGE)); else - questions.add(new Question(a, "Which painting is this?" + QGHelper.LINKCONCAT + imageLink, QuestionCategory.ART, QuestionType.IMAGE)); + questions.add(new Question(a, englishStringsIni[i%4] + QGHelper.LINKCONCAT + imageLink, QuestionCategory.ART, QuestionType.IMAGE)); } repository.saveAll(new ArrayList<>(answers)); diff --git a/questiongenerator/src/main/java/templates/SongQuestion.java b/questiongenerator/src/main/java/templates/SongQuestion.java index 6be82263..7ebb5d2c 100644 --- a/questiongenerator/src/main/java/templates/SongQuestion.java +++ b/questiongenerator/src/main/java/templates/SongQuestion.java @@ -8,6 +8,9 @@ public class SongQuestion extends QuestionTemplate { + private static final String[] spanishStringsIni = {"¿Cómo se llama esta canción?", "¿Cuál es esta canción?", "¿Qué canción es esta?", "¿Cómo se llama esta canción?"}; + private static final String[] englishStringsIni= {"What is the name of this song?", "Which song is this?", "What song is this?", "What is the name of this song?"}; + List songLabels; public SongQuestion(String langCode) { @@ -59,9 +62,9 @@ public void processResults() { answers.add(a); if (langCode.equals("es")) - questions.add(new Question(a, "¿Cuál es esta canción? " + musicVideoLink, QuestionCategory.MUSIC, QuestionType.AUDIO)); + questions.add(new Question(a, spanishStringsIni[i%4] + QGHelper.LINKCONCAT + musicVideoLink, QuestionCategory.MUSIC, QuestionType.AUDIO)); else - questions.add(new Question(a, "Which song is this? " + musicVideoLink, QuestionCategory.MUSIC, QuestionType.AUDIO)); + questions.add(new Question(a, englishStringsIni[i%4] + QGHelper.LINKCONCAT + musicVideoLink, QuestionCategory.MUSIC, QuestionType.AUDIO)); } repository.saveAll(new ArrayList<>(answers)); diff --git a/questiongenerator/src/main/java/templates/StadiumQuestion.java b/questiongenerator/src/main/java/templates/StadiumQuestion.java index 030eafbf..200ff959 100644 --- a/questiongenerator/src/main/java/templates/StadiumQuestion.java +++ b/questiongenerator/src/main/java/templates/StadiumQuestion.java @@ -8,6 +8,9 @@ public class StadiumQuestion extends QuestionTemplate { + private static final String[] spanishStringsIni = {"¿Cómo se llama este estadio?", "¿Cuál es el nombre de este estadio?", "¿Cuál es este estadio?", "¿Con qué nombre se conoce a este estadio?"}; + private static final String[] englishStringsIni= {"What is the name of this stadium?", "How's this stadium called", "Which stadium is this?", "How do they call this stadium?"}; + List stadiumLabels; public StadiumQuestion(String langCode) { @@ -56,9 +59,9 @@ public void processResults() { imageLink = imageLink.replace("http://", "https://"); if (langCode.equals("es")) - questions.add(new Question(a, "¿Cuál es este estadio?" + QGHelper.LINKCONCAT + imageLink, QuestionCategory.SPORTS, QuestionType.IMAGE)); + questions.add(new Question(a, spanishStringsIni[i%4] + QGHelper.LINKCONCAT + imageLink, QuestionCategory.SPORTS, QuestionType.IMAGE)); else - questions.add(new Question(a, "Which stadium is this?" + QGHelper.LINKCONCAT + imageLink, QuestionCategory.SPORTS, QuestionType.IMAGE)); + questions.add(new Question(a, englishStringsIni[i%4] + QGHelper.LINKCONCAT + imageLink, QuestionCategory.SPORTS, QuestionType.IMAGE)); } repository.saveAll(new ArrayList<>(answers)); diff --git a/questiongenerator/src/main/java/templates/VideogamesPublisherQuestion.java b/questiongenerator/src/main/java/templates/VideogamesPublisherQuestion.java index 54026088..7ea483b9 100644 --- a/questiongenerator/src/main/java/templates/VideogamesPublisherQuestion.java +++ b/questiongenerator/src/main/java/templates/VideogamesPublisherQuestion.java @@ -9,6 +9,12 @@ public class VideogamesPublisherQuestion extends QuestionTemplate { List videoGameLabels; + private static final String[] spanishStringsIni = {"¿Que compañía publicó ", "¿Quién publicó ", "¿Qué empresa publicó ", "¿Quién fue el publicador de "}; + private static final String[] englishStringsIni= {"Who published ", "What company published ", "Who was the publisher of ", "Which company published "}; + + private static final String[] spanishStringsFin = {"?", "?", "?", "?"}; + private static final String[] englishStringsFin = {"?", "?", "?", "?"}; + public VideogamesPublisherQuestion(String langCode) { super(langCode); } @@ -61,10 +67,15 @@ public void processResults() { Answer a = new Answer(publisherLabel, AnswerCategory.GAMES_PUBLISHER, langCode); answers.add(a); + + String questionString = ""; + if (langCode.equals("es")) - questions.add(new Question(a, "¿Qué compañía publicó " + videoGameLabel + "?", QuestionCategory.VIDEOGAMES, QuestionType.TEXT)); + questionString = spanishStringsIni[i%4] + videoGameLabel + spanishStringsFin[i%4]; else - questions.add(new Question(a, "Who published " + videoGameLabel + "?", QuestionCategory.VIDEOGAMES, QuestionType.TEXT)); + questionString = englishStringsIni[i%4] + videoGameLabel + englishStringsFin[i%4]; + + questions.add(new Question(a, questionString, QuestionCategory.VIDEOGAMES, QuestionType.TEXT)); } repository.saveAll(new ArrayList<>(answers)); From 1662c580ae83f281ec6fe1d62791967aff383a11 Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Fri, 19 Apr 2024 00:50:01 +0200 Subject: [PATCH 12/22] Feat: All questions now have different wordings :) --- questiongenerator/src/main/java/Main.java | 6 ++--- .../repositories/GeneralRepositoryStorer.java | 24 +++++++++++++++++++ .../main/java/templates/StadiumQuestion.java | 4 ++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/questiongenerator/src/main/java/Main.java b/questiongenerator/src/main/java/Main.java index db39c386..04eac083 100644 --- a/questiongenerator/src/main/java/Main.java +++ b/questiongenerator/src/main/java/Main.java @@ -4,10 +4,11 @@ public class Main { - - public static void main(String[] args) { + // Deletes all questions and answers from the DB + GeneralRepositoryStorer.clearAllQA(); + //Edit constraints of the DB GeneralRepositoryStorer.editConstraints(); // TEXT @@ -57,7 +58,6 @@ public static void main(String[] args) { new WhosThatPokemonQuestion("es"); } - /* // VIDEOS not yet supported if(GeneralRepositoryStorer.doesntExist(AnswerCategory.SONG.toString())) { diff --git a/questiongenerator/src/main/java/repositories/GeneralRepositoryStorer.java b/questiongenerator/src/main/java/repositories/GeneralRepositoryStorer.java index 88490702..dc47d79d 100644 --- a/questiongenerator/src/main/java/repositories/GeneralRepositoryStorer.java +++ b/questiongenerator/src/main/java/repositories/GeneralRepositoryStorer.java @@ -14,6 +14,30 @@ */ public class GeneralRepositoryStorer { + /** + * Removes all questions and answers from the DB using SQL queries on cascade. + */ + public static void clearAllQA() { + try{ + EntityManagerFactory emf = Jpa.getEntityManagerFactory(); + EntityManager entityManager = emf.createEntityManager(); + + entityManager.getTransaction().begin(); + + entityManager.createNativeQuery("DELETE FROM games_questions").executeUpdate(); + entityManager.createNativeQuery("DELETE FROM questions_answers").executeUpdate(); + entityManager.createNativeQuery("DELETE FROM questions").executeUpdate(); + entityManager.createNativeQuery("DELETE FROM answers").executeUpdate(); + + entityManager.getTransaction().commit(); + + entityManager.close(); + Jpa.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + public void saveAll(List storableList) { EntityManagerFactory emf = Jpa.getEntityManagerFactory(); EntityManager entityManager = emf.createEntityManager(); diff --git a/questiongenerator/src/main/java/templates/StadiumQuestion.java b/questiongenerator/src/main/java/templates/StadiumQuestion.java index 200ff959..ba86078a 100644 --- a/questiongenerator/src/main/java/templates/StadiumQuestion.java +++ b/questiongenerator/src/main/java/templates/StadiumQuestion.java @@ -35,6 +35,10 @@ protected void setQuery() { @Override public void processResults() { + + System.out.println("Processing Stadiums"); + System.out.println(results.toString()); + stadiumLabels = new ArrayList<>(); List questions = new ArrayList<>(); List answers = new ArrayList<>(); From ef2fde669fbc2cd6367d423bcff9b4e32d037b54 Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Fri, 19 Apr 2024 15:15:20 +0200 Subject: [PATCH 13/22] Chore: No pokemon question cat --- .../lab/en2b/quizapi/questions/question/QuestionCategory.java | 2 +- questiongenerator/src/main/java/model/QuestionCategory.java | 2 +- .../src/main/java/templates/WhosThatPokemonQuestion.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionCategory.java b/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionCategory.java index dfe7ccae..d97db494 100644 --- a/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionCategory.java +++ b/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionCategory.java @@ -2,5 +2,5 @@ public enum QuestionCategory { //HISTORY, GEOGRAPHY, SCIENCE, MATH, LITERATURE, ART, SPORTS, MUSIC, MOVIES, TV, POLITICS, OTHER - GEOGRAPHY, SPORTS, MUSIC, ART, VIDEOGAMES, POKEMON + GEOGRAPHY, SPORTS, MUSIC, ART, VIDEOGAMES } diff --git a/questiongenerator/src/main/java/model/QuestionCategory.java b/questiongenerator/src/main/java/model/QuestionCategory.java index a536abfb..d39d26dc 100644 --- a/questiongenerator/src/main/java/model/QuestionCategory.java +++ b/questiongenerator/src/main/java/model/QuestionCategory.java @@ -2,5 +2,5 @@ public enum QuestionCategory { //HISTORY, GEOGRAPHY, SCIENCE, MATH, LITERATURE, ART, SPORTS, MUSIC, MOVIES, TV, POLITICS, OTHER - GEOGRAPHY, SPORTS, MUSIC, ART, VIDEOGAMES, POKEMON + GEOGRAPHY, SPORTS, MUSIC, ART, VIDEOGAMES } diff --git a/questiongenerator/src/main/java/templates/WhosThatPokemonQuestion.java b/questiongenerator/src/main/java/templates/WhosThatPokemonQuestion.java index 037bf9d4..cfd499e8 100644 --- a/questiongenerator/src/main/java/templates/WhosThatPokemonQuestion.java +++ b/questiongenerator/src/main/java/templates/WhosThatPokemonQuestion.java @@ -53,11 +53,11 @@ public void processResults() { if (langCode.equals("es")){ spanishString = spanishStrings[i%4] + QGHelper.LINKCONCAT + "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/" + pokedexNum + ".png"; - questions.add(new Question(a, spanishString, QuestionCategory.POKEMON, QuestionType.TEXT)); + questions.add(new Question(a, spanishString, QuestionCategory.VIDEOGAMES, QuestionType.TEXT)); } else{ englishString = englishStrings[i%4] + QGHelper.LINKCONCAT + "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/" + pokedexNum + ".png"; - questions.add(new Question(a, englishString, QuestionCategory.POKEMON, QuestionType.TEXT)); + questions.add(new Question(a, englishString, QuestionCategory.VIDEOGAMES, QuestionType.TEXT)); } } From 45517e1436a27e6dfe765de0a83aa37e6709667a Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Fri, 19 Apr 2024 15:26:27 +0200 Subject: [PATCH 14/22] Feat: Do not delete the Questions and Answers from DB --- questiongenerator/src/main/java/Main.java | 3 --- .../repositories/GeneralRepositoryStorer.java | 24 ------------------- 2 files changed, 27 deletions(-) diff --git a/questiongenerator/src/main/java/Main.java b/questiongenerator/src/main/java/Main.java index 04eac083..e9f76e02 100644 --- a/questiongenerator/src/main/java/Main.java +++ b/questiongenerator/src/main/java/Main.java @@ -5,9 +5,6 @@ public class Main { public static void main(String[] args) { - // Deletes all questions and answers from the DB - GeneralRepositoryStorer.clearAllQA(); - //Edit constraints of the DB GeneralRepositoryStorer.editConstraints(); diff --git a/questiongenerator/src/main/java/repositories/GeneralRepositoryStorer.java b/questiongenerator/src/main/java/repositories/GeneralRepositoryStorer.java index dc47d79d..88490702 100644 --- a/questiongenerator/src/main/java/repositories/GeneralRepositoryStorer.java +++ b/questiongenerator/src/main/java/repositories/GeneralRepositoryStorer.java @@ -14,30 +14,6 @@ */ public class GeneralRepositoryStorer { - /** - * Removes all questions and answers from the DB using SQL queries on cascade. - */ - public static void clearAllQA() { - try{ - EntityManagerFactory emf = Jpa.getEntityManagerFactory(); - EntityManager entityManager = emf.createEntityManager(); - - entityManager.getTransaction().begin(); - - entityManager.createNativeQuery("DELETE FROM games_questions").executeUpdate(); - entityManager.createNativeQuery("DELETE FROM questions_answers").executeUpdate(); - entityManager.createNativeQuery("DELETE FROM questions").executeUpdate(); - entityManager.createNativeQuery("DELETE FROM answers").executeUpdate(); - - entityManager.getTransaction().commit(); - - entityManager.close(); - Jpa.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - public void saveAll(List storableList) { EntityManagerFactory emf = Jpa.getEntityManagerFactory(); EntityManager entityManager = emf.createEntityManager(); From cd0fa27acef7830cc72bcc7240d6d97f3cb35650 Mon Sep 17 00:00:00 2001 From: Gonzalo Alonso Fernandez Date: Sat, 20 Apr 2024 10:57:38 +0200 Subject: [PATCH 15/22] fix: fixed an error checking if the game is active. --- webapp/src/pages/Dashboard.jsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/webapp/src/pages/Dashboard.jsx b/webapp/src/pages/Dashboard.jsx index aa7daaf4..3bb86210 100644 --- a/webapp/src/pages/Dashboard.jsx +++ b/webapp/src/pages/Dashboard.jsx @@ -60,8 +60,8 @@ export default function Dashboard() { useEffect(() => { async function checkActiveStatus() { - const active = await isActive(); - setActive(active); + const i = await isActive(); + setActive(i.data.is_active); } checkActiveStatus(); }, []); @@ -126,7 +126,7 @@ export default function Dashboard() { - {active && ( + {!active && ( {modes.map(mode => ( - )} - {!active && ( + ) : (