77 lines
2.9 KiB
Scala
77 lines
2.9 KiB
Scala
package eu.dnetlib.dhp.sx.bio.ebi
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper
|
|
import eu.dnetlib.dhp.application.AbstractScalaApplication
|
|
import eu.dnetlib.dhp.collection.CollectionUtils
|
|
import eu.dnetlib.dhp.common.Constants.MDSTORE_DATA_PATH
|
|
import eu.dnetlib.dhp.common.vocabulary.VocabularyGroup
|
|
import eu.dnetlib.dhp.schema.mdstore.MDStoreVersion
|
|
import eu.dnetlib.dhp.schema.oaf.Oaf
|
|
import eu.dnetlib.dhp.sx.bio.pubmed.{PMArticle, PMAuthor, PMJournal, PubMedToOaf}
|
|
import eu.dnetlib.dhp.utils.ISLookupClientFactory
|
|
import org.apache.spark.sql.{Encoder, Encoders, SparkSession}
|
|
import org.slf4j.{Logger, LoggerFactory}
|
|
|
|
class SparkTransformBaselineToOAF(propertyPath: String, args: Array[String], log: Logger)
|
|
extends AbstractScalaApplication(propertyPath, args, log: Logger) {
|
|
|
|
private def convertBaseLineToOAF(
|
|
spark: SparkSession,
|
|
inputPath: String,
|
|
targetPath: String,
|
|
vocabularies: VocabularyGroup
|
|
): Unit = {
|
|
implicit val resultEncoder: Encoder[Oaf] = Encoders.kryo(classOf[Oaf])
|
|
implicit val PMEncoder: Encoder[PMArticle] = Encoders.kryo(classOf[PMArticle])
|
|
implicit val PMJEncoder: Encoder[PMJournal] = Encoders.kryo(classOf[PMJournal])
|
|
implicit val PMAEncoder: Encoder[PMAuthor] = Encoders.kryo(classOf[PMAuthor])
|
|
val exported_dataset = spark.read.load(inputPath).as[PMArticle]
|
|
CollectionUtils.saveDataset(
|
|
exported_dataset
|
|
.map(a => PubMedToOaf.convert(a, vocabularies))
|
|
.as[Oaf]
|
|
.filter(p => p != null),
|
|
targetPath
|
|
)
|
|
}
|
|
|
|
/** Here all the spark applications runs this method
|
|
* where the whole logic of the spark node is defined
|
|
*/
|
|
override def run(): Unit = {
|
|
val isLookupUrl: String = parser.get("isLookupUrl")
|
|
log.info("isLookupUrl: {}", isLookupUrl)
|
|
|
|
val sourcePath = parser.get("sourcePath")
|
|
log.info("sourcePath: {}", sourcePath)
|
|
|
|
val mdstoreOutputVersion = parser.get("mdstoreOutputVersion")
|
|
log.info(s"mdstoreOutputVersion is '$mdstoreOutputVersion'")
|
|
|
|
val mapper = new ObjectMapper()
|
|
val cleanedMdStoreVersion = mapper.readValue(mdstoreOutputVersion, classOf[MDStoreVersion])
|
|
val outputBasePath = cleanedMdStoreVersion.getHdfsPath
|
|
log.info(s"outputBasePath is '$outputBasePath'")
|
|
|
|
val targetPath = s"$outputBasePath$MDSTORE_DATA_PATH"
|
|
log.info(s"targetPath is '$targetPath'")
|
|
|
|
val isLookupService = ISLookupClientFactory.getLookUpService(isLookupUrl)
|
|
val vocabularies = VocabularyGroup.loadVocsFromIS(isLookupService)
|
|
|
|
convertBaseLineToOAF(spark, sourcePath, targetPath, vocabularies)
|
|
reportTotalSize(targetPath, outputBasePath)
|
|
}
|
|
}
|
|
|
|
object SparkTransformBaselineToOAF {
|
|
|
|
val log: Logger = LoggerFactory.getLogger(SparkTransformBaselineToOAF.getClass)
|
|
|
|
def main(args: Array[String]): Unit = {
|
|
new SparkTransformBaselineToOAF("/eu/dnetlib/dhp/sx/bio/ebi/pubmed_to_oaf_params.json", args, log)
|
|
.initialize()
|
|
.run()
|
|
}
|
|
}
|