Skip to content

Commit

Permalink
Docker fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ablx committed Oct 5, 2017
1 parent 53c85da commit e3a1784
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class DocumentController {
@Autowired
private EntityLinks links;

@Autowired
private ListPreparation listPreparation = new ListPreparation();

@Autowired
private TokenizerService tokenizerService;

Expand All @@ -64,7 +67,7 @@ public ResponseEntity<Document> bulkUpload(@RequestParam("doc") String file,
@RequestMapping(value = "/document/{id}", method = RequestMethod.PUT)
public ResponseEntity<Document> update(@PathVariable String id, @RequestBody Document doc) throws OutdatedException {
log.info("update id " + id);
ListPreparation listPreparation = new ListPreparation();

Document one = repo.findOne(id);
checkVersion(doc);
one.setState(doc.getState());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ml.anon.anonymization.model.Anonymization;
import ml.anon.docmgmt.service.TokenizerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Array;
import java.util.*;
Expand All @@ -15,30 +16,33 @@
* Compares the originals of the anonymizations and dismisses duplicates
* Created by matthias on 20.08.2017
*/
@Component
public class ListPreparation {

@Autowired
TokenizerService tokenizerService = new TokenizerService();
private TokenizerService tokenizerService;

/**
* Removes the duplicates by looking at the original value of the anonymization objects
*
* @param anonymizations list of anonymizations from ml and rulebased approaches
* @return the list of anonymizations without duplicates
*/
private ArrayList<Anonymization> removeDuplicates(List<Anonymization> anonymizations) {
ArrayList<Anonymization> noDuplicate = new ArrayList<Anonymization>();

ObjectMapper mapper = new ObjectMapper();
anonymizations = mapper.convertValue(anonymizations, new TypeReference<List<Anonymization>>(){});
anonymizations = mapper.convertValue(anonymizations, new TypeReference<List<Anonymization>>() {
});
boolean contained = false;
for (Anonymization anon1 : anonymizations) {
for (Anonymization anon2 : noDuplicate) {
if(anon1.getData().getOriginal().equals(anon2.getData().getOriginal())){
if (anon1.getData().getOriginal().equals(anon2.getData().getOriginal())) {
contained = true;
break;
}
}
if(!contained){
if (!contained) {
noDuplicate.add(anon1);
}
contained = false;
Expand All @@ -49,15 +53,16 @@ private ArrayList<Anonymization> removeDuplicates(List<Anonymization> anonymizat
/**
* Sorts the Anonymization list by the number of tokens the original holds, to cope with encapsulated
* anonymizations.
*
* @param anonymizations list to sort by token number
* @return the sorted list of {@link Anonymization}s
*/
private List<Anonymization> sortByTokenNumber(List<Anonymization> anonymizations) {

HashMap<Anonymization, Integer> anonymizationTokenNumber = new HashMap<>();
anonymizations.forEach(anonymization ->
anonymizationTokenNumber.put(anonymization, tokenizerService
.tokenize(anonymization.getData().getOriginal()).size())
anonymizationTokenNumber.put(anonymization, tokenizerService
.tokenize(anonymization.getData().getOriginal()).size())
);

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

/**
* Applies the duplicate removal and sort by number of tokens
*
* @param anonymizations list to apply operations on
* @return sorted {@link Anonymization} list without duplicates
*/
public List<Anonymization> prepareAnonymizationList(List<Anonymization> anonymizations){
public List<Anonymization> prepareAnonymizationList(List<Anonymization> anonymizations) {

anonymizations = this.removeDuplicates(anonymizations);
anonymizations = this.sortByTokenNumber(anonymizations);
Expand Down

0 comments on commit e3a1784

Please sign in to comment.