blob: b221718fb300e219cc7eaab15ee4d448bbe64ae5 (
plain)
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
|
package sandcrawler
import cascading.flow.FlowDef
import cascading.pipe.Pipe
import cascading.tuple.Fields
import com.twitter.scalding._
import com.twitter.scalding.typed.TDsl._
import parallelai.spyglass.hbase.HBaseConstants.SourceMode
import parallelai.spyglass.hbase.HBasePipeConversions
import parallelai.spyglass.hbase.HBaseSource
class CrossrefScorable extends Scorable {
def getFeaturesPipe(args : Args) : TypedPipe[MapFeatures] = {
// TODO: Generalize args so there can be multiple Grobid pipes in one job.
TextLine(args("crossref-input"))
.read
.toTypedPipe[String](new Fields("line"))
.map{ json : String =>
CrossrefScorable.crossrefToSlug(json) match {
case Some(slug) => new MapFeatures(slug, json)
case None => new MapFeatures(Scorable.NoSlug, json)
}
}
}
}
object CrossrefScorable {
def crossrefToSlug(json : String) : Option[String] = {
Scorable.jsonToMap(json) match {
case None => None
case Some(map) => {
if (map contains "title") {
// TODO: Don't ignore titles after the first.
val title = map("title").asInstanceOf[List[String]](0)
Some(Scorable.titleToSlug(title))
} else {
None
}
}
}
}
}
|