Skip to content

Bindings to Google's Compact Language Detector 3 to JVM Based Languages

License

Notifications You must be signed in to change notification settings

ntedgi/cld3-kotlin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status codecov codebeat badge

cld3-kotlin

WIP - Kotlin CLD3 - Google's Compact Language Detector 3

Bridge from c++ to Kotlin using Java Abstracted Foreign Function Layer

Operations Systems Support:

Job OS State Shared Objects
47.1 macOS passed dylib
47.2 Linux passed so
- windows not supported -

Usage Examples:

add maven dependencies

<repositories>
     <repository>
         <id>jitpack.io</id>
         <url>https://jitpack.io</url>
     </repository>
 </repositories>
 ...
<dependency>
     <groupId>com.github.ntedgi</groupId>
     <artifactId>cld3-kotlin</artifactId>
     <version>1.0.2</version>
</dependency>

download os shred objects and add them under src/lib/(os-name)

val ld = LangDetect()
val englishText = "This piece of text is in English";
var result = ld.detect(englishText)
assert(result.language == "English")
assert(result.isReliable)
assert(result.proportion == 1f)
val ld = LangDetect()
val englishBulgarianText = "This piece of text is in English Този текст е на Български";
val results = ld.findTopNMostFreqLangs(englishBulgarianText, 3)
val languages = results.map { it.language }
assert(languages.size == 3)
assert(languages.contains("English"))
assert(languages.contains("Bulgarian"))
assert(languages.contains("UNKNOWN"))

The Bridge Interface Implemantation:

from (C++)

std::vector<Result> FindTopNMostFreqLangs(const string &text, int num_langs);
Result FindLanguage(const string &text);

to (Kotlin)

fun findTopNMostFreqLangs(text: String, n: Int): List<LangDetectResponse> 
fun detect(text: String): LangDetectResponse 
data class LangDetectResponse(
    val probability: Float,
    val proportion: Float,
    val isReliable: Boolean,
    val language: String
)

if (this.repo.isAwesome || this.repo.isHelpful) {
  Star(this.repo);
}