changed the bl because of changed of the examples for the re implementation of the propagation step
This commit is contained in:
parent
6135096ef1
commit
ec7f166690
|
@ -2,6 +2,9 @@ package eu.dnetlib.dhp.projecttoresult;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.dnetlib.dhp.schema.oaf.Relation;
|
import eu.dnetlib.dhp.schema.oaf.Relation;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.spark.SparkConf;
|
import org.apache.spark.SparkConf;
|
||||||
import org.apache.spark.api.java.JavaRDD;
|
import org.apache.spark.api.java.JavaRDD;
|
||||||
|
@ -15,9 +18,6 @@ import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
public class ProjectPropagationJobTest {
|
public class ProjectPropagationJobTest {
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@ public class ProjectPropagationJobTest {
|
||||||
|
|
||||||
private static Path workingDir;
|
private static Path workingDir;
|
||||||
|
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void beforeAll() throws IOException {
|
public static void beforeAll() throws IOException {
|
||||||
workingDir = Files.createTempDirectory(ProjectPropagationJobTest.class.getSimpleName());
|
workingDir = Files.createTempDirectory(ProjectPropagationJobTest.class.getSimpleName());
|
||||||
|
@ -47,13 +46,11 @@ public class ProjectPropagationJobTest {
|
||||||
conf.set("spark.sql.warehouse.dir", workingDir.toString());
|
conf.set("spark.sql.warehouse.dir", workingDir.toString());
|
||||||
conf.set("hive.metastore.warehouse.dir", workingDir.resolve("warehouse").toString());
|
conf.set("hive.metastore.warehouse.dir", workingDir.resolve("warehouse").toString());
|
||||||
|
|
||||||
|
spark =
|
||||||
spark = SparkSession
|
SparkSession.builder()
|
||||||
.builder()
|
.appName(ProjectPropagationJobTest.class.getSimpleName())
|
||||||
.appName(ProjectPropagationJobTest.class.getSimpleName())
|
.config(conf)
|
||||||
.config(conf)
|
.getOrCreate();
|
||||||
.getOrCreate();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
|
@ -63,123 +60,203 @@ public class ProjectPropagationJobTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* There are no new relations to be added. All the possible relations have already been linked with the project in the graph
|
* There are no new relations to be added. All the possible relations have already been linked
|
||||||
|
* with the project in the graph
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void NoUpdateTest() throws Exception {
|
public void NoUpdateTest() throws Exception {
|
||||||
|
|
||||||
SparkResultToProjectThroughSemRelJob3.main(new String[]{
|
SparkResultToProjectThroughSemRelJob3.main(
|
||||||
"-isTest", Boolean.TRUE.toString(),
|
new String[] {
|
||||||
"-isSparkSessionManaged", Boolean.FALSE.toString(),
|
"-isTest",
|
||||||
// "-sourcePath", getClass().getResource("/eu/dnetlib/dhp/resulttoorganizationfrominstrepo/sample/relation").getPath(),
|
Boolean.TRUE.toString(),
|
||||||
"-hive_metastore_uris", "",
|
"-isSparkSessionManaged",
|
||||||
"-writeUpdate", "false",
|
Boolean.FALSE.toString(),
|
||||||
"-saveGraph", "true",
|
// "-sourcePath",
|
||||||
"-outputPath", workingDir.toString() + "/relation",
|
// getClass().getResource("/eu/dnetlib/dhp/resulttoorganizationfrominstrepo/sample/relation").getPath(),
|
||||||
"-potentialUpdatePath", getClass().getResource("/eu/dnetlib/dhp/projecttoresult/preparedInfo/noupdates/potentialUpdates").getPath(),
|
"-hive_metastore_uris",
|
||||||
"-alreadyLinkedPath",getClass().getResource("/eu/dnetlib/dhp/projecttoresult/preparedInfo/alreadyLinked").getPath(),
|
"",
|
||||||
});
|
"-saveGraph",
|
||||||
|
"true",
|
||||||
|
"-outputPath",
|
||||||
|
workingDir.toString() + "/relation",
|
||||||
|
"-potentialUpdatePath",
|
||||||
|
getClass()
|
||||||
|
.getResource(
|
||||||
|
"/eu/dnetlib/dhp/projecttoresult/preparedInfo/noupdates/potentialUpdates")
|
||||||
|
.getPath(),
|
||||||
|
"-alreadyLinkedPath",
|
||||||
|
getClass()
|
||||||
|
.getResource(
|
||||||
|
"/eu/dnetlib/dhp/projecttoresult/preparedInfo/alreadyLinked")
|
||||||
|
.getPath(),
|
||||||
|
});
|
||||||
|
|
||||||
final JavaSparkContext sc = new JavaSparkContext(spark.sparkContext());
|
final JavaSparkContext sc = new JavaSparkContext(spark.sparkContext());
|
||||||
|
|
||||||
JavaRDD<Relation> tmp = sc.textFile(workingDir.toString()+"/relation")
|
JavaRDD<Relation> tmp =
|
||||||
.map(item -> OBJECT_MAPPER.readValue(item, Relation.class));
|
sc.textFile(workingDir.toString() + "/relation")
|
||||||
|
.map(item -> OBJECT_MAPPER.readValue(item, Relation.class));
|
||||||
|
|
||||||
Assertions.assertEquals(0, tmp.count());
|
Assertions.assertEquals(0, tmp.count());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All the possible updates will produce a new relation. No relations are already linked in the grpha
|
* All the possible updates will produce a new relation. No relations are already linked in the
|
||||||
|
* grpha
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void UpdateTenTest() throws Exception{
|
public void UpdateTenTest() throws Exception {
|
||||||
SparkResultToProjectThroughSemRelJob3.main(new String[]{
|
SparkResultToProjectThroughSemRelJob3.main(
|
||||||
"-isTest", Boolean.TRUE.toString(),
|
new String[] {
|
||||||
"-isSparkSessionManaged", Boolean.FALSE.toString(),
|
"-isTest",
|
||||||
// "-sourcePath", getClass().getResource("/eu/dnetlib/dhp/resulttoorganizationfrominstrepo/sample/relation").getPath(),
|
Boolean.TRUE.toString(),
|
||||||
"-hive_metastore_uris", "",
|
"-isSparkSessionManaged",
|
||||||
"-writeUpdate", "false",
|
Boolean.FALSE.toString(),
|
||||||
"-saveGraph", "true",
|
// "-sourcePath",
|
||||||
"-outputPath", workingDir.toString() + "/relation",
|
// getClass().getResource("/eu/dnetlib/dhp/resulttoorganizationfrominstrepo/sample/relation").getPath(),
|
||||||
"-potentialUpdatePath", getClass().getResource("/eu/dnetlib/dhp/projecttoresult/preparedInfo/tenupdates/potentialUpdates").getPath(),
|
"-hive_metastore_uris",
|
||||||
"-alreadyLinkedPath",getClass().getResource("/eu/dnetlib/dhp/projecttoresult/preparedInfo/alreadyLinked").getPath(),
|
"",
|
||||||
});
|
"-saveGraph",
|
||||||
|
"true",
|
||||||
|
"-outputPath",
|
||||||
|
workingDir.toString() + "/relation",
|
||||||
|
"-potentialUpdatePath",
|
||||||
|
getClass()
|
||||||
|
.getResource(
|
||||||
|
"/eu/dnetlib/dhp/projecttoresult/preparedInfo/tenupdates/potentialUpdates")
|
||||||
|
.getPath(),
|
||||||
|
"-alreadyLinkedPath",
|
||||||
|
getClass()
|
||||||
|
.getResource(
|
||||||
|
"/eu/dnetlib/dhp/projecttoresult/preparedInfo/alreadyLinked")
|
||||||
|
.getPath(),
|
||||||
|
});
|
||||||
|
|
||||||
final JavaSparkContext sc = new JavaSparkContext(spark.sparkContext());
|
final JavaSparkContext sc = new JavaSparkContext(spark.sparkContext());
|
||||||
|
|
||||||
JavaRDD<Relation> tmp = sc.textFile(workingDir.toString()+"/relation")
|
JavaRDD<Relation> tmp =
|
||||||
.map(item -> OBJECT_MAPPER.readValue(item, Relation.class));
|
sc.textFile(workingDir.toString() + "/relation")
|
||||||
|
.map(item -> OBJECT_MAPPER.readValue(item, Relation.class));
|
||||||
|
|
||||||
//got 20 new relations because "produces" and "isProducedBy" are added
|
// got 20 new relations because "produces" and "isProducedBy" are added
|
||||||
Assertions.assertEquals(20, tmp.count());
|
Assertions.assertEquals(10, tmp.count());
|
||||||
|
|
||||||
Dataset<Relation> verificationDs = spark.createDataset(tmp.rdd(), Encoders.bean(Relation.class));
|
Dataset<Relation> verificationDs =
|
||||||
|
spark.createDataset(tmp.rdd(), Encoders.bean(Relation.class));
|
||||||
|
|
||||||
Assertions.assertEquals(10, verificationDs.filter("relClass = 'produces'").count());
|
Assertions.assertEquals(5, verificationDs.filter("relClass = 'produces'").count());
|
||||||
Assertions.assertEquals(10, verificationDs.filter("relClass = 'isProducedBy'").count());
|
Assertions.assertEquals(5, verificationDs.filter("relClass = 'isProducedBy'").count());
|
||||||
|
|
||||||
Assertions.assertEquals(10, verificationDs.filter(r -> r.getSource().substring(0, 2). equals("50") &&
|
Assertions.assertEquals(
|
||||||
r.getTarget().substring(0,2).equals("40") &&
|
5,
|
||||||
r.getRelClass().equals("isProducedBy")).count());
|
verificationDs
|
||||||
Assertions.assertEquals(10, verificationDs.filter(r -> r.getSource().substring(0, 2). equals("40") &&
|
.filter(
|
||||||
r.getTarget().substring(0,2).equals("50") &&
|
r ->
|
||||||
r.getRelClass().equals("produces")).count());
|
r.getSource().substring(0, 2).equals("50")
|
||||||
|
&& r.getTarget().substring(0, 2).equals("40")
|
||||||
|
&& r.getRelClass().equals("isProducedBy"))
|
||||||
|
.count());
|
||||||
|
Assertions.assertEquals(
|
||||||
|
5,
|
||||||
|
verificationDs
|
||||||
|
.filter(
|
||||||
|
r ->
|
||||||
|
r.getSource().substring(0, 2).equals("40")
|
||||||
|
&& r.getTarget().substring(0, 2).equals("50")
|
||||||
|
&& r.getRelClass().equals("produces"))
|
||||||
|
.count());
|
||||||
|
|
||||||
verificationDs.createOrReplaceTempView("temporary");
|
verificationDs.createOrReplaceTempView("temporary");
|
||||||
|
|
||||||
Assertions.assertEquals(20, spark.sql("Select * from temporary where datainfo.inferenceprovenance = 'propagation'").count());
|
Assertions.assertEquals(
|
||||||
|
10,
|
||||||
|
spark.sql(
|
||||||
|
"Select * from temporary where datainfo.inferenceprovenance = 'propagation'")
|
||||||
|
.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One of the relations in the possible updates is already linked to the project in the graph.
|
* One of the relations in the possible updates is already linked to the project in the graph.
|
||||||
* All the others are not. There will be 9 new associations leading to 18 new relations
|
* All the others are not. There will be 9 new associations leading to 18 new relations
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void UpdateMixTest() throws Exception{
|
public void UpdateMixTest() throws Exception {
|
||||||
SparkResultToProjectThroughSemRelJob3.main(new String[]{
|
SparkResultToProjectThroughSemRelJob3.main(
|
||||||
"-isTest", Boolean.TRUE.toString(),
|
new String[] {
|
||||||
"-isSparkSessionManaged", Boolean.FALSE.toString(),
|
"-isTest",
|
||||||
// "-sourcePath", getClass().getResource("/eu/dnetlib/dhp/resulttoorganizationfrominstrepo/sample/relation").getPath(),
|
Boolean.TRUE.toString(),
|
||||||
"-hive_metastore_uris", "",
|
"-isSparkSessionManaged",
|
||||||
"-writeUpdate", "false",
|
Boolean.FALSE.toString(),
|
||||||
"-saveGraph", "true",
|
// "-sourcePath",
|
||||||
"-outputPath", workingDir.toString() + "/relation",
|
// getClass().getResource("/eu/dnetlib/dhp/resulttoorganizationfrominstrepo/sample/relation").getPath(),
|
||||||
"-potentialUpdatePath", getClass().getResource("/eu/dnetlib/dhp/projecttoresult/preparedInfo/updatesmixed/potentialUpdates").getPath(),
|
"-hive_metastore_uris",
|
||||||
"-alreadyLinkedPath",getClass().getResource("/eu/dnetlib/dhp/projecttoresult/preparedInfo/alreadyLinked").getPath(),
|
"",
|
||||||
});
|
"-saveGraph",
|
||||||
|
"true",
|
||||||
|
"-outputPath",
|
||||||
|
workingDir.toString() + "/relation",
|
||||||
|
"-potentialUpdatePath",
|
||||||
|
getClass()
|
||||||
|
.getResource(
|
||||||
|
"/eu/dnetlib/dhp/projecttoresult/preparedInfo/updatesmixed/potentialUpdates")
|
||||||
|
.getPath(),
|
||||||
|
"-alreadyLinkedPath",
|
||||||
|
getClass()
|
||||||
|
.getResource(
|
||||||
|
"/eu/dnetlib/dhp/projecttoresult/preparedInfo/alreadyLinked")
|
||||||
|
.getPath(),
|
||||||
|
});
|
||||||
|
|
||||||
final JavaSparkContext sc = new JavaSparkContext(spark.sparkContext());
|
final JavaSparkContext sc = new JavaSparkContext(spark.sparkContext());
|
||||||
|
|
||||||
JavaRDD<Relation> tmp = sc.textFile(workingDir.toString()+"/relation")
|
JavaRDD<Relation> tmp =
|
||||||
.map(item -> OBJECT_MAPPER.readValue(item, Relation.class));
|
sc.textFile(workingDir.toString() + "/relation")
|
||||||
|
.map(item -> OBJECT_MAPPER.readValue(item, Relation.class));
|
||||||
|
|
||||||
// JavaRDD<Relation> tmp = sc.textFile("/tmp/relation")
|
// JavaRDD<Relation> tmp = sc.textFile("/tmp/relation")
|
||||||
// .map(item -> OBJECT_MAPPER.readValue(item, Relation.class));
|
// .map(item -> OBJECT_MAPPER.readValue(item, Relation.class));
|
||||||
|
|
||||||
|
// got 20 new relations because "produces" and "isProducedBy" are added
|
||||||
|
Assertions.assertEquals(8, tmp.count());
|
||||||
|
|
||||||
//got 20 new relations because "produces" and "isProducedBy" are added
|
Dataset<Relation> verificationDs =
|
||||||
Assertions.assertEquals(18, tmp.count());
|
spark.createDataset(tmp.rdd(), Encoders.bean(Relation.class));
|
||||||
|
|
||||||
Dataset<Relation> verificationDs = spark.createDataset(tmp.rdd(), Encoders.bean(Relation.class));
|
Assertions.assertEquals(4, verificationDs.filter("relClass = 'produces'").count());
|
||||||
|
Assertions.assertEquals(4, verificationDs.filter("relClass = 'isProducedBy'").count());
|
||||||
|
|
||||||
Assertions.assertEquals(9, verificationDs.filter("relClass = 'produces'").count());
|
Assertions.assertEquals(
|
||||||
Assertions.assertEquals(9, verificationDs.filter("relClass = 'isProducedBy'").count());
|
4,
|
||||||
|
verificationDs
|
||||||
Assertions.assertEquals(9, verificationDs.filter(r -> r.getSource().substring(0, 2). equals("50") &&
|
.filter(
|
||||||
r.getTarget().substring(0,2).equals("40") &&
|
r ->
|
||||||
r.getRelClass().equals("isProducedBy")).count());
|
r.getSource().substring(0, 2).equals("50")
|
||||||
Assertions.assertEquals(9, verificationDs.filter(r -> r.getSource().substring(0, 2). equals("40") &&
|
&& r.getTarget().substring(0, 2).equals("40")
|
||||||
r.getTarget().substring(0,2).equals("50") &&
|
&& r.getRelClass().equals("isProducedBy"))
|
||||||
r.getRelClass().equals("produces")).count());
|
.count());
|
||||||
|
Assertions.assertEquals(
|
||||||
|
4,
|
||||||
|
verificationDs
|
||||||
|
.filter(
|
||||||
|
r ->
|
||||||
|
r.getSource().substring(0, 2).equals("40")
|
||||||
|
&& r.getTarget().substring(0, 2).equals("50")
|
||||||
|
&& r.getRelClass().equals("produces"))
|
||||||
|
.count());
|
||||||
|
|
||||||
verificationDs.createOrReplaceTempView("temporary");
|
verificationDs.createOrReplaceTempView("temporary");
|
||||||
|
|
||||||
Assertions.assertEquals(18, spark.sql("Select * from temporary where datainfo.inferenceprovenance = 'propagation'").count());
|
Assertions.assertEquals(
|
||||||
|
8,
|
||||||
|
spark.sql(
|
||||||
|
"Select * from temporary where datainfo.inferenceprovenance = 'propagation'")
|
||||||
|
.count());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue