forked from D-Net/dnet-hadoop
Added citation relation on crossref Mapping
This commit is contained in:
parent
d05ca53a14
commit
a8ac79fa25
|
@ -309,6 +309,8 @@ case object Crossref2Oaf {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def generateAuhtor(given: String, family: String, orcid: String, index: Int): Author = {
|
def generateAuhtor(given: String, family: String, orcid: String, index: Int): Author = {
|
||||||
val a = new Author
|
val a = new Author
|
||||||
a.setName(given)
|
a.setName(given)
|
||||||
|
@ -370,10 +372,57 @@ case object Crossref2Oaf {
|
||||||
case dataset: Dataset => convertDataset(dataset)
|
case dataset: Dataset => convertDataset(dataset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
val doisReference:List[String] = for {
|
||||||
|
JObject(reference_json) <- json \ "reference"
|
||||||
|
JField("DOI", JString(doi_json)) <- reference_json
|
||||||
|
} yield doi_json
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (doisReference!= null && doisReference.nonEmpty) {
|
||||||
|
val citation_relations:List[Relation] = generateCitationRelations(doisReference, result)
|
||||||
|
resultList = resultList ::: citation_relations
|
||||||
|
}
|
||||||
resultList = resultList ::: List(result)
|
resultList = resultList ::: List(result)
|
||||||
resultList
|
resultList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private def createCiteRelation(source:Result, targetPid:String, targetPidType:String) :List[Relation] = {
|
||||||
|
|
||||||
|
|
||||||
|
val targetId = IdentifierFactory.idFromPid("50",targetPidType, targetPid, true)
|
||||||
|
|
||||||
|
val from = new Relation
|
||||||
|
from.setSource(source.getId)
|
||||||
|
from.setTarget(targetId)
|
||||||
|
from.setRelType(ModelConstants.RESULT_RESULT)
|
||||||
|
from.setRelClass(ModelConstants.CITES)
|
||||||
|
from.setSubRelType(ModelConstants.CITATION)
|
||||||
|
from.setCollectedfrom(source.getCollectedfrom)
|
||||||
|
from.setDataInfo(source.getDataInfo)
|
||||||
|
from.setLastupdatetimestamp(source.getLastupdatetimestamp)
|
||||||
|
|
||||||
|
|
||||||
|
val to = new Relation
|
||||||
|
to.setTarget(source.getId)
|
||||||
|
to.setSource(targetId)
|
||||||
|
to.setRelType(ModelConstants.RESULT_RESULT)
|
||||||
|
to.setRelClass(ModelConstants.IS_CITED_BY)
|
||||||
|
to.setSubRelType(ModelConstants.CITATION)
|
||||||
|
to.setCollectedfrom(source.getCollectedfrom)
|
||||||
|
to.setDataInfo(source.getDataInfo)
|
||||||
|
to.setLastupdatetimestamp(source.getLastupdatetimestamp)
|
||||||
|
|
||||||
|
List(from,to)
|
||||||
|
}
|
||||||
|
|
||||||
|
def generateCitationRelations(dois:List[String], result:Result):List[Relation] = {
|
||||||
|
dois.flatMap(d => createCiteRelation(result, d, "doi"))
|
||||||
|
}
|
||||||
|
|
||||||
def mappingFunderToRelations(
|
def mappingFunderToRelations(
|
||||||
funders: List[mappingFunder],
|
funders: List[mappingFunder],
|
||||||
sourceId: String,
|
sourceId: String,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,9 +1,14 @@
|
||||||
package eu.dnetlib.dhp.doiboost.crossref
|
package eu.dnetlib.dhp.doiboost.crossref
|
||||||
|
|
||||||
|
import eu.dnetlib.dhp.schema.common.ModelConstants
|
||||||
import eu.dnetlib.dhp.schema.oaf._
|
import eu.dnetlib.dhp.schema.oaf._
|
||||||
import eu.dnetlib.dhp.utils.DHPUtils
|
import eu.dnetlib.dhp.utils.DHPUtils
|
||||||
import eu.dnetlib.doiboost.crossref.Crossref2Oaf
|
import eu.dnetlib.doiboost.crossref.Crossref2Oaf
|
||||||
import org.codehaus.jackson.map.{ObjectMapper, SerializationConfig}
|
import org.codehaus.jackson.map.{ObjectMapper, SerializationConfig}
|
||||||
|
import org.json4s
|
||||||
|
import org.json4s.JsonAST.{JField, JObject, JString}
|
||||||
|
import org.json4s.{DefaultFormats, JValue}
|
||||||
|
import org.json4s.jackson.JsonMethods
|
||||||
import org.junit.jupiter.api.Assertions._
|
import org.junit.jupiter.api.Assertions._
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.slf4j.{Logger, LoggerFactory}
|
import org.slf4j.{Logger, LoggerFactory}
|
||||||
|
@ -109,6 +114,44 @@ class CrossrefMappingTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private def parseJson(input:String):JValue = {
|
||||||
|
implicit lazy val formats: DefaultFormats.type = org.json4s.DefaultFormats
|
||||||
|
lazy val json: json4s.JValue = JsonMethods.parse(input)
|
||||||
|
|
||||||
|
json
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
def testCitationRelations():Unit = {
|
||||||
|
val json = Source.fromInputStream(getClass.getResourceAsStream("/eu/dnetlib/doiboost/crossref/publication_license_embargo.json")).mkString
|
||||||
|
|
||||||
|
|
||||||
|
assertNotNull(json)
|
||||||
|
assertFalse(json.isEmpty)
|
||||||
|
|
||||||
|
val result:List[Oaf] = Crossref2Oaf.convert(json)
|
||||||
|
|
||||||
|
assertTrue(result.nonEmpty)
|
||||||
|
|
||||||
|
|
||||||
|
val j = parseJson(json)
|
||||||
|
|
||||||
|
val doisReference: List[String] = for {
|
||||||
|
JObject(reference_json) <- j \ "reference"
|
||||||
|
JField("DOI", JString(doi_json)) <- reference_json
|
||||||
|
} yield doi_json
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val relationList:List[Relation] = result.filter(s => s.isInstanceOf[Relation]).map(r=> r.asInstanceOf[Relation]).filter(r => r.getSubRelType.equalsIgnoreCase(ModelConstants.CITATION))
|
||||||
|
|
||||||
|
assertNotNull(relationList)
|
||||||
|
assertFalse(relationList.isEmpty)
|
||||||
|
|
||||||
|
assertEquals(doisReference.size*2, relationList.size)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
def testEmptyTitle(): Unit = {
|
def testEmptyTitle(): Unit = {
|
||||||
val json = Source
|
val json = Source
|
||||||
|
|
Loading…
Reference in New Issue