Skip to content

Commit

Permalink
#90: rename kind to matchType
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-myltsev committed Nov 9, 2016
1 parent 19a62d5 commit 91134f1
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.util.UUID

import akka.http.scaladsl.unmarshalling.Unmarshaller
import Resolver.NameRequest
import model.{DataSource, Kind, Matches, NameStringIndex, LocalId}
import model.{DataSource, MatchType, Matches, NameStringIndex, LocalId}
import spray.json.{DefaultJsonProtocol, _}

trait NamestringsProtocols extends DefaultJsonProtocol with NullOptions {
Expand Down Expand Up @@ -35,7 +35,7 @@ trait NamestringsProtocols extends DefaultJsonProtocol with NullOptions {
classificationPath: Option[String], classificationPathIds: Option[String],
classificationPathRanks: Option[String],
vernaculars: Seq[VernacularResponse],
kind: Kind)
matchType: MatchType)

def result(matches: Matches, page: Int, perPage: Int): Response = {
val items = matches.matches.map { m =>
Expand All @@ -53,7 +53,7 @@ trait NamestringsProtocols extends DefaultJsonProtocol with NullOptions {
m.nameStringIndex.classificationPath, m.nameStringIndex.classificationPathIds,
m.nameStringIndex.classificationPathRanks,
vernaculars,
m.kind)
m.matchType)
}
Response(page, perPage, matches.total, matches.localId, matches.suppliedNameString, items)
}
Expand All @@ -69,18 +69,18 @@ trait NamestringsProtocols extends DefaultJsonProtocol with NullOptions {
case x => deserializationError("Expected UUID as JsString, but got " + x)
}
}
implicit def kindFormat: JsonFormat[Kind] = new JsonFormat[Kind] {
def write(x: Kind): JsString = JsString(x.toString)
implicit def matchTypeFormat: JsonFormat[MatchType] = new JsonFormat[MatchType] {
def write(x: MatchType): JsString = JsString(x.toString)

def read(value: JsValue): Kind = value match {
def read(value: JsValue): MatchType = value match {
case JsString(js) => js match {
case "None" => Kind.None
case "Fuzzy" => Kind.Fuzzy
case "ExactNameMatchByUUID" => Kind.ExactNameMatchByUUID
case "ExactCanonicalNameMatchByUUID" => Kind.ExactCanonicalNameMatchByUUID
case x => deserializationError("Expected Kind as JsString, but got " + x)
case "None" => MatchType.None
case "Fuzzy" => MatchType.Fuzzy
case "ExactNameMatchByUUID" => MatchType.ExactNameMatchByUUID
case "ExactCanonicalNameMatchByUUID" => MatchType.ExactCanonicalNameMatchByUUID
case x => deserializationError("Expected MatchType as JsString, but got " + x)
}
case x => deserializationError("Expected Kind as JsString, but got " + x)
case x => deserializationError("Expected MatchType as JsString, but got " + x)
}
}
implicit val nameStringIndexFormat = jsonFormat12(NameStringIndex.apply)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ response {
"vernaculars": [

],
"kind": "ExactNameMatchByUUID",
"matchType": "ExactNameMatchByUUID",
"dataSourceTitle": "Index to Organism Names",
"canonicalNameUuid": "b701ec9e-efb0-5d5b-bf03-b920c00d0a77"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ response {
"surrogate": null,
"taxonId": "7232908",
"canonicalName": null,
"kind": "None",
"matchType": "None",
"dataSourceTitle": "GBIF Backbone Taxonomy",
"canonicalNameUuid": null
}
Expand Down
10 changes: 5 additions & 5 deletions api/src/test/resources/test_data/name_strings/paging/page1.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ response {
"vernaculars": [

],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "Catalogue of Life",
"canonicalNameUuid": "ee4558c2-dcf9-5831-a53f-4c3ac03d364f"
},
Expand All @@ -50,7 +50,7 @@ response {
"vernaculars": [

],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "ITIS",
"canonicalNameUuid": "ee4558c2-dcf9-5831-a53f-4c3ac03d364f"
},
Expand All @@ -68,7 +68,7 @@ response {
"vernaculars": [

],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "Interim Register of Marine and Nonmarine Genera",
"canonicalNameUuid": "ee4558c2-dcf9-5831-a53f-4c3ac03d364f"
},
Expand All @@ -86,7 +86,7 @@ response {
"vernaculars": [

],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "WoRMS",
"canonicalNameUuid": "ee4558c2-dcf9-5831-a53f-4c3ac03d364f"
},
Expand All @@ -104,7 +104,7 @@ response {
"vernaculars": [

],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "GBIF Backbone Taxonomy",
"canonicalNameUuid": "ee4558c2-dcf9-5831-a53f-4c3ac03d364f"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ response {
"surrogate": false,
"taxonId": "33255784",
"canonicalName": "Pododesmus rudis",
"kind": "None",
"matchType": "None",
"dataSourceTitle": "EOL",
"canonicalNameUuid": "ee4558c2-dcf9-5831-a53f-4c3ac03d364f"
},
Expand All @@ -51,7 +51,7 @@ response {
"surrogate": false,
"taxonId": "36507198",
"canonicalName": "Pododesmus rudis",
"kind": "None",
"matchType": "None",
"dataSourceTitle": "EOL",
"canonicalNameUuid": "ee4558c2-dcf9-5831-a53f-4c3ac03d364f"
},
Expand All @@ -69,7 +69,7 @@ response {
"surrogate": false,
"taxonId": "131877663",
"canonicalName": "Pododesmus rudis",
"kind": "None",
"matchType": "None",
"dataSourceTitle": "nlbif",
"canonicalNameUuid": "ee4558c2-dcf9-5831-a53f-4c3ac03d364f"
},
Expand All @@ -87,7 +87,7 @@ response {
"surrogate": false,
"taxonId": "94118348",
"canonicalName": "Pododesmus rudis",
"kind": "None",
"matchType": "None",
"dataSourceTitle": "uBio NameBank",
"canonicalNameUuid": "ee4558c2-dcf9-5831-a53f-4c3ac03d364f"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ response {
"vernacular": [

],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "uBio NameBank",
"canonicalNameUuid": "16f235a0-e4a3-529c-9b83-bd15fe722110"
},
Expand All @@ -48,7 +48,7 @@ response {
"vernacular": [

],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "nlbif",
"canonicalNameUuid": "16f235a0-e4a3-529c-9b83-bd15fe722110"
},
Expand All @@ -66,7 +66,7 @@ response {
"vernacular": [

],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "BioLib.cz",
"canonicalNameUuid": "16f235a0-e4a3-529c-9b83-bd15fe722110"
},
Expand All @@ -84,7 +84,7 @@ response {
"vernacular": [
"Human"
],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "IUCN Red List of Threatened Species",
"canonicalNameUuid": "16f235a0-e4a3-529c-9b83-bd15fe722110"
},
Expand All @@ -102,7 +102,7 @@ response {
"vernacular": [
"智人"
],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "The National Checklist of Taiwan",
"canonicalNameUuid": "16f235a0-e4a3-529c-9b83-bd15fe722110"
},
Expand All @@ -120,7 +120,7 @@ response {
"vernacular": [
"man"
],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "EOL",
"canonicalNameUuid": "16f235a0-e4a3-529c-9b83-bd15fe722110"
},
Expand All @@ -138,7 +138,7 @@ response {
"vernacular": [
"human"
],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "EOL",
"canonicalNameUuid": "16f235a0-e4a3-529c-9b83-bd15fe722110"
},
Expand All @@ -156,7 +156,7 @@ response {
"vernacular": [

],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "EOL",
"canonicalNameUuid": "16f235a0-e4a3-529c-9b83-bd15fe722110"
},
Expand Down Expand Up @@ -340,7 +340,7 @@ response {
"Muntu",
"Адæймаг"
],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "GBIF Backbone Taxonomy",
"canonicalNameUuid": "16f235a0-e4a3-529c-9b83-bd15fe722110"
},
Expand All @@ -358,7 +358,7 @@ response {
"vernacular": [

],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "Interim Register of Marine and Nonmarine Genera",
"canonicalNameUuid": "16f235a0-e4a3-529c-9b83-bd15fe722110"
},
Expand All @@ -376,7 +376,7 @@ response {
"vernacular": [

],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "Union 4",
"canonicalNameUuid": "16f235a0-e4a3-529c-9b83-bd15fe722110"
},
Expand All @@ -394,7 +394,7 @@ response {
"vernacular": [
"human"
],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "ITIS",
"canonicalNameUuid": "16f235a0-e4a3-529c-9b83-bd15fe722110"
},
Expand All @@ -412,7 +412,7 @@ response {
"vernacular": [

],
"kind": "None",
"matchType": "None",
"dataSourceTitle": "Catalogue of Life",
"canonicalNameUuid": "16f235a0-e4a3-529c-9b83-bd15fe722110"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ response {
"surrogate": false,
"taxonId": "12965815",
"canonicalName": "Pododesmus rudis",
"kind": "None",
"matchType": "None",
"dataSourceTitle": "Catalogue of Life",
"canonicalNameUuid": "ee4558c2-dcf9-5831-a53f-4c3ac03d364f"
},
Expand Down Expand Up @@ -62,7 +62,7 @@ response {
"surrogate": false,
"taxonId": "79794",
"canonicalName": "Pododesmus rudis",
"kind": "None",
"matchType": "None",
"dataSourceTitle": "ITIS",
"canonicalNameUuid": "ee4558c2-dcf9-5831-a53f-4c3ac03d364f"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ trait Materializer {
} yield {
Matches(count,
portion.zip(vernaculars).map { case ((ns, nsi, ds), vs) =>
Match(ns, ds, nsi, vs, parameters.kind)
Match(ns, ds, nsi, vs, parameters.matchType)
},
suppliedNameString = parameters.query)
}
Expand All @@ -89,7 +89,7 @@ trait Materializer {
val l = vernacularsGet(portion, parameters).map { vss =>
Matches(count,
portion.zip(vss).map { case ((ns, nsi, ds), vs) =>
Match(ns, ds, nsi, vs, parameters.kind)
Match(ns, ds, nsi, vs, parameters.matchType)
},
localId = parameters.localId,
suppliedNameString = parameters.query)
Expand All @@ -106,7 +106,7 @@ object Materializer {
case class Parameters(page: Int, perPage: Int,
withSurrogates: Boolean, withVernaculars: Boolean,
query: String = "",
localId: Option[LocalId] = None, kind: Kind = Kind.None) {
localId: Option[LocalId] = None, matchType: MatchType = MatchType.None) {
val take: Int = perPage.min(1000).max(0)
val drop: Int = (page * perPage).max(0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Resolver(val db: Database, matcher: Matcher) extends Materializer {
ns.canonicalUuid.inSetBind(candUuids)
}
val params = parameters.copy(query = verbatim, perPage = fuzzyNameStringsMaxCount,
kind = Kind.Fuzzy)
matchType = MatchType.Fuzzy)
(ns, params)
})

Expand Down Expand Up @@ -144,9 +144,10 @@ class Resolver(val db: Database, matcher: Matcher) extends Materializer {
.filter { m =>
dataSourceIds.isEmpty || dataSourceIds.contains(m.nameStringIndex.dataSourceId)
}.map { m =>
val k: Kind = if (m.nameString.name.id == sn.input.id) Kind.ExactNameMatchByUUID
else Kind.ExactCanonicalNameMatchByUUID
m.copy(kind = k)
val mt: MatchType =
if (m.nameString.name.id == sn.input.id) MatchType.ExactNameMatchByUUID
else MatchType.ExactCanonicalNameMatchByUUID
m.copy(matchType = mt)
}
mtch.copy(matches = ms, localId = localId)
}
Expand Down
14 changes: 7 additions & 7 deletions resolver/src/main/scala/org/globalnames/resolver/model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ package resolver

package object model {

sealed trait Kind
object Kind {
case object None extends Kind
case object ExactNameMatchByUUID extends Kind
case object ExactCanonicalNameMatchByUUID extends Kind
case object Fuzzy extends Kind
sealed trait MatchType
object MatchType {
case object None extends MatchType
case object ExactNameMatchByUUID extends MatchType
case object ExactCanonicalNameMatchByUUID extends MatchType
case object Fuzzy extends MatchType
}

type LocalId = Int

case class Match(nameString: NameString, dataSource: DataSource, nameStringIndex: NameStringIndex,
vernacularStrings: Seq[(VernacularString, VernacularStringIndex)],
kind: Kind = Kind.None)
matchType: MatchType = MatchType.None)

case class Matches(total: Long, matches: Seq[Match],
suppliedNameString: String = "", localId: Option[LocalId] = None)
Expand Down
Loading

0 comments on commit 91134f1

Please sign in to comment.