use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration in project openolat by klemens.
the class EssayAssessmentItemBuilder method createAssessmentItem.
private static AssessmentItem createAssessmentItem(String title) {
AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.essay, title);
// define the response
Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
ResponseDeclaration responseDeclaration = createExtendedTextResponseDeclaration(assessmentItem, responseDeclarationId);
assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
// outcomes
appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
ItemBody itemBody = appendDefaultItemBody(assessmentItem);
appendExtendedTextInteraction(itemBody, responseDeclarationId);
// response processing
ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
return assessmentItem;
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration in project openolat by klemens.
the class QTI21StatisticsManagerImpl method getTextEntryInteractionsStatistic.
@Override
public List<AbstractTextEntryInteractionStatistics> getTextEntryInteractionsStatistic(String itemRefIdent, AssessmentItem item, List<TextEntryInteraction> interactions, QTI21StatisticSearchParams searchParams) {
List<AbstractTextEntryInteractionStatistics> options = new ArrayList<>();
Map<String, AbstractTextEntryInteractionStatistics> optionMap = new HashMap<>();
for (TextEntryInteraction interaction : interactions) {
Identifier responseIdentifier = interaction.getResponseIdentifier();
ResponseDeclaration responseDeclaration = item.getResponseDeclaration(responseIdentifier);
if (responseDeclaration.hasBaseType(BaseType.STRING)) {
TextEntryInteractionStatistics stats = getTextEntryInteractionSettings(responseIdentifier, responseDeclaration);
optionMap.put(responseIdentifier.toString(), stats);
options.add(stats);
} else if (responseDeclaration.hasBaseType(BaseType.FLOAT)) {
NumericalInputInteractionStatistics stats = getNumericalInputInteractionSettings(responseIdentifier, responseDeclaration, item);
optionMap.put(responseIdentifier.toString(), stats);
options.add(stats);
}
}
for (TextEntryInteraction interaction : interactions) {
String responseIdentifier = interaction.getResponseIdentifier().toString();
List<RawData> datas = getRawDatas(itemRefIdent, responseIdentifier, searchParams);
for (RawData data : datas) {
Long count = data.getCount();
if (count != null && count.longValue() > 0) {
AbstractTextEntryInteractionStatistics stats = optionMap.get(responseIdentifier);
String response = data.getStringuifiedResponse();
if (response != null && response.length() >= 2 && response.startsWith("[") && response.endsWith("]")) {
response = response.substring(1, response.length() - 1);
}
if (stats.matchResponse(response)) {
stats.addCorrect(count.longValue());
} else {
stats.addIncorrect(count.longValue());
stats.addWrongResponses(response);
}
}
}
}
return options;
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration in project openolat by klemens.
the class QTI21StatisticsManagerImpl method getMatchStatistics.
@Override
public List<MatchStatistics> getMatchStatistics(String itemRefIdent, AssessmentItem item, MatchInteraction interaction, QTI21StatisticSearchParams searchParams) {
List<RawData> rawDatas = getRawDatas(itemRefIdent, interaction.getResponseIdentifier().toString(), searchParams);
SimpleMatchSet sourceMatchSets = interaction.getSimpleMatchSets().get(0);
SimpleMatchSet targetMatchSets = interaction.getSimpleMatchSets().get(1);
List<MatchStatistics> matchPoints = new ArrayList<>();
ResponseDeclaration responseDeclaration = item.getResponseDeclaration(interaction.getResponseIdentifier());
// readable responses
Map<Identifier, List<Identifier>> associations = new HashMap<>();
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
QtiNodesExtractor.extractIdentifiersFromCorrectResponse(correctResponse, associations);
for (SimpleAssociableChoice sourceChoice : sourceMatchSets.getSimpleAssociableChoices()) {
for (SimpleAssociableChoice targetChoice : targetMatchSets.getSimpleAssociableChoices()) {
DirectedPairValue dKey = new DirectedPairValue(sourceChoice.getIdentifier(), targetChoice.getIdentifier());
String choiceIdentifier = dKey.toQtiString();
String marker = "[" + choiceIdentifier + "]";
boolean correct = associations.containsKey(sourceChoice.getIdentifier()) && associations.get(sourceChoice.getIdentifier()).contains(targetChoice.getIdentifier());
long numCorrect = 0;
long numIncorrect = 0;
for (RawData rawData : rawDatas) {
String response = rawData.getStringuifiedResponse();
if (response.indexOf(marker) >= 0) {
if (correct) {
numCorrect += rawData.getCount();
} else {
numIncorrect += rawData.getCount();
}
}
}
matchPoints.add(new MatchStatistics(sourceChoice.getIdentifier(), targetChoice.getIdentifier(), numCorrect, numIncorrect));
}
}
return matchPoints;
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration in project openolat by klemens.
the class QTI21StatisticsManagerImpl method getKPrimStatistics.
// stringuifiedResponse: [a93247453265982 correct][b93247453265983 correct][c93247453265984 correct][d93247453265985 correct]
@Override
public List<KPrimStatistics> getKPrimStatistics(String itemRefIdent, AssessmentItem item, MatchInteraction interaction, QTI21StatisticSearchParams searchParams) {
List<RawData> rawDatas = getRawDatas(itemRefIdent, interaction.getResponseIdentifier().toString(), searchParams);
List<SimpleMatchSet> matchSets = interaction.getSimpleMatchSets();
List<KPrimStatistics> kprimPoints = new ArrayList<>();
SimpleMatchSet fourMatchSet = matchSets.get(0);
ResponseDeclaration responseDeclaration = item.getResponseDeclaration(interaction.getResponseIdentifier());
// readable responses
Set<String> rightResponses = new HashSet<>();
List<MapEntry> mapEntries = responseDeclaration.getMapping().getMapEntries();
for (MapEntry mapEntry : mapEntries) {
SingleValue mapKey = mapEntry.getMapKey();
if (mapKey instanceof DirectedPairValue) {
DirectedPairValue pairValue = (DirectedPairValue) mapKey;
String source = pairValue.sourceValue().toString();
String destination = pairValue.destValue().toString();
rightResponses.add("[" + source + " " + destination + "]");
}
}
for (SimpleAssociableChoice choice : fourMatchSet.getSimpleAssociableChoices()) {
String choiceIdentifier = choice.getIdentifier().toString();
String markerCorrect = "[" + choiceIdentifier + " correct]";
String markerWrong = "[" + choiceIdentifier + " wrong]";
boolean isCorrectRight = rightResponses.contains(markerCorrect);
String rightFlag = isCorrectRight ? markerCorrect : markerWrong;
String wrongFlag = isCorrectRight ? markerWrong : markerCorrect;
long numCorrect = 0;
long numIncorrect = 0;
long numUnanswered = 0;
for (RawData rawData : rawDatas) {
String response = rawData.getStringuifiedResponse();
if (response.indexOf(rightFlag) >= 0) {
numCorrect += rawData.getCount();
} else if (response.indexOf(wrongFlag) >= 0) {
numIncorrect += rawData.getCount();
} else {
numUnanswered += rawData.getCount();
}
}
kprimPoints.add(new KPrimStatistics(choice.getIdentifier(), isCorrectRight, numCorrect, numIncorrect, numUnanswered));
}
return kprimPoints;
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration in project openolat by klemens.
the class CorrectResponsesUtil method getCorrectMultiplePairResponses.
public static final List<String> getCorrectMultiplePairResponses(AssessmentItem assessmentItem, Interaction interaction, boolean withDelimiter) {
final List<String> correctAnswers = new ArrayList<>(5);
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
if (correctResponse.getCardinality().isOneOf(Cardinality.MULTIPLE)) {
List<FieldValue> values = correctResponse.getFieldValues();
Value value = FieldValue.computeValue(Cardinality.MULTIPLE, values);
if (value instanceof MultipleValue) {
MultipleValue multiValue = (MultipleValue) value;
multiValue.forEach(oValue -> {
if (oValue instanceof PairValue) {
PairValue pairValue = (PairValue) oValue;
String source = pairValue.sourceValue().toString();
String destination = pairValue.destValue().toString();
if (withDelimiter) {
correctAnswers.add("[" + source + " " + destination + "]");
} else {
correctAnswers.add(source + " " + destination);
}
}
});
}
}
}
return correctAnswers;
}
Aggregations