Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added low ranking parses as server config, and implemented in response p... #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion server/src/main/scala/GeocodeServerConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ case class GeocodeServerConfig(
maxTokens: Int = 10,
reload: Boolean = false,
hotfixBasePath: String = "",
enablePrivateEndpoints: Boolean = false
enablePrivateEndpoints: Boolean = false,
removeLowRankingParses: Boolean = true,
minPopulationForLowRankingParse: Int = 50000
)

object GeocodeServerConfigSingleton {
Expand Down Expand Up @@ -55,6 +57,12 @@ object GeocodeServerConfigParser {
opt[Boolean]("enable_private_endpoints")
.text("enable private endpoints on server")
.action { (x, c) => c.copy(enablePrivateEndpoints = x)}
opt[Boolean]("remove_low_ranking_parses")
.text("whether to remove low ranking parses")
.action { (x, c) => c.copy(removeLowRankingParses = x)}
opt[Int]("min_population_for_low_ranking_parse")
.text("the minimum population to be considered a low ranking parse")
.action { (x, c) => c.copy(minPopulationForLowRankingParse = x)}
}

// parser.parse returns Option[C]
Expand Down
13 changes: 8 additions & 5 deletions server/src/main/scala/ResponseProcessor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import java.nio.ByteBuffer
import scala.collection.mutable.{HashSet, ListBuffer}
import scalaj.collection.Implicits._
import com.twitter.ostrich.stats.Stats
import GeocodeServerConfigSingleton._

// Sort a list of features, smallest to biggest
object GeocodeServingFeatureOrdering extends Ordering[GeocodeServingFeature] {
Expand Down Expand Up @@ -550,14 +551,16 @@ class ResponseProcessor(

logger.ifDebug("have %d parses after filtering from delete hotfixes", goodParses.size)

goodParses = goodParses.filter(p => {
val parseLength = p.tokenLength
if (config.removeLowRankingParses) {
goodParses = goodParses.filter(p => {
val parseLength = p.tokenLength
parseLength == parseParams.tokens.size || parseLength != 1 ||
p.headOption.exists(m => {
m.fmatch.scoringFeatures.population > 50000 || p.length > 1
m.fmatch.scoringFeatures.population > config.minPopulationForLowRankingParse || p.length > 1
})
})
logger.ifDebug("have %d parses after removeLowRankingParses", goodParses.size)
})
logger.ifDebug("have %d parses after removeLowRankingParses", goodParses.size)
}

goodParses = goodParses.filter(p => p.headOption.exists(m => {
!m.fmatch.scoringFeatures.canGeocodeIsSet || m.fmatch.scoringFeatures.canGeocode
Expand Down