This repository has been archived by the owner on Mar 7, 2018. It is now read-only.
/
FortisEvent.scala
90 lines (80 loc) · 2.47 KB
/
FortisEvent.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.microsoft.partnercatalyst.fortis.spark.dto
import java.util.Objects
trait FortisEvent {
val details: Details
val analysis: Analysis
}
trait Details {
val eventid: String
val sourceeventid: String
val eventtime: Long
val body: String
val title: String
val externalsourceid: String
val pipelinekey: String
val sourceurl: String
val sharedLocations: List[Location]
}
case class Analysis(
language: Option[String] = None,
locations: List[Location] = List(),
sentiments: List[Double] = List(),
moods: List[Tag] = List(),
//todo genders: List[Tag] = List(),
keywords: List[Tag] = List(),
entities: List[Tag] = List(),
summary: Option[String] = None
)
case class Location(
wofId: String,
layer: String,
latitude: Double,
longitude: Double,
confidence: Option[Double] = None
) extends Ordered[Location] {
override def equals(obj: scala.Any): Boolean = {
if (obj == null) return false
if (!obj.isInstanceOf[Location]) return false
val location = obj.asInstanceOf[Location]
Objects.equals(wofId, location.wofId)
}
override def hashCode(): Int = wofId.hashCode
override def compare(that: Location): Int = {
Location.layerToInt(layer).compare(Location.layerToInt(that.layer))
}
}
object Location {
/**
* @see https://github.com/whosonfirst/whosonfirst-placetypes
*/
def layerToInt(layer: String): Int = {
Option(layer).map(_.toLowerCase) match {
case Some("continent") => 4000
case Some("empire") => 3900
case Some("country") => 3800
case Some("dependency") |
Some("disputed") => 3700
case Some("macroregion") => 3600
case Some("region") => 3500
case Some("macrocounty") => 3400
case Some("county") => 3300
case Some("metro area") |
Some("localadmin") => 3200
case Some("locality") => 3100
case Some("borough") => 3000
case Some("macrohood") => 2900
case Some("neighbourhood") => 2800
case Some("microhood") => 2700
case Some("campus") => 2600
case Some("building") => 2500
case Some("address") => 2400
case Some("venue") => 2300
case _ => 999999 // we usually care about the most granular location values
// so it's fine to treat unknown values as greater than all
}
}
}
case class Tag(
name: String,
confidence: Option[Double]
)