<commit_before>package com.rm.translateit.api.wiki

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.rm.translateit.api.Translater
import com.rm.translateit.api.models.Language
import com.rm.translateit.api.wiki.response.LanguageLinksResult
import com.rm.translateit.api.wiki.response.SuggestionResult
import retrofit2.Retrofit
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import rx.Observable
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers

class WikiTranslater : Translater {
    override fun translate(word: String, from: String, to: String): Observable<String> {
        val gson = GsonBuilder()
                .registerTypeAdapter(LanguageLinksResult::class.java, LanguageDeserializer())
                .create()
        val service = wikiService(from, gson)

        return service.query(word)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .map { result -> result.list
                        .filter({ result -> result.code == to.toLowerCase() })
                        .firstOrNull()?.title
                }
    }

    //TODO: load languages from somewhere.
    override fun languages(): List<Language> {
        return listOf(
                Language("EN", "English"),
                Language("PL", "Polish"),
                Language("RU", "Russian")
        )
    }

    override fun suggestions(title: String, from: String, offset: Int): Observable<List<String>> {
        val gson = GsonBuilder()
                .registerTypeAdapter(SuggestionResult::class.java, SuggestionDeserializer())
                .create()

        val service = wikiService(from, gson)<commit_msg>WikiTranslater.kt edited online with Bitbucket<commit_after>package com.rm.translateit.api.wiki

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.rm.translateit.api.Translater
import com.rm.translateit.api.models.Language
import com.rm.translateit.api.wiki.response.LanguageLinksResult
import com.rm.translateit.api.wiki.response.SuggestionResult
import retrofit2.Retrofit
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import rx.Observable
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers

class WikiTranslater : Translater {
    override fun translate(word: String, from: String, to: String): Observable<String> {
        val gson = GsonBuilder()
                .registerTypeAdapter(LanguageLinksResult::class.java, LanguageDeserializer())
                .create()
        val service = wikiService(from, gson)

        return service.query(word, to)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .map { result -> result.list
                        .filter({ result -> result.code == to.toLowerCase() })
                        .firstOrNull()?.title
                }
    }

    //TODO: load languages from somewhere.
    override fun languages(): List<Language> {
        return listOf(
                Language("EN", "English"),
                Language("PL", "Polish"),
                Language("RU", "Russian")
        )
    }

    override fun suggestions(title: String, from: String, offset: Int): Observable<List<String>> {
        val gson = GsonBuilder()
                .registerTypeAdapter(SuggestionResult::class.java, SuggestionDeserializer())
                .create()

        val service = wikiService(from, gson)
{'fraction_non_alphanumeric': 0.1035527402919306, 'fraction_numerical': 0.0016524373450839988, 'mean_word_length': 2.67983789260385, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2014622', 'n_tokens_mistral': 1016, 'n_tokens_neox': 963, 'n_words': 196}