Skip to content

Commit

Permalink
Improved the way of collecting the properties for generating entites
Browse files Browse the repository at this point in the history
  • Loading branch information
UO289845 committed Apr 18, 2024
1 parent e807bf1 commit 5281b9c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public List<Question> generateQuestions(QuestionType type, int amount){
List<Question> questions = new ArrayList<>();
List<String> entites = new ArrayList<>();
try {
entites = EntityGenerator.getEntities(type, 100);
entites = EntityGenerator.getEntities(type, 100, generator.getPropertyId());
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ public class EntityGenerator {
private static final String PRE_URL = "https://www.wikidata.org/w/api.php?action=query&format=json&"
+ "list=backlinks&formatversion=2&";

private static String property = "";
private static final String PROPERTY_URL = "bltitle=Property%3AP";
private static final String PROPERTY_URL = "bltitle=Property%3A";

private static final String POST_URL = "&blnamespace=0&";

private static final String LIMIT = "bllimit=";

public static List<String> getEntities(QuestionType type, int size) throws IOException{
propertyFactory(type);
public static List<String> getEntities(QuestionType type, int size, String property) throws IOException{
URL url = new URL(PRE_URL+PROPERTY_URL+property+POST_URL+LIMIT+size);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
Expand All @@ -44,29 +42,6 @@ public static List<String> getEntities(QuestionType type, int size) throws IOExc
return result;
}

private static void propertyFactory(QuestionType type) {
switch (type) {
case CAPITAL:
property = "36";
break;
case LANGUAGE:
property = "37";
break;
case POPULATION:
property = "1082";
break;
case SIZE:
property = "2046";
break;
case HEAD_OF_GOVERMENT:
property = "6";
break;
case DIRECTOR:
property = "57";
break;
}
}

private static List<String> extractEntities(String json){
List<String> result = new ArrayList<>();
String[] entities = json.split("\"title\":");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private String getAnswer(String id) throws Exception{
public List<String> getWrongAnswers(String rightAnswer) throws Exception {
List<String> entites = new ArrayList<>();
try {
entites = EntityGenerator.getEntities(type, 100);
entites = EntityGenerator.getEntities(type, 100, getPropertyId());
} catch (IOException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 5281b9c

Please sign in to comment.