-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'''kotlin | ||
GlobalScope.launch{ | ||
withContext(Dispatchers.IO){ | ||
val kotlinWiki = KotlinWiki() | ||
var search = kotlinWiki.searchResponse("hello world"); | ||
for(page in search.query?.pages!!){ | ||
val pageData = page.title?.let { kotlinWiki.getPage(it) } | ||
if (pageData != null) { | ||
Log.d("page", kotlinWiki.getSimplyParsedWikiText()) | ||
GlobalScope.launch(Dispatchers.Main){ | ||
textView.append(kotlinWiki.getSimplyParsedWikiText()) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
''' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'kotlin-android' | ||
} | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.3" | ||
|
||
defaultConfig { | ||
applicationId "jacs.apps.kotlinwikipediasearch" | ||
minSdkVersion 16 | ||
targetSdkVersion 30 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation project("kotlinwiki") | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||
implementation 'androidx.core:core-ktx:1.5.0' | ||
implementation 'androidx.appcompat:appcompat:1.3.0' | ||
implementation 'com.google.android.material:material:1.3.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' | ||
testImplementation 'junit:junit:4.+' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1' | ||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9' | ||
implementation 'com.squareup.retrofit2:retrofit:2.9.0' | ||
implementation 'com.squareup.retrofit2:converter-moshi:2.7.2' | ||
implementation "com.squareup.moshi:moshi:1.9.2" | ||
implementation "com.squareup.moshi:moshi-kotlin:1.9.2" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
plugins { | ||
id 'com.android.library' | ||
id 'kotlin-android' | ||
} | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.3" | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
targetSdkVersion 30 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles "consumer-rules.pro" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||
implementation 'androidx.core:core-ktx:1.5.0' | ||
implementation 'androidx.appcompat:appcompat:1.3.0' | ||
implementation 'com.google.android.material:material:1.3.0' | ||
implementation 'com.squareup.retrofit2:retrofit:2.9.0' | ||
implementation 'com.squareup.retrofit2:converter-moshi:2.7.2' | ||
implementation "com.squareup.moshi:moshi:1.9.2" | ||
implementation "com.squareup.moshi:moshi-kotlin:1.9.2" | ||
testImplementation 'junit:junit:4.+' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package jacs.apps.kotlinwiki | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("jacs.apps.kotlinwiki.test", appContext.packageName) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="jacs.apps.kotlinwiki"> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package jacs.apps.kotlinwiki | ||
|
||
import com.squareup.moshi.Moshi | ||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory | ||
import jacs.apps.kotlinwiki.datamodel.PageData | ||
import jacs.apps.kotlinwiki.datamodel.WikiResponse | ||
import jacs.apps.kotlinwiki.network.WikiAPI | ||
import okhttp3.OkHttpClient | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.moshi.MoshiConverterFactory | ||
import java.util.concurrent.TimeUnit | ||
|
||
class KotlinWiki { | ||
private lateinit var apiService: Retrofit | ||
private var wikitext: String = "" | ||
init { | ||
apiService = Retrofit.Builder().baseUrl("https://en.wikipedia.org/w/") | ||
.addConverterFactory( | ||
MoshiConverterFactory.create( | ||
Moshi.Builder().add( | ||
KotlinJsonAdapterFactory() | ||
).build()).asLenient()) | ||
.client( | ||
OkHttpClient().newBuilder() | ||
.writeTimeout(30, TimeUnit.SECONDS) | ||
.readTimeout(30, TimeUnit.SECONDS) | ||
.connectTimeout(30, TimeUnit.SECONDS).build()) | ||
.build() | ||
} | ||
suspend fun searchResponse(string: String) : WikiResponse{ | ||
val response = apiService.create(WikiAPI::class.java).getSearchRespone(string, | ||
"query", | ||
"2", | ||
"extracts|pageimages|pageterms", | ||
"100", | ||
"true", | ||
"thumbnail", | ||
"json", | ||
"prefixsearch", | ||
"300", | ||
"true") | ||
return response | ||
} | ||
suspend fun getPage(string: String) : PageData{ | ||
val nextResponse = apiService.create(WikiAPI::class.java).getPageData("parse", string, "wikitext","json","2") | ||
wikitext = nextResponse.parse?.wikitext.toString() | ||
return nextResponse | ||
} | ||
fun getSimplyParsedWikiText() : String{ | ||
wikitext = wikitext.replace("(?s)<ref.*?</ref>".toRegex(), ""); | ||
wikitext = wikitext.replace("(?s)<!--.*?-->".toRegex(), ""); | ||
wikitext = wikitext.replace("(?s)<small>.*?</small>".toRegex(), ""); | ||
wikitext = wikitext.replace("[[", "") | ||
wikitext = wikitext.replace("]]","") | ||
wikitext = wikitext.replace("|", " ") | ||
wikitext = wikitext.replace("(?s)\\{\\{.*?\\}\\}".toRegex(), "") | ||
wikitext = wikitext.replace("(?s)\\{.*?\\}".toRegex(), "") | ||
wikitext = wikitext.replace("}}","") | ||
//wikitext = wikitext.replace("\\{(?<re>\\{\\{(?:(?> [^\\{\\}]+ )|<re>)*\\}\\})\\}".toRegex(), "") | ||
return wikitext | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package jacs.apps.kotlinwiki.datamodel | ||
|
||
data class Continue( | ||
val `continue`: String?, | ||
val gpsoffset: Int? | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package jacs.apps.kotlinwiki.datamodel | ||
|
||
data class Page( | ||
val extract: String?, | ||
val index: Int?, | ||
val ns: Int?, | ||
val pageid: Int?, | ||
val terms: Terms?, | ||
val thumbnail: Thumbnail?, | ||
val title: String? | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package jacs.apps.kotlinwiki.datamodel | ||
|
||
data class PageData ( | ||
val parse : Parse? | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package jacs.apps.kotlinwiki.datamodel | ||
|
||
data class Parse ( | ||
|
||
val title : String?, | ||
val pageid : Int?, | ||
val wikitext : String? | ||
|
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package jacs.apps.kotlinwiki.datamodel | ||
|
||
data class Query( | ||
val pages: List<Page>? | ||
) |