2020-05-22 15:15:09 +02:00
|
|
|
package eu.dnetlib.doiboost.uw
|
|
|
|
|
|
|
|
import eu.dnetlib.dhp.application.ArgumentApplicationParser
|
|
|
|
import eu.dnetlib.dhp.schema.oaf.Publication
|
|
|
|
import eu.dnetlib.doiboost.crossref.SparkMapDumpIntoOAF
|
|
|
|
import org.apache.commons.io.IOUtils
|
|
|
|
import org.apache.spark.SparkConf
|
|
|
|
import org.apache.spark.rdd.RDD
|
2021-12-06 14:24:03 +01:00
|
|
|
import org.apache.spark.sql._
|
2020-05-22 15:15:09 +02:00
|
|
|
import org.slf4j.{Logger, LoggerFactory}
|
|
|
|
|
|
|
|
object SparkMapUnpayWallToOAF {
|
|
|
|
|
|
|
|
def main(args: Array[String]): Unit = {
|
|
|
|
|
|
|
|
|
|
|
|
val logger: Logger = LoggerFactory.getLogger(SparkMapDumpIntoOAF.getClass)
|
|
|
|
val conf: SparkConf = new SparkConf()
|
2021-07-14 09:44:32 +02:00
|
|
|
val parser = new ArgumentApplicationParser(IOUtils.toString(SparkMapDumpIntoOAF.getClass.getResourceAsStream("/eu/dnetlib/dhp/doiboost/convert_uw_to_oaf_params.json")))
|
2020-05-22 15:15:09 +02:00
|
|
|
parser.parseArgument(args)
|
|
|
|
val spark: SparkSession =
|
|
|
|
SparkSession
|
|
|
|
.builder()
|
|
|
|
.config(conf)
|
|
|
|
.appName(getClass.getSimpleName)
|
|
|
|
.master(parser.get("master")).getOrCreate()
|
|
|
|
|
2020-06-04 14:39:20 +02:00
|
|
|
implicit val mapEncoderPubs: Encoder[Publication] = Encoders.kryo[Publication]
|
2020-05-22 15:15:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
val sourcePath = parser.get("sourcePath")
|
|
|
|
val targetPath = parser.get("targetPath")
|
2021-12-06 14:24:03 +01:00
|
|
|
val inputRDD: RDD[String] = spark.sparkContext.textFile(s"$sourcePath")
|
2020-05-22 15:15:09 +02:00
|
|
|
|
|
|
|
logger.info("Converting UnpayWall to OAF")
|
2020-06-04 14:39:20 +02:00
|
|
|
|
2021-12-06 14:24:03 +01:00
|
|
|
val d: Dataset[Publication] = spark.createDataset(inputRDD.map(UnpayWallToOAF.convertToOAF).filter(p => p != null)).as[Publication]
|
2020-05-22 15:15:09 +02:00
|
|
|
d.write.mode(SaveMode.Overwrite).save(targetPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|