2020-03-27 10:42:17 +01:00
|
|
|
package eu.dnetlib.dhp.oa.dedup;
|
2019-12-06 13:38:00 +01:00
|
|
|
|
|
|
|
import eu.dnetlib.dhp.application.ArgumentApplicationParser;
|
2019-12-11 15:43:24 +01:00
|
|
|
import eu.dnetlib.dhp.schema.oaf.OafEntity;
|
2020-04-06 16:30:31 +02:00
|
|
|
import eu.dnetlib.dhp.utils.ISLookupClientFactory;
|
2020-03-20 13:01:56 +01:00
|
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
2020-04-06 16:30:31 +02:00
|
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
2019-12-06 13:38:00 +01:00
|
|
|
import eu.dnetlib.pace.config.DedupConfig;
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import org.apache.spark.api.java.JavaRDD;
|
|
|
|
import org.apache.spark.api.java.JavaSparkContext;
|
|
|
|
import org.apache.spark.sql.SparkSession;
|
2020-03-20 13:01:56 +01:00
|
|
|
import org.dom4j.DocumentException;
|
2020-04-16 12:36:37 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2019-12-06 13:38:00 +01:00
|
|
|
|
2020-04-06 16:30:31 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
public class SparkCreateDedupRecord extends AbstractSparkAction {
|
|
|
|
|
2020-04-16 12:36:37 +02:00
|
|
|
private static final Logger log = LoggerFactory.getLogger(SparkCreateDedupRecord.class);
|
2020-04-06 16:30:31 +02:00
|
|
|
|
2020-04-16 12:36:37 +02:00
|
|
|
public SparkCreateDedupRecord(ArgumentApplicationParser parser, SparkSession spark) {
|
2020-04-06 16:30:31 +02:00
|
|
|
super(parser, spark);
|
|
|
|
}
|
2019-12-06 13:38:00 +01:00
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
2020-04-06 16:30:31 +02:00
|
|
|
ArgumentApplicationParser parser = new ArgumentApplicationParser(
|
2020-03-27 10:42:17 +01:00
|
|
|
IOUtils.toString(
|
2020-04-06 16:30:31 +02:00
|
|
|
SparkCreateSimRels.class.getResourceAsStream("/eu/dnetlib/dhp/oa/dedup/createDedupRecord_parameters.json")));
|
2019-12-11 15:43:24 +01:00
|
|
|
parser.parseArgument(args);
|
|
|
|
|
2020-04-15 16:34:06 +02:00
|
|
|
new SparkCreateDedupRecord(parser, getSparkSession(parser)).run(ISLookupClientFactory.getLookUpService(parser.get("isLookUpUrl")));
|
2020-03-20 13:01:56 +01:00
|
|
|
}
|
|
|
|
|
2020-04-06 16:30:31 +02:00
|
|
|
@Override
|
|
|
|
public void run(ISLookUpService isLookUpService) throws ISLookUpException, DocumentException, IOException {
|
2020-03-20 13:01:56 +01:00
|
|
|
|
|
|
|
final String graphBasePath = parser.get("graphBasePath");
|
|
|
|
final String isLookUpUrl = parser.get("isLookUpUrl");
|
|
|
|
final String actionSetId = parser.get("actionSetId");
|
|
|
|
final String workingPath = parser.get("workingPath");
|
2019-12-11 15:43:24 +01:00
|
|
|
|
2020-04-17 13:12:44 +02:00
|
|
|
log.info("graphBasePath: '{}'", graphBasePath);
|
|
|
|
log.info("isLookUpUrl: '{}'", isLookUpUrl);
|
|
|
|
log.info("actionSetId: '{}'", actionSetId);
|
|
|
|
log.info("workingPath: '{}'", workingPath);
|
2020-04-15 16:34:06 +02:00
|
|
|
|
2020-04-06 16:30:31 +02:00
|
|
|
final JavaSparkContext sc = new JavaSparkContext(spark.sparkContext());
|
2019-12-06 13:38:00 +01:00
|
|
|
|
2020-04-06 16:30:31 +02:00
|
|
|
for (DedupConfig dedupConf: getConfigurations(isLookUpService, actionSetId)) {
|
|
|
|
String subEntity = dedupConf.getWf().getSubEntityValue();
|
2020-04-17 13:12:44 +02:00
|
|
|
log.info("Creating deduprecords for: '{}'", subEntity);
|
|
|
|
|
|
|
|
final String outputPath = DedupUtility.createDedupRecordPath(workingPath, actionSetId, subEntity);
|
|
|
|
removeOutputDir(spark, outputPath);
|
2019-12-06 13:38:00 +01:00
|
|
|
|
2020-04-06 16:30:31 +02:00
|
|
|
final String mergeRelPath = DedupUtility.createMergeRelPath(workingPath, actionSetId, subEntity);
|
|
|
|
final String entityPath = DedupUtility.createEntityPath(graphBasePath, subEntity);
|
|
|
|
final OafEntityType entityType = OafEntityType.valueOf(subEntity);
|
|
|
|
final JavaRDD<OafEntity> dedupRecord =
|
|
|
|
DedupRecordFactory.createDedupRecord(sc, spark, mergeRelPath, entityPath, entityType, dedupConf);
|
2020-04-17 13:12:44 +02:00
|
|
|
|
|
|
|
dedupRecord.map(r -> OBJECT_MAPPER.writeValueAsString(r)).saveAsTextFile(outputPath);
|
2020-03-20 13:01:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-06 16:30:31 +02:00
|
|
|
}
|