Skip to content
This repository was archived by the owner on Mar 7, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ object Constants {
val HighlyAvailableProgressDir = "HA_PROGRESS_DIR"
val AppInsightsKey = "FORTIS_APPINSIGHTS_IKEY"
val LanguageModelDir = "FORTIS_MODELS_DIRECTORY"
val FeatureServiceHost = "FORTIS_FEATURE_SERVICE_HOST"
val FeatureServiceUrlBase = "FORTIS_FEATURE_SERVICE_HOST"
val OxfordVisionToken= "OXFORD_VISION_TOKEN"
val OxfordLanguageToken = "OXFORD_LANGUAGE_TOKEN"
val BlobHost = "FORTIS_BLOB_HOST"
val BlobUrlBase = "FORTIS_CENTRAL_ASSETS_HOST"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ object Pipeline {
// broadcast changes across the Spark cluster.

val geofence = Geofence(north = 49.6185146245, west = -124.9578052195, south = 46.8691952854, east = -121.0945042053)
val entityModelsProvider = new ZipModelsProvider(language => s"${Settings.blobHost}/opener/opener-$language.zip", Settings.modelsDir)
val sentimentModelsProvider = new ZipModelsProvider(language => s"${Settings.blobHost}/sentiment/sentiment-$language.zip", Settings.modelsDir)
val entityModelsProvider = new ZipModelsProvider(language => s"${Settings.blobUrlBase}/opener/opener-$language.zip", Settings.modelsDir)
val sentimentModelsProvider = new ZipModelsProvider(language => s"${Settings.blobUrlBase}/sentiment/sentiment-$language.zip", Settings.modelsDir)

val featureServiceClient = new FeatureServiceClient(Settings.featureServiceHost)
val featureServiceClient = new FeatureServiceClient(Settings.featureServiceUrlBase)
val locationsExtractorFactory = new LocationsExtractorFactory(featureServiceClient, geofence).buildLookup()
val locationFetcher = locationsExtractorFactory.fetch _
val blacklist = new Blacklist(Seq(Set("Trump", "Hilary")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ object ProjectFortis extends App {
import scala.util.Properties.envOrNone

val progressDir = envOrFail(Constants.Env.HighlyAvailableProgressDir)
val featureServiceHost = envOrFail(Constants.Env.FeatureServiceHost)
val featureServiceUrlBase = envOrFail(Constants.Env.FeatureServiceUrlBase)
val oxfordLanguageToken = envOrFail(Constants.Env.OxfordLanguageToken)
val oxfordVisionToken = envOrFail(Constants.Env.OxfordVisionToken)
val blobHost = envOrElse(Constants.Env.BlobHost, "https://fortiscentral.blob.core.windows.net")
val blobUrlBase = envOrElse(Constants.Env.BlobUrlBase, "https://fortiscentral.blob.core.windows.net")

val appInsightsKey = envOrNone(Constants.Env.AppInsightsKey)
val modelsDir = envOrNone(Constants.Env.LanguageModelDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.microsoft.partnercatalyst.fortis.spark

trait Settings {
val progressDir: String
val featureServiceHost: String
val featureServiceUrlBase: String
val oxfordLanguageToken: String
val oxfordVisionToken: String
val blobHost: String
val blobUrlBase: String
val appInsightsKey: Option[String]
val modelsDir: Option[String]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import net.liftweb.json

import scalaj.http.Http

case class ImageAnalysisAuth(key: String, apiHost: String = "https://westus.api.cognitive.microsoft.com")
case class ImageAnalysisAuth(key: String, apiUrlBase: String = "https://westus.api.cognitive.microsoft.com")

@SerialVersionUID(100L)
class ImageAnalyzer(auth: ImageAnalysisAuth, featureServiceClient: FeatureServiceClient) extends Serializable {
Expand All @@ -17,7 +17,7 @@ class ImageAnalyzer(auth: ImageAnalysisAuth, featureServiceClient: FeatureServic
}

protected def callCognitiveServices(requestBody: String): String = {
Http(s"${auth.apiHost}/vision/v1.0/analyze")
Http(s"${auth.apiUrlBase}/vision/v1.0/analyze")
.params(
"details" -> "Celebrities,Landmarks",
"visualFeatures" -> "Categories,Tags,Description,Faces")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import net.liftweb.json

import scalaj.http.Http

case class LanguageDetectorAuth(key: String, apiHost: String = "https://westus.api.cognitive.microsoft.com")
case class LanguageDetectorAuth(key: String, apiUrlBase: String = "https://westus.api.cognitive.microsoft.com")

@SerialVersionUID(100L)
class LanguageDetector(
Expand All @@ -24,7 +24,7 @@ class LanguageDetector(
}

protected def callCognitiveServices(requestBody: String): String = {
Http(s"${auth.apiHost}/text/analytics/v2.0/languages")
Http(s"${auth.apiUrlBase}/text/analytics/v2.0/languages")
.params(
"numberOfLanguagesToDetect" -> "1")
.headers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import scala.io.Source
import scala.util.{Failure, Success, Try}

@SerialVersionUID(100L)
class FeatureServiceClient(host: String) extends Serializable with Loggable {
class FeatureServiceClient(apiUrlBase: String) extends Serializable with Loggable {
def bbox(geofence: Geofence): Iterable[FeatureServiceFeature] = {
unpack(fetchBboxResponse(geofence), "bbox")
}
Expand Down Expand Up @@ -40,17 +40,17 @@ class FeatureServiceClient(host: String) extends Serializable with Loggable {
}

protected def fetchBboxResponse(geofence: Geofence): Try[String] = {
val fetch = s"$host/features/bbox/${geofence.north}/${geofence.west}/${geofence.south}/${geofence.east}"
val fetch = s"$apiUrlBase/features/bbox/${geofence.north}/${geofence.west}/${geofence.south}/${geofence.east}"
fetchResponse(fetch)
}

protected def fetchPointResponse(latitude: Double, longitude: Double): Try[String] = {
val fetch = s"$host/features/point/$latitude/$longitude"
val fetch = s"$apiUrlBase/features/point/$latitude/$longitude"
fetchResponse(fetch)
}

protected def fetchNameResponse(names: Iterable[String]): Try[String] = {
val fetch = s"$host/features/name/${names.mkString(",")}"
val fetch = s"$apiUrlBase/features/name/${names.mkString(",")}"
fetchResponse(fetch)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import net.liftweb.json

import scalaj.http.Http

case class SentimentDetectorAuth(key: String, apiHost: String = "https://westus.api.cognitive.microsoft.com")
case class SentimentDetectorAuth(key: String, apiUrlBase: String = "https://westus.api.cognitive.microsoft.com")

@SerialVersionUID(100L)
class CognitiveServicesSentimentDetector(
Expand All @@ -20,7 +20,7 @@ class CognitiveServicesSentimentDetector(
}

protected def callCognitiveServices(requestBody: String): String = {
Http(s"${auth.apiHost}/text/analytics/v2.0/sentiment")
Http(s"${auth.apiUrlBase}/text/analytics/v2.0/sentiment")
.headers(
"Content-Type" -> "application/json",
"Ocp-Apim-Subscription-Key" -> auth.key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TestLocationsExtractorFactory(client: FeatureServiceClient) extends Locati
def getLookup: Map[String, Set[String]] = lookup
}

class TestFeatureServiceClient(givenBbox: Seq[FeatureServiceFeature], givenPoint: Seq[FeatureServiceFeature]) extends FeatureServiceClient("test-host") {
class TestFeatureServiceClient(givenBbox: Seq[FeatureServiceFeature], givenPoint: Seq[FeatureServiceFeature]) extends FeatureServiceClient("http://some/test/url") {
override def bbox(geofence: Geofence): Iterable[FeatureServiceFeature] = givenBbox
override def point(latitude: Double, longitude: Double): Iterable[FeatureServiceFeature] = givenPoint
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.scalatest.FlatSpec

import scala.util.Try

class TestFeatureServiceClient(bboxResponse: String) extends FeatureServiceClient(host = "unittest") {
class TestFeatureServiceClient(bboxResponse: String) extends FeatureServiceClient(apiUrlBase = "unittest") {
override def fetchBboxResponse(geofence: Geofence): Try[String] = Try(bboxResponse)
}

Expand Down