Skip to content

Commit

Permalink
Fixed the issue with the capitals being incorrectly generated
Browse files Browse the repository at this point in the history
  • Loading branch information
UO289845 committed Apr 1, 2024
1 parent 964a123 commit 632765d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import org.wikidata.wdtk.datamodel.implementation.ItemDocumentImpl;
import org.wikidata.wdtk.datamodel.interfaces.Statement;
import org.wikidata.wdtk.datamodel.interfaces.Value;
import org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException;

import main.java.questionGenerator.question.QuestionType;
Expand All @@ -19,10 +18,17 @@ public RightAnswerIsEntity(String propertyId, QuestionType type) {
super(propertyId, type);
}

/**
* This method acts as a wrapper because in some cases this is enough, but not in all of them,
* so the rest are in charge of overriding it and modifying what they need
*/
@Override
protected String getRightAnswer(Map<String, List<Statement>> claims) {
Value v = claims.get(super.getPropertyId()).get(0).getValue();
String entity = getRightAnswerEntity(v.toString());
return processRightAnswer(claims.get(super.getPropertyId()).get(0));
}

protected String processRightAnswer(Statement st) {
String entity = getRightAnswerEntity(st.getValue().toString());
String answer = "";
try {
ItemDocumentImpl idi = getAlreadyProcessedEntities().get(entity);
Expand All @@ -34,7 +40,7 @@ protected String getRightAnswer(Map<String, List<Statement>> claims) {
else
answer = getName(idi.getLabels());
} catch (MediaWikiApiErrorException | IOException e) {
return null;

}
return answer;
}
Expand All @@ -59,7 +65,7 @@ protected String getAnswer(String id){
return getRightAnswer(idi.getJsonClaims());
}

private String getRightAnswerEntity(String url) {
protected String getRightAnswerEntity(String url) {
String[] split1 = url.split(" ");
String[] split2 = split1[0].split("/");
return split2[split2.length-1];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package main.java.questionGenerator.generator.specificGenerators;

import java.util.List;
import java.util.Map;

import org.wikidata.wdtk.datamodel.interfaces.Snak;
import org.wikidata.wdtk.datamodel.interfaces.SnakGroup;
import org.wikidata.wdtk.datamodel.interfaces.Statement;

import main.java.questionGenerator.generator.RightAnswerIsEntity;
import main.java.questionGenerator.question.QuestionType;

Expand All @@ -17,4 +24,26 @@ protected String getQuestion(String name) {
return String.format(q, name);
}

@Override
protected String getRightAnswer(Map<String, List<Statement>> claims) {
for(Statement st : claims.get(super.getPropertyId())) {
boolean valid = true;
for(SnakGroup sg : st.getQualifiers()) {
for(Snak s : sg.getSnaks()) {
String value = getRightAnswerEntity(s.getPropertyId().toString());
if(value.equals("P582")) {
valid = false;
break;
}
}
if(!valid)
break;
}
if(valid) {
return processRightAnswer(st);
}
}
return null;
}

}

0 comments on commit 632765d

Please sign in to comment.