Skip to content

Commit e3a1784

Browse files
committed
Docker fixes
1 parent 53c85da commit e3a1784

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

service/src/main/java/ml/anon/docmgmt/controller/DocumentController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public class DocumentController {
4141
@Autowired
4242
private EntityLinks links;
4343

44+
@Autowired
45+
private ListPreparation listPreparation = new ListPreparation();
46+
4447
@Autowired
4548
private TokenizerService tokenizerService;
4649

@@ -64,7 +67,7 @@ public ResponseEntity<Document> bulkUpload(@RequestParam("doc") String file,
6467
@RequestMapping(value = "/document/{id}", method = RequestMethod.PUT)
6568
public ResponseEntity<Document> update(@PathVariable String id, @RequestBody Document doc) throws OutdatedException {
6669
log.info("update id " + id);
67-
ListPreparation listPreparation = new ListPreparation();
70+
6871
Document one = repo.findOne(id);
6972
checkVersion(doc);
7073
one.setState(doc.getState());

service/src/main/java/ml/anon/docmgmt/extraction/ListPreparation.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import ml.anon.anonymization.model.Anonymization;
88
import ml.anon.docmgmt.service.TokenizerService;
99
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.stereotype.Component;
1011

1112
import java.lang.reflect.Array;
1213
import java.util.*;
@@ -15,30 +16,33 @@
1516
* Compares the originals of the anonymizations and dismisses duplicates
1617
* Created by matthias on 20.08.2017
1718
*/
19+
@Component
1820
public class ListPreparation {
1921

2022
@Autowired
21-
TokenizerService tokenizerService = new TokenizerService();
23+
private TokenizerService tokenizerService;
2224

2325
/**
2426
* Removes the duplicates by looking at the original value of the anonymization objects
27+
*
2528
* @param anonymizations list of anonymizations from ml and rulebased approaches
2629
* @return the list of anonymizations without duplicates
2730
*/
2831
private ArrayList<Anonymization> removeDuplicates(List<Anonymization> anonymizations) {
2932
ArrayList<Anonymization> noDuplicate = new ArrayList<Anonymization>();
3033

3134
ObjectMapper mapper = new ObjectMapper();
32-
anonymizations = mapper.convertValue(anonymizations, new TypeReference<List<Anonymization>>(){});
35+
anonymizations = mapper.convertValue(anonymizations, new TypeReference<List<Anonymization>>() {
36+
});
3337
boolean contained = false;
3438
for (Anonymization anon1 : anonymizations) {
3539
for (Anonymization anon2 : noDuplicate) {
36-
if(anon1.getData().getOriginal().equals(anon2.getData().getOriginal())){
40+
if (anon1.getData().getOriginal().equals(anon2.getData().getOriginal())) {
3741
contained = true;
3842
break;
3943
}
4044
}
41-
if(!contained){
45+
if (!contained) {
4246
noDuplicate.add(anon1);
4347
}
4448
contained = false;
@@ -49,15 +53,16 @@ private ArrayList<Anonymization> removeDuplicates(List<Anonymization> anonymizat
4953
/**
5054
* Sorts the Anonymization list by the number of tokens the original holds, to cope with encapsulated
5155
* anonymizations.
56+
*
5257
* @param anonymizations list to sort by token number
5358
* @return the sorted list of {@link Anonymization}s
5459
*/
5560
private List<Anonymization> sortByTokenNumber(List<Anonymization> anonymizations) {
5661

5762
HashMap<Anonymization, Integer> anonymizationTokenNumber = new HashMap<>();
5863
anonymizations.forEach(anonymization ->
59-
anonymizationTokenNumber.put(anonymization, tokenizerService
60-
.tokenize(anonymization.getData().getOriginal()).size())
64+
anonymizationTokenNumber.put(anonymization, tokenizerService
65+
.tokenize(anonymization.getData().getOriginal()).size())
6166
);
6267

6368
Collections.sort(anonymizations,
@@ -70,10 +75,11 @@ private List<Anonymization> sortByTokenNumber(List<Anonymization> anonymizations
7075

7176
/**
7277
* Applies the duplicate removal and sort by number of tokens
78+
*
7379
* @param anonymizations list to apply operations on
7480
* @return sorted {@link Anonymization} list without duplicates
7581
*/
76-
public List<Anonymization> prepareAnonymizationList(List<Anonymization> anonymizations){
82+
public List<Anonymization> prepareAnonymizationList(List<Anonymization> anonymizations) {
7783

7884
anonymizations = this.removeDuplicates(anonymizations);
7985
anonymizations = this.sortByTokenNumber(anonymizations);

0 commit comments

Comments
 (0)