Search in sources :

Example 6 with Submission

use of uk.ac.ebi.spot.goci.model.deposition.Submission in project goci by EBISPOT.

the class PublicationController method matchPublication.

@RequestMapping(value = "/match", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<Map<String, Object>> matchPublication(Model model, @RequestBody String pubmedId) {
    Map<String, Object> results = new HashMap<>();
    CosineDistance cosScore = new CosineDistance();
    LevenshteinDistance levenshteinDistance = new LevenshteinDistance();
    JaroWinklerSimilarity jwDistance = new JaroWinklerSimilarity();
    EuropePMCData europePMCResult = europepmcPubMedSearchService.createStudyByPubmed(pubmedId);
    Map<String, String> searchProps = new HashMap<>();
    List<Map<String, String>> data = new ArrayList<>();
    if (!europePMCResult.getError()) {
        try {
            searchProps.put("pubMedID", europePMCResult.getPublication().getPubmedId());
            searchProps.put("author", europePMCResult.getFirstAuthor().getFullname());
            searchProps.put("title", europePMCResult.getPublication().getTitle());
            searchProps.put("doi", europePMCResult.getDoi());
            results.put("search", searchProps);
            String searchTitle = europePMCResult.getPublication().getTitle();
            String searchAuthor = europePMCResult.getFirstAuthor().getFullname();
            CharSequence searchString = buildSearch(searchAuthor, searchTitle);
            Map<String, Submission> submissionMap = submissionService.getSubmissionsBasic();
            for (Map.Entry<String, Submission> e : submissionMap.entrySet()) {
                Map<String, String> props = new HashMap<>();
                Submission submission = e.getValue();
                String matchTitle = submission.getTitle();
                String matchAuthor = submission.getAuthor();
                CharSequence matchString = buildSearch(matchAuthor, matchTitle);
                props.put("submissionID", submission.getId());
                props.put("pubMedID", submission.getPubMedID());
                props.put("author", submission.getAuthor());
                props.put("title", submission.getTitle());
                props.put("doi", submission.getDoi());
                if (matchString.equals("")) {
                    props.put("cosScore", new Integer(0).toString());
                    props.put("levDistance", new Integer(0).toString());
                    props.put("jwScore", new Integer(0).toString());
                } else {
                    Double score = cosScore.apply(searchString, matchString) * 100;
                    Integer ldScore = levenshteinDistance.apply(searchString, matchString);
                    Double jwScore = jwDistance.apply(searchString, matchString) * 100;
                    props.put("cosScore", normalizeScore(score.intValue()).toString());
                    props.put("levDistance", normalizeScore(ldScore).toString());
                    props.put("jwScore", new Integer(jwScore.intValue()).toString());
                }
                data.add(props);
            }
            data.sort((o1, o2) -> Integer.decode(o2.get("cosScore")).compareTo(Integer.decode(o1.get("cosScore"))));
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        results.put("error", "ID " + pubmedId + " not found");
    }
    results.put("data", data);
    model.addAttribute("baseUrl", depositionUiURL);
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.add("Content-Type", "application/json; charset=utf-8");
    return new ResponseEntity<>(results, responseHeaders, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) Submission(uk.ac.ebi.spot.goci.model.deposition.Submission) LevenshteinDistance(org.apache.commons.text.similarity.LevenshteinDistance) IOException(java.io.IOException) EuropePMCData(uk.ac.ebi.spot.goci.utils.EuropePMCData) ResponseEntity(org.springframework.http.ResponseEntity) JaroWinklerSimilarity(org.apache.commons.text.similarity.JaroWinklerSimilarity) CosineDistance(org.apache.commons.text.similarity.CosineDistance)

Aggregations

Submission (uk.ac.ebi.spot.goci.model.deposition.Submission)6 DepositionSubmission (uk.ac.ebi.spot.goci.model.deposition.DepositionSubmission)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ResponseEntity (org.springframework.http.ResponseEntity)2 SecureUser (uk.ac.ebi.spot.goci.model.SecureUser)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 CosineDistance (org.apache.commons.text.similarity.CosineDistance)1 JaroWinklerSimilarity (org.apache.commons.text.similarity.JaroWinklerSimilarity)1 LevenshteinDistance (org.apache.commons.text.similarity.LevenshteinDistance)1 HttpHeaders (org.springframework.http.HttpHeaders)1 Async (org.springframework.scheduling.annotation.Async)1 Transactional (org.springframework.transaction.annotation.Transactional)1 DepositionAssociationDto (uk.ac.ebi.spot.goci.model.deposition.DepositionAssociationDto)1 DepositionAuthor (uk.ac.ebi.spot.goci.model.deposition.DepositionAuthor)1 DepositionStudyDto (uk.ac.ebi.spot.goci.model.deposition.DepositionStudyDto)1 SubmissionImportProgress (uk.ac.ebi.spot.goci.model.deposition.SubmissionImportProgress)1 EuropePMCData (uk.ac.ebi.spot.goci.utils.EuropePMCData)1