use of de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult in project ArTEMiS by ls1intum.
the class ModelingPlagiarismDetectionService method checkPlagiarism.
/**
* Convenience method to extract all latest submissions from a ModelingExercise and compute pair-wise distances.
*
* @param exerciseWithParticipationsSubmissionsResults Text Exercise with fetched participations and submissions
* @param minimumSimilarity the minimum similarity so that the result is considered
* @param minimumModelSize the minimum number of model elements to be considered as plagiarism
* @param minimumScore the minimum result score (if available) to be considered as plagiarism
* @return List of submission id pairs and similarity score
*/
public ModelingPlagiarismResult checkPlagiarism(ModelingExercise exerciseWithParticipationsSubmissionsResults, double minimumSimilarity, int minimumModelSize, int minimumScore) {
final List<ModelingSubmission> modelingSubmissions = modelingSubmissionsForComparison(exerciseWithParticipationsSubmissionsResults);
log.info("Found {} modeling submissions in exercise {}", modelingSubmissions.size(), exerciseWithParticipationsSubmissionsResults.getId());
Long exerciseId = exerciseWithParticipationsSubmissionsResults.getId();
ModelingPlagiarismResult result = checkPlagiarism(modelingSubmissions, minimumSimilarity, minimumModelSize, minimumScore, exerciseId);
result.setExercise(exerciseWithParticipationsSubmissionsResults);
return result;
}
use of de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult in project ArTEMiS by ls1intum.
the class ModelingPlagiarismDetectionService method checkPlagiarism.
/**
* Pairwise comparison of text submissions using a TextComparisonStrategy
*
* @param modelingSubmissions List of modeling submissions
* @param minimumSimilarity the minimum similarity so that the result is considered
* @param minimumModelSize the minimum number of model elements to be considered as plagiarism
* @param minimumScore the minimum result score (if available) to be considered as plagiarism
* @param exerciseId the id of the exercise for which the modeling submissions are compared
*
* @return List of submission id pairs and similarity score
*/
public ModelingPlagiarismResult checkPlagiarism(List<ModelingSubmission> modelingSubmissions, double minimumSimilarity, int minimumModelSize, int minimumScore, Long exerciseId) {
String topic = plagiarismWebsocketService.getModelingExercisePlagiarismCheckTopic(exerciseId);
ModelingPlagiarismResult result = new ModelingPlagiarismResult();
Map<UMLDiagram, ModelingSubmission> models = new HashMap<>();
ObjectMapper objectMapper = new ObjectMapper();
AtomicInteger processedSubmissionCount = new AtomicInteger(1);
modelingSubmissions.stream().filter(modelingSubmission -> !modelingSubmission.isEmpty(objectMapper)).filter(modelingSubmission -> minimumScore == 0 || modelingSubmission.getLatestResult() != null && modelingSubmission.getLatestResult().getScore() != null && modelingSubmission.getLatestResult().getScore() >= minimumScore).forEach(modelingSubmission -> {
String progressMessage = "Getting UML diagram for submission: " + processedSubmissionCount + "/" + modelingSubmissions.size();
plagiarismWebsocketService.notifyInstructorAboutPlagiarismState(topic, PlagiarismCheckState.RUNNING, List.of(progressMessage));
try {
log.debug("Build UML diagram from json");
UMLDiagram model = UMLModelParser.buildModelFromJSON(parseString(modelingSubmission.getModel()).getAsJsonObject(), modelingSubmission.getId());
if (model.getAllModelElements().size() >= minimumModelSize) {
models.put(model, modelingSubmission);
}
} catch (IOException e) {
log.error("Parsing the modeling submission " + modelingSubmission.getId() + " did throw an exception:", e);
}
processedSubmissionCount.getAndIncrement();
});
log.info("Found {} modeling submissions with at least {} elements to compare", models.size(), minimumModelSize);
Set<PlagiarismComparison<ModelingSubmissionElement>> comparisons = new HashSet<>();
List<UMLDiagram> nonEmptyDiagrams = new ArrayList<>(models.keySet());
long timeBeforeStartInMillis = System.currentTimeMillis();
// similarity between two different submissions once
for (int i = 0; i < nonEmptyDiagrams.size(); i++) {
String progressMessage = "Comparing submissions: " + (i + 1) + "/" + nonEmptyDiagrams.size();
plagiarismWebsocketService.notifyInstructorAboutPlagiarismState(topic, PlagiarismCheckState.RUNNING, List.of(progressMessage));
for (int j = i + 1; j < nonEmptyDiagrams.size(); j++) {
UMLDiagram model1 = nonEmptyDiagrams.get(i);
UMLDiagram model2 = nonEmptyDiagrams.get(j);
final double similarity = model1.similarity(model2);
log.debug("Compare result {} with {}: {}", i, j, similarity);
if (similarity < minimumSimilarity) {
// ignore comparison results with too small similarity
continue;
}
ModelingSubmission modelingSubmissionA = models.get(model1);
ModelingSubmission modelingSubmissionB = models.get(model2);
log.info("Found similar models {} with {}: {}", i, j, similarity);
PlagiarismSubmission<ModelingSubmissionElement> submissionA = PlagiarismSubmission.fromModelingSubmission(modelingSubmissionA);
submissionA.setSize(model1.getAllModelElements().size());
submissionA.setElements(model1.getAllModelElements().stream().map(ModelingSubmissionElement::fromUMLElement).collect(Collectors.toList()));
PlagiarismSubmission<ModelingSubmissionElement> submissionB = PlagiarismSubmission.fromModelingSubmission(modelingSubmissionB);
submissionB.setSize(model2.getAllModelElements().size());
submissionB.setElements(model2.getAllModelElements().stream().map(ModelingSubmissionElement::fromUMLElement).collect(Collectors.toList()));
PlagiarismComparison<ModelingSubmissionElement> comparison = new PlagiarismComparison<>();
comparison.setPlagiarismResult(result);
comparison.setSimilarity(similarity * 100);
comparison.setSubmissionA(submissionA);
comparison.setSubmissionB(submissionB);
// TODO: Add matches to highlight similar modeling elements
comparison.setMatches(new HashSet<>());
comparisons.add(comparison);
}
}
log.info("Found {} similar modeling submission combinations (>{})", comparisons.size(), minimumSimilarity);
plagiarismWebsocketService.notifyInstructorAboutPlagiarismState(topic, PlagiarismCheckState.COMPLETED, List.of());
long durationInMillis = System.currentTimeMillis() - timeBeforeStartInMillis;
int[] similarityDistribution = calculateSimilarityDistribution(comparisons);
result.setComparisons(comparisons);
result.setDuration(durationInMillis);
result.setSimilarityDistribution(similarityDistribution);
return result;
}
use of de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult in project ArTEMiS by ls1intum.
the class ModelingExerciseIntegrationTest method testGetPlagiarismResultWithoutExercise.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testGetPlagiarismResultWithoutExercise() throws Exception {
ModelingPlagiarismResult result = request.get("/api/modeling-exercises/" + 1 + "/plagiarism-result", HttpStatus.NOT_FOUND, ModelingPlagiarismResult.class);
assertThat(result).isNull();
}
use of de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult in project Artemis by ls1intum.
the class ModelingPlagiarismDetectionService method checkPlagiarism.
/**
* Pairwise comparison of text submissions using a TextComparisonStrategy
*
* @param modelingSubmissions List of modeling submissions
* @param minimumSimilarity the minimum similarity so that the result is considered
* @param minimumModelSize the minimum number of model elements to be considered as plagiarism
* @param minimumScore the minimum result score (if available) to be considered as plagiarism
* @param exerciseId the id of the exercise for which the modeling submissions are compared
*
* @return List of submission id pairs and similarity score
*/
public ModelingPlagiarismResult checkPlagiarism(List<ModelingSubmission> modelingSubmissions, double minimumSimilarity, int minimumModelSize, int minimumScore, Long exerciseId) {
String topic = plagiarismWebsocketService.getModelingExercisePlagiarismCheckTopic(exerciseId);
ModelingPlagiarismResult result = new ModelingPlagiarismResult();
Map<UMLDiagram, ModelingSubmission> models = new HashMap<>();
ObjectMapper objectMapper = new ObjectMapper();
AtomicInteger processedSubmissionCount = new AtomicInteger(1);
modelingSubmissions.stream().filter(modelingSubmission -> !modelingSubmission.isEmpty(objectMapper)).filter(modelingSubmission -> minimumScore == 0 || modelingSubmission.getLatestResult() != null && modelingSubmission.getLatestResult().getScore() != null && modelingSubmission.getLatestResult().getScore() >= minimumScore).forEach(modelingSubmission -> {
String progressMessage = "Getting UML diagram for submission: " + processedSubmissionCount + "/" + modelingSubmissions.size();
plagiarismWebsocketService.notifyInstructorAboutPlagiarismState(topic, PlagiarismCheckState.RUNNING, List.of(progressMessage));
try {
log.debug("Build UML diagram from json");
UMLDiagram model = UMLModelParser.buildModelFromJSON(parseString(modelingSubmission.getModel()).getAsJsonObject(), modelingSubmission.getId());
if (model.getAllModelElements().size() >= minimumModelSize) {
models.put(model, modelingSubmission);
}
} catch (IOException e) {
log.error("Parsing the modeling submission " + modelingSubmission.getId() + " did throw an exception:", e);
}
processedSubmissionCount.getAndIncrement();
});
log.info("Found {} modeling submissions with at least {} elements to compare", models.size(), minimumModelSize);
Set<PlagiarismComparison<ModelingSubmissionElement>> comparisons = new HashSet<>();
List<UMLDiagram> nonEmptyDiagrams = new ArrayList<>(models.keySet());
long timeBeforeStartInMillis = System.currentTimeMillis();
// similarity between two different submissions once
for (int i = 0; i < nonEmptyDiagrams.size(); i++) {
String progressMessage = "Comparing submissions: " + (i + 1) + "/" + nonEmptyDiagrams.size();
plagiarismWebsocketService.notifyInstructorAboutPlagiarismState(topic, PlagiarismCheckState.RUNNING, List.of(progressMessage));
for (int j = i + 1; j < nonEmptyDiagrams.size(); j++) {
UMLDiagram model1 = nonEmptyDiagrams.get(i);
UMLDiagram model2 = nonEmptyDiagrams.get(j);
final double similarity = model1.similarity(model2);
log.debug("Compare result {} with {}: {}", i, j, similarity);
if (similarity < minimumSimilarity) {
// ignore comparison results with too small similarity
continue;
}
ModelingSubmission modelingSubmissionA = models.get(model1);
ModelingSubmission modelingSubmissionB = models.get(model2);
log.info("Found similar models {} with {}: {}", i, j, similarity);
PlagiarismSubmission<ModelingSubmissionElement> submissionA = PlagiarismSubmission.fromModelingSubmission(modelingSubmissionA);
submissionA.setSize(model1.getAllModelElements().size());
submissionA.setElements(model1.getAllModelElements().stream().map(ModelingSubmissionElement::fromUMLElement).collect(Collectors.toList()));
PlagiarismSubmission<ModelingSubmissionElement> submissionB = PlagiarismSubmission.fromModelingSubmission(modelingSubmissionB);
submissionB.setSize(model2.getAllModelElements().size());
submissionB.setElements(model2.getAllModelElements().stream().map(ModelingSubmissionElement::fromUMLElement).collect(Collectors.toList()));
PlagiarismComparison<ModelingSubmissionElement> comparison = new PlagiarismComparison<>();
comparison.setPlagiarismResult(result);
comparison.setSimilarity(similarity * 100);
comparison.setSubmissionA(submissionA);
comparison.setSubmissionB(submissionB);
// TODO: Add matches to highlight similar modeling elements
comparison.setMatches(new HashSet<>());
comparisons.add(comparison);
}
}
log.info("Found {} similar modeling submission combinations (>{})", comparisons.size(), minimumSimilarity);
plagiarismWebsocketService.notifyInstructorAboutPlagiarismState(topic, PlagiarismCheckState.COMPLETED, List.of());
long durationInMillis = System.currentTimeMillis() - timeBeforeStartInMillis;
int[] similarityDistribution = calculateSimilarityDistribution(comparisons);
result.setComparisons(comparisons);
result.setDuration(durationInMillis);
result.setSimilarityDistribution(similarityDistribution);
return result;
}
use of de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult in project Artemis by ls1intum.
the class ModelingExerciseResource method checkPlagiarism.
/**
* GET modeling-exercises/{exerciseId}/check-plagiarism
* <p>
* Start the automated plagiarism detection for the given exercise and return its result.
*
* @param exerciseId for which all submission should be checked
* @param similarityThreshold ignore comparisons whose similarity is below this threshold (%)
* @param minimumScore consider only submissions whose score is greater or equal to this
* value
* @param minimumSize consider only submissions whose size is greater or equal to this
* value
* @return the ResponseEntity with status 200 (OK) and the list of at most 500 pair-wise submissions with a similarity above the given threshold (e.g. 50%).
*/
@GetMapping("modeling-exercises/{exerciseId}/check-plagiarism")
@FeatureToggle(Feature.PlagiarismChecks)
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<ModelingPlagiarismResult> checkPlagiarism(@PathVariable long exerciseId, @RequestParam float similarityThreshold, @RequestParam int minimumScore, @RequestParam int minimumSize) {
var modelingExercise = modelingExerciseRepository.findByIdWithStudentParticipationsSubmissionsResultsElseThrow(exerciseId);
authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.INSTRUCTOR, modelingExercise, null);
long start = System.nanoTime();
log.info("Start modelingPlagiarismDetectionService.checkPlagiarism for exercise {}", exerciseId);
ModelingPlagiarismResult result = modelingPlagiarismDetectionService.checkPlagiarism(modelingExercise, similarityThreshold / 100, minimumSize, minimumScore);
log.info("Finished modelingPlagiarismDetectionService.checkPlagiarism call for {} comparisons in {}", result.getComparisons().size(), TimeLogUtil.formatDurationFrom(start));
// TODO: limit the amount temporarily because of database issues
result.sortAndLimit(100);
log.info("Limited number of comparisons to {} to avoid performance issues when saving to database", result.getComparisons().size());
start = System.nanoTime();
plagiarismResultRepository.savePlagiarismResultAndRemovePrevious(result);
log.info("Finished plagiarismResultRepository.savePlagiarismResultAndRemovePrevious call in {}", TimeLogUtil.formatDurationFrom(start));
for (var comparison : result.getComparisons()) {
comparison.setPlagiarismResult(null);
}
return ResponseEntity.ok(result);
}
Aggregations