2020-04-02 18:37:53 +02:00
|
|
|
package eu.dnetlib.dhp.oa.dedup;
|
2020-04-01 18:48:31 +02:00
|
|
|
|
2020-04-06 16:30:31 +02:00
|
|
|
import com.google.common.hash.HashFunction;
|
|
|
|
import com.google.common.hash.Hashing;
|
2020-04-02 18:37:53 +02:00
|
|
|
import eu.dnetlib.dhp.application.ArgumentApplicationParser;
|
2020-04-01 18:48:31 +02:00
|
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
2020-04-02 18:37:53 +02:00
|
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
2020-04-03 18:32:25 +02:00
|
|
|
import org.apache.commons.io.FileUtils;
|
2020-04-01 18:48:31 +02:00
|
|
|
import org.apache.commons.io.IOUtils;
|
2020-04-03 18:32:25 +02:00
|
|
|
import org.apache.spark.SparkConf;
|
|
|
|
import org.apache.spark.sql.SparkSession;
|
|
|
|
import org.junit.jupiter.api.*;
|
2020-04-02 18:37:53 +02:00
|
|
|
import org.junit.jupiter.api.extension.ExtendWith;
|
2020-04-01 18:48:31 +02:00
|
|
|
import org.mockito.Mock;
|
2020-04-02 18:37:53 +02:00
|
|
|
import org.mockito.Mockito;
|
2020-04-01 19:05:48 +02:00
|
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
2020-04-01 18:48:31 +02:00
|
|
|
|
2020-04-03 18:32:25 +02:00
|
|
|
import java.io.File;
|
2020-04-01 18:48:31 +02:00
|
|
|
import java.io.IOException;
|
2020-04-03 18:32:25 +02:00
|
|
|
import java.net.URISyntaxException;
|
|
|
|
import java.nio.file.Paths;
|
2020-04-01 18:48:31 +02:00
|
|
|
|
2020-04-01 19:05:48 +02:00
|
|
|
import static org.mockito.Mockito.when;
|
2020-04-03 18:32:25 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
2020-04-01 19:05:48 +02:00
|
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
2020-04-03 18:32:25 +02:00
|
|
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
2020-04-01 18:48:31 +02:00
|
|
|
public class SparkDedupTest {
|
|
|
|
|
2020-04-03 18:32:25 +02:00
|
|
|
@Mock
|
|
|
|
ISLookUpService isLookUpService;
|
2020-04-01 18:48:31 +02:00
|
|
|
|
2020-04-06 16:30:31 +02:00
|
|
|
private SparkSession spark;
|
2020-04-01 18:48:31 +02:00
|
|
|
|
2020-04-06 16:30:31 +02:00
|
|
|
private static String testGraphBasePath;
|
|
|
|
private final static String testOutputBasePath = "/tmp/test_dedup_workflow";
|
|
|
|
private final static String testActionSetId = "test-orchestrator";
|
|
|
|
private final static String testDedupGraphBasePath = "/tmp/test_dedup_workflow/dedup_graph";
|
|
|
|
|
|
|
|
@BeforeAll
|
|
|
|
private static void cleanUp() throws IOException, URISyntaxException {
|
|
|
|
|
|
|
|
testGraphBasePath = Paths.get(SparkDedupTest.class.getResource("/eu/dnetlib/dhp/dedup/entities").toURI()).toFile().getAbsolutePath();
|
|
|
|
|
|
|
|
FileUtils.deleteDirectory(new File(testOutputBasePath));
|
|
|
|
}
|
2020-04-02 18:37:53 +02:00
|
|
|
|
2020-04-03 18:32:25 +02:00
|
|
|
@BeforeEach
|
2020-04-06 16:30:31 +02:00
|
|
|
private void setUp() throws IOException, ISLookUpException {
|
2020-04-03 18:32:25 +02:00
|
|
|
|
|
|
|
spark = SparkSession
|
|
|
|
.builder()
|
|
|
|
.appName(SparkCreateSimRels.class.getSimpleName())
|
|
|
|
.master("local[*]")
|
|
|
|
.config(new SparkConf())
|
|
|
|
.getOrCreate();
|
|
|
|
|
|
|
|
when(isLookUpService.getResourceProfileByQuery(Mockito.contains(testActionSetId)))
|
2020-04-06 16:30:31 +02:00
|
|
|
.thenReturn(IOUtils.toString(SparkDedupTest.class.getResourceAsStream("/eu/dnetlib/dhp/dedup/profiles/mock_orchestrator.xml")));
|
2020-04-02 18:37:53 +02:00
|
|
|
|
|
|
|
when(isLookUpService.getResourceProfileByQuery(Mockito.contains("organization")))
|
2020-04-06 16:30:31 +02:00
|
|
|
.thenReturn(IOUtils.toString(SparkDedupTest.class.getResourceAsStream("/eu/dnetlib/dhp/dedup/conf/org.curr.conf.json")));
|
2020-04-01 18:48:31 +02:00
|
|
|
|
2020-04-02 18:37:53 +02:00
|
|
|
when(isLookUpService.getResourceProfileByQuery(Mockito.contains("publication")))
|
2020-04-06 16:30:31 +02:00
|
|
|
.thenReturn(IOUtils.toString(SparkDedupTest.class.getResourceAsStream("/eu/dnetlib/dhp/dedup/conf/pub.curr.conf.json")));
|
|
|
|
|
2020-04-01 18:48:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-04-03 18:32:25 +02:00
|
|
|
@Order(1)
|
2020-04-01 18:48:31 +02:00
|
|
|
public void createSimRelsTest() throws Exception {
|
2020-04-02 18:37:53 +02:00
|
|
|
|
|
|
|
ArgumentApplicationParser parser = new ArgumentApplicationParser(
|
|
|
|
IOUtils.toString(
|
|
|
|
SparkCreateSimRels.class.getResourceAsStream("/eu/dnetlib/dhp/oa/dedup/createSimRels_parameters.json")));
|
|
|
|
parser.parseArgument(new String[]{
|
2020-04-01 18:48:31 +02:00
|
|
|
"-mt", "local[*]",
|
2020-04-03 18:32:25 +02:00
|
|
|
"-i", testGraphBasePath,
|
|
|
|
"-asi", testActionSetId,
|
2020-04-01 18:48:31 +02:00
|
|
|
"-la", "lookupurl",
|
2020-04-03 18:32:25 +02:00
|
|
|
"-w", testOutputBasePath});
|
|
|
|
|
|
|
|
new SparkCreateSimRels(parser, spark).run(isLookUpService);
|
|
|
|
|
|
|
|
long orgs_simrel = spark.read().load(testOutputBasePath + "/" + testActionSetId + "/organization_simrel").count();
|
|
|
|
long pubs_simrel = spark.read().load(testOutputBasePath + "/" + testActionSetId + "/publication_simrel").count();
|
2020-04-02 18:37:53 +02:00
|
|
|
|
2020-04-06 16:30:31 +02:00
|
|
|
System.out.println("pubs_simrel = " + pubs_simrel);
|
|
|
|
System.out.println("orgs_simrel = " + orgs_simrel);
|
|
|
|
// assertEquals(918, orgs_simrel);
|
|
|
|
// assertEquals(0, pubs_simrel);
|
2020-04-02 18:37:53 +02:00
|
|
|
|
2020-04-01 18:48:31 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 16:30:31 +02:00
|
|
|
@Test
|
|
|
|
@Order(2)
|
|
|
|
public void createCCTest() throws Exception {
|
|
|
|
|
|
|
|
ArgumentApplicationParser parser = new ArgumentApplicationParser(
|
|
|
|
IOUtils.toString(
|
|
|
|
SparkCreateConnectedComponent.class.getResourceAsStream("/eu/dnetlib/dhp/oa/dedup/createCC_parameters.json")));
|
|
|
|
parser.parseArgument(new String[]{
|
|
|
|
"-mt", "local[*]",
|
|
|
|
"-i", testGraphBasePath,
|
|
|
|
"-asi", testActionSetId,
|
|
|
|
"-la", "lookupurl",
|
|
|
|
"-w", testOutputBasePath});
|
|
|
|
|
|
|
|
new SparkCreateConnectedComponent(parser, spark).run(isLookUpService);
|
|
|
|
|
|
|
|
long orgs_mergerel = spark.read().load(testOutputBasePath + "/" + testActionSetId + "/organization_mergerel").count();
|
|
|
|
long pubs_mergerel = spark.read().load(testOutputBasePath + "/" + testActionSetId + "/publication_mergerel").count();
|
|
|
|
|
|
|
|
System.out.println("pubs_mergerel = " + pubs_mergerel);
|
|
|
|
System.out.println("orgs_mergerel = " + orgs_mergerel);
|
|
|
|
// assertEquals(458, orgs_mergerel);
|
|
|
|
// assertEquals(0, pubs_mergerel);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Order(3)
|
|
|
|
public void dedupRecordTest() throws Exception {
|
|
|
|
|
|
|
|
ArgumentApplicationParser parser = new ArgumentApplicationParser(
|
|
|
|
IOUtils.toString(
|
|
|
|
SparkCreateDedupRecord.class.getResourceAsStream("/eu/dnetlib/dhp/oa/dedup/createDedupRecord_parameters.json")));
|
|
|
|
parser.parseArgument(new String[]{
|
|
|
|
"-mt", "local[*]",
|
|
|
|
"-i", testGraphBasePath,
|
|
|
|
"-asi", testActionSetId,
|
|
|
|
"-la", "lookupurl",
|
|
|
|
"-w", testOutputBasePath});
|
|
|
|
|
|
|
|
new SparkCreateDedupRecord(parser, spark).run(isLookUpService);
|
|
|
|
|
|
|
|
long orgs_deduprecord = spark.read().load(testOutputBasePath + "/" + testActionSetId + "/organization_deduprecord").count();
|
|
|
|
long pubs_deduprecord = spark.read().load(testOutputBasePath + "/" + testActionSetId + "/publication_deduprecord").count();
|
|
|
|
|
|
|
|
System.out.println("pubs_deduprecord = " + pubs_deduprecord);
|
|
|
|
System.out.println("pubs_deduprecord = " + orgs_deduprecord);
|
|
|
|
// assertEquals(458, orgs_deduprecord);
|
|
|
|
// assertEquals(0, pubs_deduprecord);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Order(4)
|
|
|
|
public void updateEntityTest() throws Exception {
|
|
|
|
|
|
|
|
ArgumentApplicationParser parser = new ArgumentApplicationParser(
|
|
|
|
IOUtils.toString(
|
|
|
|
SparkUpdateEntity.class.getResourceAsStream("/eu/dnetlib/dhp/oa/dedup/updateEntity_parameters.json")));
|
|
|
|
parser.parseArgument(new String[]{
|
|
|
|
"-mt", "local[*]",
|
|
|
|
"-i", testGraphBasePath,
|
|
|
|
"-w", testOutputBasePath,
|
|
|
|
"-o", testDedupGraphBasePath
|
|
|
|
});
|
|
|
|
|
|
|
|
new SparkUpdateEntity(parser, spark).run(isLookUpService);
|
|
|
|
|
|
|
|
long organizations = spark.read().load(testDedupGraphBasePath + "/organization").count();
|
|
|
|
long publications = spark.read().load(testDedupGraphBasePath + "/publication").count();
|
|
|
|
|
|
|
|
System.out.println("publications = " + publications);
|
|
|
|
System.out.println("organizations = " + organizations);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Order(5)
|
|
|
|
public void propagateRelationTest() throws Exception {
|
|
|
|
|
|
|
|
ArgumentApplicationParser parser = new ArgumentApplicationParser(
|
|
|
|
IOUtils.toString(
|
|
|
|
SparkPropagateRelation.class.getResourceAsStream("/eu/dnetlib/dhp/oa/dedup/propagateRelation_parameters.json")));
|
|
|
|
parser.parseArgument(new String[]{
|
|
|
|
"-mt", "local[*]",
|
|
|
|
"-i", testGraphBasePath,
|
|
|
|
"-w", testOutputBasePath,
|
|
|
|
"-o", testDedupGraphBasePath
|
|
|
|
});
|
|
|
|
|
|
|
|
new SparkPropagateRelation(parser, spark).run(isLookUpService);
|
|
|
|
|
|
|
|
long relations = spark.read().load(testDedupGraphBasePath + "/relation").count();
|
|
|
|
|
|
|
|
System.out.println("relations = " + relations);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Disabled("must be parametrized to run locally")
|
|
|
|
public void testHashCode() {
|
|
|
|
final String s1 = "20|grid________::6031f94bef015a37783268ec1e75f17f";
|
|
|
|
final String s2 = "20|nsf_________::b12be9edf414df8ee66b4c52a2d8da46";
|
|
|
|
|
|
|
|
final HashFunction hashFunction = Hashing.murmur3_128();
|
|
|
|
|
|
|
|
System.out.println(s1.hashCode());
|
|
|
|
System.out.println(hashFunction.hashString(s1).asLong());
|
|
|
|
System.out.println(s2.hashCode());
|
|
|
|
System.out.println(hashFunction.hashString(s2).asLong());
|
2020-04-02 18:37:53 +02:00
|
|
|
}
|
2020-04-01 18:48:31 +02:00
|
|
|
}
|