generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from Arquisoft/develop
merging for deploy
- Loading branch information
Showing
33 changed files
with
843 additions
and
280 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
api/src/main/java/lab/en2b/quizapi/questions/answer/AnswerCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package lab.en2b.quizapi.questions.answer; | ||
|
||
public enum AnswerCategory { | ||
OTHER, CAPITAL_CITY, COUNTRY, SONG, STADIUM, DATE, PERSON, EVENT | ||
CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR | ||
} | ||
|
5 changes: 2 additions & 3 deletions
5
api/src/main/java/lab/en2b/quizapi/questions/answer/AnswerRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
package lab.en2b.quizapi.questions.answer; | ||
|
||
import lab.en2b.quizapi.questions.question.Question; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.util.List; | ||
|
||
public interface AnswerRepository extends JpaRepository<Answer,Long> { | ||
|
||
@Query(value = "SELECT * FROM answers WHERE category=?1 AND language=?2 ORDER BY RANDOM() LIMIT ?3", nativeQuery = true) | ||
List<Answer> findDistractors(String answerCategory, String lang, int numDistractors); | ||
@Query(value = "SELECT MAX(id) AS id, text, category, language FROM answers WHERE category = ?1 AND language = ?2 AND text <> ?3 GROUP BY text, category, language ORDER BY RANDOM() LIMIT ?4", nativeQuery = true) | ||
List<Answer> findDistractors(String answerCategory, String lang, String answerTest, int numDistractors); | ||
} |
3 changes: 2 additions & 1 deletion
3
api/src/main/java/lab/en2b/quizapi/questions/question/QuestionCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package lab.en2b.quizapi.questions.question; | ||
|
||
public enum QuestionCategory { | ||
HISTORY, GEOGRAPHY, SCIENCE, MATH, LITERATURE, ART, SPORTS, MUSIC, MOVIES, TV, POLITICS, OTHER | ||
//HISTORY, GEOGRAPHY, SCIENCE, MATH, LITERATURE, ART, SPORTS, MUSIC, MOVIES, TV, POLITICS, OTHER | ||
GEOGRAPHY, SPORTS, MUSIC | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
import model.AnswerCategory; | ||
import repositories.GeneralRepositoryStorer; | ||
import templates.BallonDOrQuestion; | ||
import templates.CountryCapitalQuestion; | ||
import templates.SongQuestion; | ||
import templates.StadiumQuestion; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
new CountryCapitalQuestion("en"); | ||
new CountryCapitalQuestion("es"); | ||
|
||
//new SongQuestion("en"); | ||
//new SongQuestion("es"); | ||
if(GeneralRepositoryStorer.doesntExist(AnswerCategory.CAPITAL_CITY)) { | ||
new CountryCapitalQuestion("en"); | ||
new CountryCapitalQuestion("es"); | ||
} | ||
|
||
/* | ||
if(GeneralRepositoryStorer.doesntExist(AnswerCategory.SONG.toString())) { | ||
new SongQuestion("en"); | ||
new SongQuestion("es"); | ||
} | ||
if(GeneralRepositoryStorer.doesntExist(AnswerCategory.STADIUM.toString())) { | ||
new StadiumQuestion("en"); | ||
new StadiumQuestion("es"); | ||
} | ||
*/ | ||
|
||
if (GeneralRepositoryStorer.doesntExist(AnswerCategory.BALLON_DOR)) { | ||
new BallonDOrQuestion(""); // No need to specify language code as it is not used | ||
} | ||
|
||
//new StadiumQuestion("en"); | ||
//new StadiumQuestion("es"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,6 @@ | ||
package model; | ||
|
||
public enum AnswerCategory { | ||
OTHER(1), | ||
CAPITAL_CITY(2), | ||
COUNTRY(3), | ||
SONG(4), | ||
STADIUM(5), | ||
DATE(6), | ||
PERSON(7), | ||
EVENT(8); | ||
|
||
private final int value; | ||
|
||
AnswerCategory(int value) { | ||
this.value = value; | ||
} | ||
|
||
public int getValue() { | ||
return value; | ||
} | ||
CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package model; | ||
|
||
public enum QuestionCategory { | ||
HISTORY, GEOGRAPHY, SCIENCE, MATH, LITERATURE, ART, SPORTS, MUSIC, MOVIES, TV, POLITICS, OTHER | ||
//HISTORY, GEOGRAPHY, SCIENCE, MATH, LITERATURE, ART, SPORTS, MUSIC, MOVIES, TV, POLITICS, OTHER | ||
GEOGRAPHY, SPORTS, MUSIC | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
questiongenerator/src/main/java/templates/BallonDOrQuestion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package templates; | ||
|
||
import model.*; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class BallonDOrQuestion extends QuestionTemplate { | ||
|
||
/** | ||
* 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 | ||
*/ | ||
public BallonDOrQuestion(String langCode) { | ||
super(langCode); | ||
} | ||
|
||
@Override | ||
protected void setQuery() { | ||
this.sparqlQuery = | ||
"SELECT ?playerLabel ?year " + | ||
"WHERE { " + | ||
" wd:Q166177 p:P1346 ?statement. " + | ||
" ?statement ps:P1346 ?player. " + | ||
" ?statement pq:P585 ?year. " + | ||
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". } " + | ||
"} " + | ||
"ORDER BY ?year"; | ||
} | ||
|
||
@Override | ||
protected void processResults() { | ||
List<Question> questions = new ArrayList<>(); | ||
List<Answer> answers = new ArrayList<>(); | ||
for (int i = 0; i < results.length(); i++) { | ||
JSONObject result = results.getJSONObject(i); | ||
String playerLabel = result.getJSONObject("playerLabel").getString("value"); | ||
String year = result.getJSONObject("year").getString("value").substring(0, 4); | ||
|
||
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)); | ||
|
||
// 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)); | ||
|
||
} | ||
|
||
repository.saveAll(new ArrayList<>(answers)); | ||
repository.saveAll(new ArrayList<>(questions)); | ||
} | ||
|
||
// Method to check if the player name or year is missing | ||
private boolean needToSkip(String playerLabel, String year) { | ||
return playerLabel.isEmpty() || year.isEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.