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/questiongenerator/src/main/java/Main.java b/questiongenerator/src/main/java/Main.java index 6d0a7b54..e9f76e02 100644 --- a/questiongenerator/src/main/java/Main.java +++ b/questiongenerator/src/main/java/Main.java @@ -4,10 +4,8 @@ public class Main { - - public static void main(String[] args) { - + //Edit constraints of the DB GeneralRepositoryStorer.editConstraints(); // TEXT @@ -25,6 +23,21 @@ public static void main(String[] args) { new VideogamesPublisherQuestion("es"); } + if (GeneralRepositoryStorer.doesntExist(AnswerCategory.GAMES_GENRE)) { + new VideogamesGenreQuestion("en"); + new VideogamesGenreQuestion("es"); + } + + if (GeneralRepositoryStorer.doesntExist(AnswerCategory.GAMES_COUNTRY)) { + new VideogamesCountryQuestion("en"); + new VideogamesCountryQuestion("es"); + } + + if (GeneralRepositoryStorer.doesntExist(AnswerCategory.BASKETBALL_VENUE)) { + new BasketballVenueQuestion("en"); + new BasketballVenueQuestion("es"); + } + // IMAGES if(GeneralRepositoryStorer.doesntExist(AnswerCategory.STADIUM)) { @@ -37,9 +50,13 @@ public static void main(String[] args) { new PaintingQuestion("es"); } + if (GeneralRepositoryStorer.doesntExist(AnswerCategory.WTPOKEMON)) { + new WhosThatPokemonQuestion("en"); + new WhosThatPokemonQuestion("es"); + } /* - // 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 9af4f704..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 + CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE, BASKETBALL_VENUE } 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/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/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; + } +} 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 eafac578..71ea8ecd 100644 --- a/questiongenerator/src/main/java/templates/PaintingQuestion.java +++ b/questiongenerator/src/main/java/templates/PaintingQuestion.java @@ -2,13 +2,15 @@ import model.*; import org.json.JSONObject; -import repositories.GeneralRepositoryStorer; import java.util.ArrayList; import java.util.List; 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) { @@ -50,7 +52,7 @@ public void processResults() { JSONObject imageObject = result.getJSONObject("image"); String imageLink = imageObject.getString("value"); - if (needToSkip(paintingLabel)) + if (needToSkip(paintingLabel, imageLink)) continue; String answerText = ""; @@ -62,32 +64,29 @@ 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?" + GeneralRepositoryStorer.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?" + GeneralRepositoryStorer.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)); repository.saveAll(new ArrayList<>(questions)); } - private boolean needToSkip(String paintingLabel) { + private boolean needToSkip(String paintingLabel, String imageLink) { if (paintingLabels.contains(paintingLabel)) { return true; } paintingLabels.add(paintingLabel); - boolean isEntityName = true; // Check if it is like Q232334 - if (paintingLabel.startsWith("Q") ){ - for (int i=1; i 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)); @@ -74,6 +77,10 @@ private boolean needToSkip(String songLabel) { } songLabels.add(songLabel); + if (QGHelper.isEntityName(songLabel)){ + return true; + } + return false; } } diff --git a/questiongenerator/src/main/java/templates/StadiumQuestion.java b/questiongenerator/src/main/java/templates/StadiumQuestion.java index 2d473e4c..bcef0d33 100644 --- a/questiongenerator/src/main/java/templates/StadiumQuestion.java +++ b/questiongenerator/src/main/java/templates/StadiumQuestion.java @@ -2,13 +2,15 @@ import model.*; import org.json.JSONObject; -import repositories.GeneralRepositoryStorer; import java.util.ArrayList; import java.util.List; 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) { @@ -33,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<>(); @@ -48,39 +54,35 @@ 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?" + GeneralRepositoryStorer.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?" + GeneralRepositoryStorer.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)); 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 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 (\"" + langCode + "\")) " + + " } " + + " 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) || 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 new file mode 100644 index 00000000..50c489e8 --- /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(); 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)); + } + + repository.saveAll(new ArrayList<>(answers)); + repository.saveAll(new ArrayList<>(questions)); + } + + private boolean needToSkip(String videoGameLabel, String genreLabel) { + if (videoGameLabels.contains(videoGameLabel)) { + return true; + } + videoGameLabels.add(videoGameLabel); + + if (QGHelper.isEntityName(videoGameLabel) || 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 d5982caa..2946bbce 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); } @@ -38,7 +44,7 @@ public void processResults() { List questions = new ArrayList<>(); List answers = new ArrayList<>(); - for (int i = 0; i < results.length()-10; i++) { + for (int i = 0; i < results.length(); i++) { JSONObject result = results.getJSONObject(i); @@ -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)); @@ -77,29 +88,9 @@ private boolean needToSkip(String videoGameLabel, String publisherLabel) { } videoGameLabels.add(videoGameLabel); - boolean isEntityName = isEntityName(videoGameLabel); - if (isEntityName){ - return true; - } - isEntityName = isEntityName(publisherLabel); - if (isEntityName){ + if (QGHelper.isEntityName(videoGameLabel) || 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 pokemonLabels; + + 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] + QGHelper.LINKCONCAT + "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/" + pokedexNum + ".png"; + questions.add(new Question(a, spanishString, QuestionCategory.VIDEOGAMES, QuestionType.IMAGE)); + } + 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.VIDEOGAMES, QuestionType.IMAGE)); + } + } + + 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; + } + + if (QGHelper.isEntityName(pokemonLabel) || QGHelper.isEntityName(pokemonIndex)) + return true; + + + return false; + } +}