Skip to content

Commit

Permalink
Fix deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
pemistahl committed Jul 19, 2021
1 parent f2ca537 commit b8c3a25
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ linguaGroupId=com.github.pemistahl

linguaArtifactId=lingua

linguaVersion=1.1.0
linguaVersion=1.2.0-SNAPSHOT

linguaName=Lingua

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ abstract class AbstractLanguageDetectionAccuracyReport(
fun afterAll() {
val projectRootPath = Paths.get("").toAbsolutePath().toString()
val accuracyReportsDirectoryName = "accuracy-reports"
val detectorDirectoryName = implementationToUse.name.toLowerCase(Locale.ROOT)
val languageReportFileName = "${language.name.toLowerCase(Locale.ROOT).capitalize()}.txt"
val detectorDirectoryName = implementationToUse.name.lowercase()
val languageReportFileName = "${language.name.lowercase().replaceFirstChar { it.titlecase() }}.txt"
val accuracyReportsDirectoryPath = Paths.get(
projectRootPath,
accuracyReportsDirectoryName,
Expand Down Expand Up @@ -184,7 +184,7 @@ abstract class AbstractLanguageDetectionAccuracyReport(
OPENNLP -> {
val detectedLanguage = opennlpDetector.predictLanguage(element)
val isoCode = try {
val isoCode = detectedLanguage.lang.toUpperCase(Locale.ROOT)
val isoCode = detectedLanguage.lang.uppercase()
IsoCode639_3.valueOf(mapOpenNlpIsoCodeToLinguaIsoCode(isoCode))
} catch (e: IllegalArgumentException) {
IsoCode639_3.NONE
Expand Down Expand Up @@ -249,15 +249,15 @@ abstract class AbstractLanguageDetectionAccuracyReport(
return when {
!locale.isPresent -> UNKNOWN
locale.get().language.startsWith("zh") -> CHINESE
else -> Language.getByIsoCode639_1(IsoCode639_1.valueOf(locale.get().language.toUpperCase(Locale.ROOT)))
else -> Language.getByIsoCode639_1(IsoCode639_1.valueOf(locale.get().language.uppercase()))
}
}

private fun mapLanguageResultToLanguage(result: LanguageResult): Language {
return when {
result.isUnknown -> UNKNOWN
result.language.startsWith("zh") -> CHINESE
else -> Language.getByIsoCode639_1(IsoCode639_1.valueOf(result.language.toUpperCase(Locale.ROOT)))
else -> Language.getByIsoCode639_1(IsoCode639_1.valueOf(result.language.uppercase()))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
import java.util.Locale
import java.util.SortedMap
import java.util.TreeMap
import kotlin.math.ln
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/com/github/pemistahl/lingua/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import com.github.pemistahl.lingua.api.LanguageDetectorBuilder
import com.github.pemistahl.lingua.api.LanguageDetectorBuilder.Companion.fromAllLanguages
import com.github.pemistahl.lingua.api.LanguageDetectorBuilder.Companion.fromIsoCodes639_1
import java.io.Console
import java.util.Locale
import java.util.Scanner

fun main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ internal object Constant {
)

fun isJapaneseAlphabet(char: Char): Boolean {
val script = Character.UnicodeScript.of(char.toInt())
val script = Character.UnicodeScript.of(char.code)
return script == Character.UnicodeScript.HIRAGANA ||
script == Character.UnicodeScript.KATAKANA ||
script == Character.UnicodeScript.HAN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.util.Locale

@Serializable
internal data class JsonLanguageModel(val language: Language, val ngrams: Map<Fraction, String>)
Expand Down Expand Up @@ -89,7 +88,6 @@ internal data class TrainingDataLanguageModel(
for ((fraction, ngrams) in jsonLanguageModel.ngrams) {
val fractionAsDouble = fraction.toDouble()
for (ngram in ngrams.split(' ')) {
// Note: Don't use `[...] =` because that wraps primitive as Object
jsonRelativeFrequencies.put(ngram, fractionAsDouble)
}
}
Expand Down

0 comments on commit b8c3a25

Please sign in to comment.