From d8b5f43a7e923544510a8f15d384ec8ed00015e9 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Tue, 22 Dec 2020 14:59:03 +0100 Subject: [PATCH] code formatting --- .../eu/dnetlib/dhp/oa/merge/AuthorMerger.java | 5 +- .../dhp/oa/merge/AuthorMergerTest.java | 140 +++++++++--------- 2 files changed, 73 insertions(+), 72 deletions(-) diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/oa/merge/AuthorMerger.java b/dhp-common/src/main/java/eu/dnetlib/dhp/oa/merge/AuthorMerger.java index 5ad4598a6..b3d84c40f 100644 --- a/dhp-common/src/main/java/eu/dnetlib/dhp/oa/merge/AuthorMerger.java +++ b/dhp-common/src/main/java/eu/dnetlib/dhp/oa/merge/AuthorMerger.java @@ -73,7 +73,7 @@ public class AuthorMerger { if (base == null || enrich == null) return; - // (if an Author has more than 1 pid, it appears 2 times in the list) + // (if an Author has more than 1 pid, it appears 2 times in the list) final Map basePidAuthorMap = base .stream() .filter(a -> a.getPid() != null && a.getPid().size() > 0) @@ -84,7 +84,7 @@ public class AuthorMerger { .map(p -> new Tuple2<>(pidToComparableString(p), a))) .collect(Collectors.toMap(Tuple2::_1, Tuple2::_2, (x1, x2) -> x1)); - // (list of pid that are missing in the other list) + // (list of pid that are missing in the other list) final List> pidToEnrich = enrich .stream() .filter(a -> a.getPid() != null && a.getPid().size() > 0) @@ -96,7 +96,6 @@ public class AuthorMerger { .map(p -> new Tuple2<>(p, a))) .collect(Collectors.toList()); - pidToEnrich .forEach( a -> { diff --git a/dhp-common/src/test/java/eu/dnetlib/dhp/oa/merge/AuthorMergerTest.java b/dhp-common/src/test/java/eu/dnetlib/dhp/oa/merge/AuthorMergerTest.java index 1ff9753be..02e694770 100644 --- a/dhp-common/src/test/java/eu/dnetlib/dhp/oa/merge/AuthorMergerTest.java +++ b/dhp-common/src/test/java/eu/dnetlib/dhp/oa/merge/AuthorMergerTest.java @@ -1,14 +1,5 @@ -package eu.dnetlib.dhp.oa.merge; -import eu.dnetlib.dhp.schema.oaf.Author; -import eu.dnetlib.dhp.schema.oaf.Publication; -import eu.dnetlib.dhp.schema.oaf.StructuredProperty; -import eu.dnetlib.pace.util.MapDocumentUtil; -import org.codehaus.jackson.map.ObjectMapper; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import scala.Tuple2; +package eu.dnetlib.dhp.oa.merge; import java.io.BufferedReader; import java.io.FileReader; @@ -18,80 +9,91 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import org.codehaus.jackson.map.ObjectMapper; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import eu.dnetlib.dhp.schema.oaf.Author; +import eu.dnetlib.dhp.schema.oaf.Publication; +import eu.dnetlib.dhp.schema.oaf.StructuredProperty; +import eu.dnetlib.pace.util.MapDocumentUtil; +import scala.Tuple2; + public class AuthorMergerTest { - String publicationsBasePath; + String publicationsBasePath; - List> authors; + List> authors; - @BeforeEach - public void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { - publicationsBasePath = Paths - .get(AuthorMergerTest.class.getResource("/eu/dnetlib/dhp/oa/merge").toURI()) - .toFile() - .getAbsolutePath(); + publicationsBasePath = Paths + .get(AuthorMergerTest.class.getResource("/eu/dnetlib/dhp/oa/merge").toURI()) + .toFile() + .getAbsolutePath(); - authors = - readSample(publicationsBasePath + "/publications_with_authors.json", Publication.class) - .stream() - .map(p -> p._2().getAuthor()).collect(Collectors.toList()); + authors = readSample(publicationsBasePath + "/publications_with_authors.json", Publication.class) + .stream() + .map(p -> p._2().getAuthor()) + .collect(Collectors.toList()); - } + } - @Test - public void mergeTest() { //used in the dedup: threshold set to 0.95 + @Test + public void mergeTest() { // used in the dedup: threshold set to 0.95 - for (List authors1: authors){ - System.out.println("List " + (authors.indexOf(authors1)+1)); - for (Author author: authors1){ - System.out.println(authorToString(author)); - } - } + for (List authors1 : authors) { + System.out.println("List " + (authors.indexOf(authors1) + 1)); + for (Author author : authors1) { + System.out.println(authorToString(author)); + } + } - List merge = AuthorMerger.merge(authors); + List merge = AuthorMerger.merge(authors); - System.out.println("Merge "); - for (Author author: merge) { - System.out.println(authorToString(author)); - } + System.out.println("Merge "); + for (Author author : merge) { + System.out.println(authorToString(author)); + } - Assertions.assertEquals(7, merge.size()); + Assertions.assertEquals(7, merge.size()); - } + } - public List> readSample(String path, Class clazz) { - List> res = new ArrayList<>(); - BufferedReader reader; - try { - reader = new BufferedReader(new FileReader(path)); - String line = reader.readLine(); - while (line != null) { - res - .add( - new Tuple2<>( - MapDocumentUtil.getJPathString("$.id", line), - new ObjectMapper().readValue(line, clazz))); - // read next line - line = reader.readLine(); - } - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - } + public List> readSample(String path, Class clazz) { + List> res = new ArrayList<>(); + BufferedReader reader; + try { + reader = new BufferedReader(new FileReader(path)); + String line = reader.readLine(); + while (line != null) { + res + .add( + new Tuple2<>( + MapDocumentUtil.getJPathString("$.id", line), + new ObjectMapper().readValue(line, clazz))); + // read next line + line = reader.readLine(); + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } - return res; - } + return res; + } - public String authorToString(Author a){ + public String authorToString(Author a) { - String print = "Fullname = "; - print += a.getFullname() + " pid = ["; - if (a.getPid() != null) - for (StructuredProperty sp : a.getPid()) { - print += sp.toComparableString() + " "; - } - print += "]"; - return print; - } + String print = "Fullname = "; + print += a.getFullname() + " pid = ["; + if (a.getPid() != null) + for (StructuredProperty sp : a.getPid()) { + print += sp.toComparableString() + " "; + } + print += "]"; + return print; + } }