提高智能
This commit is contained in:
parent
58d9a791bc
commit
1b4302ed23
3 changed files with 68 additions and 19 deletions
|
@ -11,8 +11,8 @@ android {
|
|||
applicationId = "uk.kagurach.android101"
|
||||
minSdk = 31
|
||||
targetSdk = 34
|
||||
versionCode = 141
|
||||
versionName = "1.4.1"
|
||||
versionCode = 151
|
||||
versionName = "1.5.1"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
package uk.kagurach.android101;
|
||||
|
||||
import static uk.kagurach.misc.AIAnswerServiceKt.AIAnswerService;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
public class Page4OtherActivity extends AppCompatActivity {
|
||||
|
||||
|
@ -19,13 +15,7 @@ public class Page4OtherActivity extends AppCompatActivity {
|
|||
if (bundle == null) throw new NullPointerException();
|
||||
String content = bundle.getString("request_content");
|
||||
if (content!=null){
|
||||
content = content.replace("?","?")
|
||||
.replace("?","!")
|
||||
.replace("你","我")
|
||||
.replace("吗","");
|
||||
if (!content.contains("!")){
|
||||
content = "对不起我不知道";
|
||||
}
|
||||
content = AIAnswerService(content);
|
||||
}else {
|
||||
content = "对不起坏掉了";
|
||||
}
|
||||
|
@ -37,8 +27,4 @@ public class Page4OtherActivity extends AppCompatActivity {
|
|||
setResult(RESULT_OK,intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
private void reply(String s){
|
||||
|
||||
}
|
||||
}
|
63
app/src/main/java/uk/kagurach/misc/AIAnswerService.kt
Normal file
63
app/src/main/java/uk/kagurach/misc/AIAnswerService.kt
Normal file
|
@ -0,0 +1,63 @@
|
|||
package uk.kagurach.misc
|
||||
|
||||
import java.time.Instant
|
||||
import java.util.Date
|
||||
import kotlin.random.Random
|
||||
|
||||
fun AIAnswerService(s: String):String {
|
||||
val rng = Random(Date.from(Instant.now()).time)
|
||||
|
||||
var result = s
|
||||
|
||||
result = result.replace("?","?")
|
||||
|
||||
|
||||
val isMoral = s.contains("您")
|
||||
val needAI = s.contains("你")
|
||||
|
||||
|
||||
|
||||
result = result.replace("我","^")
|
||||
result = result.replace("喵","")
|
||||
result = result.replace("咱","@")
|
||||
|
||||
|
||||
|
||||
if (isMoral){
|
||||
result = if (rng.nextBoolean()) {
|
||||
"谢谢@的提问,$result"
|
||||
} else{
|
||||
if (result.endsWith(".")||
|
||||
result.endsWith("。")||
|
||||
result.endsWith("?")){
|
||||
result = result.dropLast(1);
|
||||
}
|
||||
"$result,谢谢。"
|
||||
}
|
||||
result = result.replace("您","我")
|
||||
}
|
||||
if (needAI){
|
||||
result = result.replace("你","我")
|
||||
}
|
||||
|
||||
result = result.replace("想",
|
||||
if (rng.nextBoolean()){
|
||||
"可以"
|
||||
}else{
|
||||
"不可以"
|
||||
}
|
||||
)
|
||||
result = result.replace("什么","很多")
|
||||
result = result.replace("吗","")
|
||||
result = result.replace("?","。")
|
||||
result = result.replace("^","你")
|
||||
result = result.replace("@","您")
|
||||
return result
|
||||
}
|
||||
|
||||
fun main(){
|
||||
println(AIAnswerService("我想吃饭"))
|
||||
println(AIAnswerService("咱可以吃饭吗"))
|
||||
println(AIAnswerService("您可以做什么?"))
|
||||
println(AIAnswerService("您吃了吗?"))
|
||||
}
|
Loading…
Reference in a new issue