-
Notifications
You must be signed in to change notification settings - Fork 1
/
Reference.scala
59 lines (48 loc) · 1.91 KB
/
Reference.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package org.comp.bio.aging.extractor
import pl.edu.icm.cermine.bibref.model.BibEntry
import scala.collection.JavaConverters._
object Reference {
def apply(entry: BibEntry): Reference = {
val keys = entry.getFieldKeys.asScala
val fields: Map[String, List[String]] = keys.map(key => key-> entry.getAllFields(key).asScala.map(_.getText).toList).toMap
new Reference(fields)
}
}
/**
* Extracts biblio-reference fields from the Map of values we get from CERMINE
* @param fields
* @param position
*/
class Reference(fields: Map[String, List[String]], position: Int = 0)
{
protected def getHead(name: String) = get(name).flatMap(list=>list.headOption)
protected def get(name: String) = fields.get(name)
lazy val doi: Option[String] = for(value <- getHead("doi"))
yield {
if (value.endsWith(")") && (value.count(_ == ')') > value.count(_ == ')') ) )
value.substring(0, value.length - 1)
else value.substring(0, value.length - 1)
}
lazy val sciHubDoi: Option[String] = for{
value <- doi
} yield s"http://sci-hub.cc/${value}"
lazy val url = for{
link <- sciHubDoi
d <- doi
} yield link //s"""<a href="${link}">${d}</a>"""
lazy val title: Option[String] = getHead("title")
lazy val authors: Option[List[String]] = get("author")
lazy val journal: Option[String] = getHead("journal")
lazy val volume: Option[String] = getHead("volume")
lazy val year: Option[String] = getHead("year")
def toBiblioReference(num: Int): BiblioReference = {
val na = "N/A"
val auth = authors.fold("N/A")(list => list.foldLeft(""){
case ("", e) => e
case (acc, e)=> acc +", "+ e
})
BiblioReference(num, url.getOrElse(num.toString), title.getOrElse(na), auth, journal.getOrElse(na), year.getOrElse(na) )
}
//def hasPosition(str: String) =
}
case class BiblioReference(num: Int, url: String, title: String, authors: String, journal: String, year: String)