forked from D-Net/dnet-hadoop
[Country Propagation] left out from previous commit
This commit is contained in:
parent
2fbb35ade5
commit
12de9acb0d
|
@ -7,7 +7,6 @@ import static eu.dnetlib.dhp.common.SparkSessionSupport.runWithSparkSession;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.spark.SparkConf;
|
import org.apache.spark.SparkConf;
|
||||||
import org.apache.spark.api.java.function.FilterFunction;
|
import org.apache.spark.api.java.function.FilterFunction;
|
||||||
|
@ -20,6 +19,8 @@ import org.apache.spark.sql.SparkSession;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import eu.dnetlib.dhp.application.ArgumentApplicationParser;
|
import eu.dnetlib.dhp.application.ArgumentApplicationParser;
|
||||||
import eu.dnetlib.dhp.schema.common.ModelConstants;
|
import eu.dnetlib.dhp.schema.common.ModelConstants;
|
||||||
import eu.dnetlib.dhp.schema.oaf.Datasource;
|
import eu.dnetlib.dhp.schema.oaf.Datasource;
|
||||||
|
|
|
@ -80,7 +80,6 @@ public class SparkCountryPropagationJob {
|
||||||
String outputPath,
|
String outputPath,
|
||||||
Class<R> resultClazz) {
|
Class<R> resultClazz) {
|
||||||
|
|
||||||
|
|
||||||
log.info("Reading Graph table from: {}", sourcePath);
|
log.info("Reading Graph table from: {}", sourcePath);
|
||||||
Dataset<R> res = readPath(spark, sourcePath, resultClazz);
|
Dataset<R> res = readPath(spark, sourcePath, resultClazz);
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import eu.dnetlib.dhp.schema.oaf.Publication;
|
|
||||||
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;
|
||||||
|
@ -25,6 +24,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import eu.dnetlib.dhp.schema.oaf.Country;
|
import eu.dnetlib.dhp.schema.oaf.Country;
|
||||||
|
import eu.dnetlib.dhp.schema.oaf.Publication;
|
||||||
import eu.dnetlib.dhp.schema.oaf.Qualifier;
|
import eu.dnetlib.dhp.schema.oaf.Qualifier;
|
||||||
import eu.dnetlib.dhp.schema.oaf.Software;
|
import eu.dnetlib.dhp.schema.oaf.Software;
|
||||||
import scala.Tuple2;
|
import scala.Tuple2;
|
||||||
|
@ -285,41 +285,117 @@ public class CountryPropagationJobTest {
|
||||||
|
|
||||||
Assertions.assertEquals(5, tmp.filter(r -> r.getCountry().size() > 0).count());
|
Assertions.assertEquals(5, tmp.filter(r -> r.getCountry().size() > 0).count());
|
||||||
|
|
||||||
tmp.foreach(r -> r.getCountry().stream().forEach(c -> Assertions.assertEquals("dnet:countries", c.getSchemeid())));
|
tmp
|
||||||
tmp.foreach(r -> r.getCountry().stream().forEach(c -> Assertions.assertEquals("dnet:countries", c.getSchemename())));
|
.foreach(
|
||||||
tmp.foreach(r -> r.getCountry().stream().forEach(c -> Assertions.assertFalse(c.getDataInfo().getDeletedbyinference())));
|
r -> r.getCountry().stream().forEach(c -> Assertions.assertEquals("dnet:countries", c.getSchemeid())));
|
||||||
|
tmp
|
||||||
|
.foreach(
|
||||||
|
r -> r
|
||||||
|
.getCountry()
|
||||||
|
.stream()
|
||||||
|
.forEach(c -> Assertions.assertEquals("dnet:countries", c.getSchemename())));
|
||||||
|
tmp
|
||||||
|
.foreach(
|
||||||
|
r -> r
|
||||||
|
.getCountry()
|
||||||
|
.stream()
|
||||||
|
.forEach(c -> Assertions.assertFalse(c.getDataInfo().getDeletedbyinference())));
|
||||||
tmp.foreach(r -> r.getCountry().stream().forEach(c -> Assertions.assertFalse(c.getDataInfo().getInvisible())));
|
tmp.foreach(r -> r.getCountry().stream().forEach(c -> Assertions.assertFalse(c.getDataInfo().getInvisible())));
|
||||||
tmp.foreach(r -> r.getCountry().stream().forEach(c -> Assertions.assertTrue(c.getDataInfo().getInferred())));
|
tmp.foreach(r -> r.getCountry().stream().forEach(c -> Assertions.assertTrue(c.getDataInfo().getInferred())));
|
||||||
tmp.foreach(r -> r.getCountry().stream().forEach(c -> Assertions.assertEquals("0.85", c.getDataInfo().getTrust())));
|
tmp
|
||||||
tmp.foreach(r -> r.getCountry().stream().forEach(c -> Assertions.assertEquals("propagation", c.getDataInfo().getInferenceprovenance())));
|
.foreach(
|
||||||
tmp.foreach(r -> r.getCountry().stream().forEach(c -> Assertions.assertEquals("country:instrepos", c.getDataInfo().getProvenanceaction().getClassid())));
|
r -> r.getCountry().stream().forEach(c -> Assertions.assertEquals("0.85", c.getDataInfo().getTrust())));
|
||||||
tmp.foreach(r -> r.getCountry().stream().forEach(c -> Assertions.assertEquals("dnet:provenanceActions", c.getDataInfo().getProvenanceaction().getSchemeid())));
|
tmp
|
||||||
tmp.foreach(r -> r.getCountry().stream().forEach(c -> Assertions.assertEquals("dnet:provenanceActions", c.getDataInfo().getProvenanceaction().getSchemename())));
|
.foreach(
|
||||||
|
r -> r
|
||||||
|
.getCountry()
|
||||||
|
.stream()
|
||||||
|
.forEach(c -> Assertions.assertEquals("propagation", c.getDataInfo().getInferenceprovenance())));
|
||||||
|
tmp
|
||||||
|
.foreach(
|
||||||
|
r -> r
|
||||||
|
.getCountry()
|
||||||
|
.stream()
|
||||||
|
.forEach(
|
||||||
|
c -> Assertions
|
||||||
|
.assertEquals("country:instrepos", c.getDataInfo().getProvenanceaction().getClassid())));
|
||||||
|
tmp
|
||||||
|
.foreach(
|
||||||
|
r -> r
|
||||||
|
.getCountry()
|
||||||
|
.stream()
|
||||||
|
.forEach(
|
||||||
|
c -> Assertions
|
||||||
|
.assertEquals(
|
||||||
|
"dnet:provenanceActions", c.getDataInfo().getProvenanceaction().getSchemeid())));
|
||||||
|
tmp
|
||||||
|
.foreach(
|
||||||
|
r -> r
|
||||||
|
.getCountry()
|
||||||
|
.stream()
|
||||||
|
.forEach(
|
||||||
|
c -> Assertions
|
||||||
|
.assertEquals(
|
||||||
|
"dnet:provenanceActions", c.getDataInfo().getProvenanceaction().getSchemename())));
|
||||||
|
|
||||||
List<Country> countries = tmp.filter(r -> r.getId().equals("50|06cdd3ff4700::49ec404cee4e1452808aabeaffbd3072")).collect().get(0).getCountry();
|
List<Country> countries = tmp
|
||||||
|
.filter(r -> r.getId().equals("50|06cdd3ff4700::49ec404cee4e1452808aabeaffbd3072"))
|
||||||
|
.collect()
|
||||||
|
.get(0)
|
||||||
|
.getCountry();
|
||||||
Assertions.assertEquals(1, countries.size());
|
Assertions.assertEquals(1, countries.size());
|
||||||
Assertions.assertEquals("NL", countries.get(0).getClassid());
|
Assertions.assertEquals("NL", countries.get(0).getClassid());
|
||||||
Assertions.assertEquals("Netherlands", countries.get(0).getClassname());
|
Assertions.assertEquals("Netherlands", countries.get(0).getClassname());
|
||||||
|
|
||||||
countries = tmp.filter(r -> r.getId().equals("50|07b5c0ccd4fe::e7f5459cc97865f2af6e3da964c1250b")).collect().get(0).getCountry();
|
countries = tmp
|
||||||
|
.filter(r -> r.getId().equals("50|07b5c0ccd4fe::e7f5459cc97865f2af6e3da964c1250b"))
|
||||||
|
.collect()
|
||||||
|
.get(0)
|
||||||
|
.getCountry();
|
||||||
Assertions.assertEquals(1, countries.size());
|
Assertions.assertEquals(1, countries.size());
|
||||||
Assertions.assertEquals("NL", countries.get(0).getClassid());
|
Assertions.assertEquals("NL", countries.get(0).getClassid());
|
||||||
Assertions.assertEquals("Netherlands", countries.get(0).getClassname());
|
Assertions.assertEquals("Netherlands", countries.get(0).getClassname());
|
||||||
|
|
||||||
countries = tmp.filter(r -> r.getId().equals("50|355e65625b88::e7d48a470b13bda61f7ebe3513e20cb6")).collect().get(0).getCountry();
|
countries = tmp
|
||||||
|
.filter(r -> r.getId().equals("50|355e65625b88::e7d48a470b13bda61f7ebe3513e20cb6"))
|
||||||
|
.collect()
|
||||||
|
.get(0)
|
||||||
|
.getCountry();
|
||||||
Assertions.assertEquals(2, countries.size());
|
Assertions.assertEquals(2, countries.size());
|
||||||
Assertions.assertTrue(countries.stream().anyMatch(cs -> cs.getClassid().equals("IT") && cs.getClassname().equals("Italy")));
|
Assertions
|
||||||
Assertions.assertTrue(countries.stream().anyMatch(cs -> cs.getClassid().equals("FR") && cs.getClassname().equals("France")));
|
.assertTrue(
|
||||||
|
countries.stream().anyMatch(cs -> cs.getClassid().equals("IT") && cs.getClassname().equals("Italy")));
|
||||||
|
Assertions
|
||||||
|
.assertTrue(
|
||||||
|
countries.stream().anyMatch(cs -> cs.getClassid().equals("FR") && cs.getClassname().equals("France")));
|
||||||
|
|
||||||
countries = tmp.filter(r -> r.getId().equals("50|355e65625b88::74009c567c81b4aa55c813db658734df")).collect().get(0).getCountry();
|
countries = tmp
|
||||||
|
.filter(r -> r.getId().equals("50|355e65625b88::74009c567c81b4aa55c813db658734df"))
|
||||||
|
.collect()
|
||||||
|
.get(0)
|
||||||
|
.getCountry();
|
||||||
Assertions.assertEquals(2, countries.size());
|
Assertions.assertEquals(2, countries.size());
|
||||||
Assertions.assertTrue(countries.stream().anyMatch(cs -> cs.getClassid().equals("IT") && cs.getClassname().equals("Italy")));
|
Assertions
|
||||||
Assertions.assertTrue(countries.stream().anyMatch(cs -> cs.getClassid().equals("NL") && cs.getClassname().equals("Netherlands")));
|
.assertTrue(
|
||||||
|
countries.stream().anyMatch(cs -> cs.getClassid().equals("IT") && cs.getClassname().equals("Italy")));
|
||||||
|
Assertions
|
||||||
|
.assertTrue(
|
||||||
|
countries
|
||||||
|
.stream()
|
||||||
|
.anyMatch(cs -> cs.getClassid().equals("NL") && cs.getClassname().equals("Netherlands")));
|
||||||
|
|
||||||
countries = tmp.filter(r -> r.getId().equals("50|355e65625b88::54a1c76f520bb2c8da27d12e42891088")).collect().get(0).getCountry();
|
countries = tmp
|
||||||
|
.filter(r -> r.getId().equals("50|355e65625b88::54a1c76f520bb2c8da27d12e42891088"))
|
||||||
|
.collect()
|
||||||
|
.get(0)
|
||||||
|
.getCountry();
|
||||||
Assertions.assertEquals(2, countries.size());
|
Assertions.assertEquals(2, countries.size());
|
||||||
Assertions.assertTrue(countries.stream().anyMatch(cs -> cs.getClassid().equals("IT") && cs.getClassname().equals("Italy")));
|
Assertions
|
||||||
Assertions.assertTrue(countries.stream().anyMatch(cs -> cs.getClassid().equals("FR") && cs.getClassname().equals("France")));
|
.assertTrue(
|
||||||
|
countries.stream().anyMatch(cs -> cs.getClassid().equals("IT") && cs.getClassname().equals("Italy")));
|
||||||
|
Assertions
|
||||||
|
.assertTrue(
|
||||||
|
countries.stream().anyMatch(cs -> cs.getClassid().equals("FR") && cs.getClassname().equals("France")));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,21 @@
|
||||||
|
|
||||||
package eu.dnetlib.dhp.countrypropagation;
|
package eu.dnetlib.dhp.countrypropagation;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
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;
|
||||||
import org.apache.spark.api.java.JavaSparkContext;
|
import org.apache.spark.api.java.JavaSparkContext;
|
||||||
|
|
||||||
import org.apache.spark.sql.SparkSession;
|
import org.apache.spark.sql.SparkSession;
|
||||||
import org.junit.jupiter.api.AfterAll;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
|
|
||||||
public class DatasourceCountryPreparationTest {
|
public class DatasourceCountryPreparationTest {
|
||||||
|
|
||||||
|
@ -67,7 +65,8 @@ public class DatasourceCountryPreparationTest {
|
||||||
"--sourcePath", sourcePath,
|
"--sourcePath", sourcePath,
|
||||||
"--outputPath", workingDir.toString() + "/datasourceCountry",
|
"--outputPath", workingDir.toString() + "/datasourceCountry",
|
||||||
"--allowedtypes", "pubsrepository::institutional",
|
"--allowedtypes", "pubsrepository::institutional",
|
||||||
"--whitelist","10|openaire____::3795d6478e30e2c9f787d427ff160944;10|opendoar____::16e6a3326dd7d868cbc926602a61e4d0;10|eurocrisdris::fe4903425d9040f680d8610d9079ea14;10|openaire____::5b76240cc27a58c6f7ceef7d8c36660e;10|openaire____::172bbccecf8fca44ab6a6653e84cb92a;10|openaire____::149c6590f8a06b46314eed77bfca693f;10|eurocrisdris::a6026877c1a174d60f81fd71f62df1c1;10|openaire____::4692342f0992d91f9e705c26959f09e0;10|openaire____::8d529dbb05ec0284662b391789e8ae2a;10|openaire____::345c9d171ef3c5d706d08041d506428c;10|opendoar____::1c1d4df596d01da60385f0bb17a4a9e0;10|opendoar____::7a614fd06c325499f1680b9896beedeb;10|opendoar____::1ee3dfcd8a0645a25a35977997223d22;10|opendoar____::d296c101daa88a51f6ca8cfc1ac79b50;10|opendoar____::798ed7d4ee7138d49b8828958048130a;10|openaire____::c9d2209ecc4d45ba7b4ca7597acb88a2;10|eurocrisdris::c49e0fe4b9ba7b7fab717d1f0f0a674d;10|eurocrisdris::9ae43d14471c4b33661fedda6f06b539;10|eurocrisdris::432ca599953ff50cd4eeffe22faf3e48"
|
"--whitelist",
|
||||||
|
"10|openaire____::3795d6478e30e2c9f787d427ff160944;10|opendoar____::16e6a3326dd7d868cbc926602a61e4d0;10|eurocrisdris::fe4903425d9040f680d8610d9079ea14;10|openaire____::5b76240cc27a58c6f7ceef7d8c36660e;10|openaire____::172bbccecf8fca44ab6a6653e84cb92a;10|openaire____::149c6590f8a06b46314eed77bfca693f;10|eurocrisdris::a6026877c1a174d60f81fd71f62df1c1;10|openaire____::4692342f0992d91f9e705c26959f09e0;10|openaire____::8d529dbb05ec0284662b391789e8ae2a;10|openaire____::345c9d171ef3c5d706d08041d506428c;10|opendoar____::1c1d4df596d01da60385f0bb17a4a9e0;10|opendoar____::7a614fd06c325499f1680b9896beedeb;10|opendoar____::1ee3dfcd8a0645a25a35977997223d22;10|opendoar____::d296c101daa88a51f6ca8cfc1ac79b50;10|opendoar____::798ed7d4ee7138d49b8828958048130a;10|openaire____::c9d2209ecc4d45ba7b4ca7597acb88a2;10|eurocrisdris::c49e0fe4b9ba7b7fab717d1f0f0a674d;10|eurocrisdris::9ae43d14471c4b33661fedda6f06b539;10|eurocrisdris::432ca599953ff50cd4eeffe22faf3e48"
|
||||||
});
|
});
|
||||||
|
|
||||||
final JavaSparkContext sc = JavaSparkContext.fromSparkContext(spark.sparkContext());
|
final JavaSparkContext sc = JavaSparkContext.fromSparkContext(spark.sparkContext());
|
||||||
|
@ -77,33 +76,99 @@ public class DatasourceCountryPreparationTest {
|
||||||
.map(item -> OBJECT_MAPPER.readValue(item, DatasourceCountry.class));
|
.map(item -> OBJECT_MAPPER.readValue(item, DatasourceCountry.class));
|
||||||
|
|
||||||
Assertions.assertEquals(3, tmp.count());
|
Assertions.assertEquals(3, tmp.count());
|
||||||
Assertions.assertEquals(1, tmp.filter(dsc -> dsc.getDataSourceId()
|
Assertions
|
||||||
.equals("10|eurocrisdris::fe4903425d9040f680d8610d9079ea14")).count());
|
.assertEquals(
|
||||||
Assertions.assertEquals(1, tmp.filter(dsc -> dsc.getDataSourceId()
|
1, tmp
|
||||||
.equals("10|opendoar____::f0dd4a99fba6075a9494772b58f95280")).count());
|
.filter(
|
||||||
Assertions.assertEquals(1, tmp.filter(dsc -> dsc.getDataSourceId()
|
dsc -> dsc
|
||||||
.equals("10|eurocrisdris::9ae43d14471c4b33661fedda6f06b539")).count());
|
.getDataSourceId()
|
||||||
|
.equals("10|eurocrisdris::fe4903425d9040f680d8610d9079ea14"))
|
||||||
|
.count());
|
||||||
|
Assertions
|
||||||
|
.assertEquals(
|
||||||
|
1, tmp
|
||||||
|
.filter(
|
||||||
|
dsc -> dsc
|
||||||
|
.getDataSourceId()
|
||||||
|
.equals("10|opendoar____::f0dd4a99fba6075a9494772b58f95280"))
|
||||||
|
.count());
|
||||||
|
Assertions
|
||||||
|
.assertEquals(
|
||||||
|
1, tmp
|
||||||
|
.filter(
|
||||||
|
dsc -> dsc
|
||||||
|
.getDataSourceId()
|
||||||
|
.equals("10|eurocrisdris::9ae43d14471c4b33661fedda6f06b539"))
|
||||||
|
.count());
|
||||||
|
|
||||||
Assertions.assertEquals("NL", tmp.filter(dsc -> dsc.getDataSourceId()
|
Assertions
|
||||||
.equals("10|eurocrisdris::fe4903425d9040f680d8610d9079ea14")).collect()
|
.assertEquals(
|
||||||
.get(0).getCountry().getClassid());
|
"NL", tmp
|
||||||
Assertions.assertEquals("Netherlands", tmp.filter(dsc -> dsc.getDataSourceId()
|
.filter(
|
||||||
.equals("10|eurocrisdris::fe4903425d9040f680d8610d9079ea14")).collect()
|
dsc -> dsc
|
||||||
.get(0).getCountry().getClassname());
|
.getDataSourceId()
|
||||||
|
.equals("10|eurocrisdris::fe4903425d9040f680d8610d9079ea14"))
|
||||||
|
.collect()
|
||||||
|
.get(0)
|
||||||
|
.getCountry()
|
||||||
|
.getClassid());
|
||||||
|
Assertions
|
||||||
|
.assertEquals(
|
||||||
|
"Netherlands", tmp
|
||||||
|
.filter(
|
||||||
|
dsc -> dsc
|
||||||
|
.getDataSourceId()
|
||||||
|
.equals("10|eurocrisdris::fe4903425d9040f680d8610d9079ea14"))
|
||||||
|
.collect()
|
||||||
|
.get(0)
|
||||||
|
.getCountry()
|
||||||
|
.getClassname());
|
||||||
|
|
||||||
Assertions.assertEquals("IT", tmp.filter(dsc -> dsc.getDataSourceId()
|
Assertions
|
||||||
.equals("10|opendoar____::f0dd4a99fba6075a9494772b58f95280")).collect()
|
.assertEquals(
|
||||||
.get(0).getCountry().getClassid());
|
"IT", tmp
|
||||||
Assertions.assertEquals("Italy", tmp.filter(dsc -> dsc.getDataSourceId()
|
.filter(
|
||||||
.equals("10|opendoar____::f0dd4a99fba6075a9494772b58f95280")).collect()
|
dsc -> dsc
|
||||||
.get(0).getCountry().getClassname());
|
.getDataSourceId()
|
||||||
|
.equals("10|opendoar____::f0dd4a99fba6075a9494772b58f95280"))
|
||||||
|
.collect()
|
||||||
|
.get(0)
|
||||||
|
.getCountry()
|
||||||
|
.getClassid());
|
||||||
|
Assertions
|
||||||
|
.assertEquals(
|
||||||
|
"Italy", tmp
|
||||||
|
.filter(
|
||||||
|
dsc -> dsc
|
||||||
|
.getDataSourceId()
|
||||||
|
.equals("10|opendoar____::f0dd4a99fba6075a9494772b58f95280"))
|
||||||
|
.collect()
|
||||||
|
.get(0)
|
||||||
|
.getCountry()
|
||||||
|
.getClassname());
|
||||||
|
|
||||||
Assertions.assertEquals("FR", tmp.filter(dsc -> dsc.getDataSourceId()
|
Assertions
|
||||||
.equals("10|eurocrisdris::9ae43d14471c4b33661fedda6f06b539")).collect()
|
.assertEquals(
|
||||||
.get(0).getCountry().getClassid());
|
"FR", tmp
|
||||||
Assertions.assertEquals("France", tmp.filter(dsc -> dsc.getDataSourceId()
|
.filter(
|
||||||
.equals("10|eurocrisdris::9ae43d14471c4b33661fedda6f06b539")).collect()
|
dsc -> dsc
|
||||||
.get(0).getCountry().getClassname());
|
.getDataSourceId()
|
||||||
|
.equals("10|eurocrisdris::9ae43d14471c4b33661fedda6f06b539"))
|
||||||
|
.collect()
|
||||||
|
.get(0)
|
||||||
|
.getCountry()
|
||||||
|
.getClassid());
|
||||||
|
Assertions
|
||||||
|
.assertEquals(
|
||||||
|
"France", tmp
|
||||||
|
.filter(
|
||||||
|
dsc -> dsc
|
||||||
|
.getDataSourceId()
|
||||||
|
.equals("10|eurocrisdris::9ae43d14471c4b33661fedda6f06b539"))
|
||||||
|
.collect()
|
||||||
|
.get(0)
|
||||||
|
.getCountry()
|
||||||
|
.getClassname());
|
||||||
|
|
||||||
tmp.foreach(e -> System.out.println(OBJECT_MAPPER.writeValueAsString(e)));
|
tmp.foreach(e -> System.out.println(OBJECT_MAPPER.writeValueAsString(e)));
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
|
|
||||||
package eu.dnetlib.dhp.countrypropagation;
|
package eu.dnetlib.dhp.countrypropagation;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import static eu.dnetlib.dhp.PropagationConstant.isSparkSessionManaged;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import eu.dnetlib.dhp.schema.oaf.Publication;
|
|
||||||
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;
|
||||||
|
@ -13,11 +17,9 @@ import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
import static eu.dnetlib.dhp.PropagationConstant.isSparkSessionManaged;
|
import eu.dnetlib.dhp.schema.oaf.Publication;
|
||||||
|
|
||||||
public class ResultCountryPreparationTest {
|
public class ResultCountryPreparationTest {
|
||||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||||
|
@ -63,7 +65,6 @@ public class ResultCountryPreparationTest {
|
||||||
.getResource("/eu/dnetlib/dhp/countrypropagation/datasourcecountry")
|
.getResource("/eu/dnetlib/dhp/countrypropagation/datasourcecountry")
|
||||||
.getPath();
|
.getPath();
|
||||||
|
|
||||||
|
|
||||||
PrepareResultCountrySet
|
PrepareResultCountrySet
|
||||||
.main(
|
.main(
|
||||||
new String[] {
|
new String[] {
|
||||||
|
@ -81,35 +82,77 @@ public class ResultCountryPreparationTest {
|
||||||
.textFile(workingDir.toString() + "/resultCountry")
|
.textFile(workingDir.toString() + "/resultCountry")
|
||||||
.map(item -> OBJECT_MAPPER.readValue(item, ResultCountrySet.class));
|
.map(item -> OBJECT_MAPPER.readValue(item, ResultCountrySet.class));
|
||||||
|
|
||||||
|
|
||||||
Assertions.assertEquals(5, tmp.count());
|
Assertions.assertEquals(5, tmp.count());
|
||||||
|
|
||||||
ResultCountrySet rc = tmp.filter(r -> r.getResultId().equals("50|06cdd3ff4700::49ec404cee4e1452808aabeaffbd3072")).collect().get(0);
|
ResultCountrySet rc = tmp
|
||||||
|
.filter(r -> r.getResultId().equals("50|06cdd3ff4700::49ec404cee4e1452808aabeaffbd3072"))
|
||||||
|
.collect()
|
||||||
|
.get(0);
|
||||||
Assertions.assertEquals(1, rc.getCountrySet().size());
|
Assertions.assertEquals(1, rc.getCountrySet().size());
|
||||||
Assertions.assertEquals("NL", rc.getCountrySet().get(0).getClassid());
|
Assertions.assertEquals("NL", rc.getCountrySet().get(0).getClassid());
|
||||||
Assertions.assertEquals("Netherlands", rc.getCountrySet().get(0).getClassname());
|
Assertions.assertEquals("Netherlands", rc.getCountrySet().get(0).getClassname());
|
||||||
|
|
||||||
rc = tmp.filter(r -> r.getResultId().equals("50|07b5c0ccd4fe::e7f5459cc97865f2af6e3da964c1250b")).collect().get(0);
|
rc = tmp
|
||||||
|
.filter(r -> r.getResultId().equals("50|07b5c0ccd4fe::e7f5459cc97865f2af6e3da964c1250b"))
|
||||||
|
.collect()
|
||||||
|
.get(0);
|
||||||
Assertions.assertEquals(1, rc.getCountrySet().size());
|
Assertions.assertEquals(1, rc.getCountrySet().size());
|
||||||
Assertions.assertEquals("NL", rc.getCountrySet().get(0).getClassid());
|
Assertions.assertEquals("NL", rc.getCountrySet().get(0).getClassid());
|
||||||
Assertions.assertEquals("Netherlands", rc.getCountrySet().get(0).getClassname());
|
Assertions.assertEquals("Netherlands", rc.getCountrySet().get(0).getClassname());
|
||||||
|
|
||||||
rc = tmp.filter(r -> r.getResultId().equals("50|355e65625b88::e7d48a470b13bda61f7ebe3513e20cb6")).collect().get(0);
|
rc = tmp
|
||||||
|
.filter(r -> r.getResultId().equals("50|355e65625b88::e7d48a470b13bda61f7ebe3513e20cb6"))
|
||||||
|
.collect()
|
||||||
|
.get(0);
|
||||||
Assertions.assertEquals(2, rc.getCountrySet().size());
|
Assertions.assertEquals(2, rc.getCountrySet().size());
|
||||||
Assertions.assertTrue(rc.getCountrySet().stream().anyMatch(cs -> cs.getClassid().equals("IT") && cs.getClassname().equals("Italy")));
|
Assertions
|
||||||
Assertions.assertTrue(rc.getCountrySet().stream().anyMatch(cs -> cs.getClassid().equals("FR") && cs.getClassname().equals("France")));
|
.assertTrue(
|
||||||
|
rc
|
||||||
|
.getCountrySet()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(cs -> cs.getClassid().equals("IT") && cs.getClassname().equals("Italy")));
|
||||||
|
Assertions
|
||||||
|
.assertTrue(
|
||||||
|
rc
|
||||||
|
.getCountrySet()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(cs -> cs.getClassid().equals("FR") && cs.getClassname().equals("France")));
|
||||||
|
|
||||||
rc = tmp.filter(r -> r.getResultId().equals("50|355e65625b88::74009c567c81b4aa55c813db658734df")).collect().get(0);
|
rc = tmp
|
||||||
|
.filter(r -> r.getResultId().equals("50|355e65625b88::74009c567c81b4aa55c813db658734df"))
|
||||||
|
.collect()
|
||||||
|
.get(0);
|
||||||
Assertions.assertEquals(2, rc.getCountrySet().size());
|
Assertions.assertEquals(2, rc.getCountrySet().size());
|
||||||
Assertions.assertTrue(rc.getCountrySet().stream().anyMatch(cs -> cs.getClassid().equals("IT") && cs.getClassname().equals("Italy")));
|
Assertions
|
||||||
Assertions.assertTrue(rc.getCountrySet().stream().anyMatch(cs -> cs.getClassid().equals("NL") && cs.getClassname().equals("Netherlands")));
|
.assertTrue(
|
||||||
|
rc
|
||||||
|
.getCountrySet()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(cs -> cs.getClassid().equals("IT") && cs.getClassname().equals("Italy")));
|
||||||
|
Assertions
|
||||||
|
.assertTrue(
|
||||||
|
rc
|
||||||
|
.getCountrySet()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(cs -> cs.getClassid().equals("NL") && cs.getClassname().equals("Netherlands")));
|
||||||
|
|
||||||
|
rc = tmp
|
||||||
rc = tmp.filter(r -> r.getResultId().equals("50|355e65625b88::54a1c76f520bb2c8da27d12e42891088")).collect().get(0);
|
.filter(r -> r.getResultId().equals("50|355e65625b88::54a1c76f520bb2c8da27d12e42891088"))
|
||||||
|
.collect()
|
||||||
|
.get(0);
|
||||||
Assertions.assertEquals(2, rc.getCountrySet().size());
|
Assertions.assertEquals(2, rc.getCountrySet().size());
|
||||||
Assertions.assertTrue(rc.getCountrySet().stream().anyMatch(cs -> cs.getClassid().equals("IT") && cs.getClassname().equals("Italy")));
|
Assertions
|
||||||
Assertions.assertTrue(rc.getCountrySet().stream().anyMatch(cs -> cs.getClassid().equals("FR") && cs.getClassname().equals("France")));
|
.assertTrue(
|
||||||
|
rc
|
||||||
|
.getCountrySet()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(cs -> cs.getClassid().equals("IT") && cs.getClassname().equals("Italy")));
|
||||||
|
Assertions
|
||||||
|
.assertTrue(
|
||||||
|
rc
|
||||||
|
.getCountrySet()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(cs -> cs.getClassid().equals("FR") && cs.getClassname().equals("France")));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue