Created
June 13, 2019 05:31
-
-
Save shubham0204/92364ad5d63e3ac90351e5d654bac1d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface VocabCallback { | |
fun onDataProcessed( result : HashMap<String, DoubleArray>?) | |
} | |
private inner class LoadVocabularyTask(callback: VocabCallback?) : AsyncTask<String, Void, HashMap<String, DoubleArray>?>() { | |
private var callback : VocabCallback? = callback | |
override fun doInBackground(vararg params: String?): HashMap<String, DoubleArray>? { | |
val jsonObject = JSONObject( params[0] ) | |
val iterator : Iterator<String> = jsonObject.keys() | |
val data = HashMap< String , DoubleArray >() | |
while ( iterator.hasNext() ) { | |
val key = iterator.next() | |
val array = jsonObject.getJSONArray( key ) | |
val embeddingArray = DoubleArray( array.length() ) | |
for ( x in 0 until array.length() ) { | |
embeddingArray[x] = array.get( x ) as Double | |
} | |
data[key] = embeddingArray | |
} | |
return data | |
} | |
override fun onPostExecute(vocab: HashMap<String, DoubleArray>?) { | |
super.onPostExecute(vocab) | |
callback?.onDataProcessed( vocab ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment