Comparing Javascript code words with glossary words

main
Cemal Odabasioglu 2023-12-07 16:17:39 +01:00
parent 9e407d78cc
commit 87ed353f9e
2 changed files with 86 additions and 10 deletions

View File

@ -4,12 +4,10 @@ import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.Close
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
@ -30,8 +28,6 @@ import java.io.FileInputStream
val customRedColor = Color(0xFFB70D1B)
@Composable
fun homePage(
onGlossaireClick: () -> Unit,
@ -46,6 +42,8 @@ fun homePage(
) {
Text("Quali'Nomme", style = MaterialTheme.typography.h3)
var isCompareClicked by remember { mutableStateOf(false) }
Spacer(modifier = Modifier.height(16.dp))
Row(
@ -72,7 +70,10 @@ fun homePage(
}
Button(
onClick = { /* Action de Comparer */ },
onClick = {
isCompareClicked = true
},
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
@ -80,16 +81,89 @@ fun homePage(
) {
Text("Comparer")
}
if (isCompareClicked) {
println(mostUsedWordList.keys.toList())
compareResults(
motsGlossaire = chargerDonneesDepuisFichier(),
motsCode = mostUsedWordList.keys.toList(),
onRetourClick = { isCompareClicked = false }
)
}
}
}
}
@Composable
fun compareResults(
motsGlossaire: List<Mot>,
motsCode: List<String>,
onRetourClick: () -> Unit,
navigationIcon: @Composable () -> Unit = { Icon(Icons.Filled.ArrowBack, contentDescription = null) }
) {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Top, // Align content at the top
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = "Le code contient ${comparerMots(motsGlossaire, motsCode)}% des mots du glossaire\"", style = MaterialTheme.typography.h3)
}
Column(
modifier = Modifier
.fillMaxSize() // Fills the maximum available width
.padding(16.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = "Le code contient ${comparerMots(motsGlossaire, motsCode)}% des mots du glossaire")
}
// Bouton retour positionné tout en bas et centré horizontalement
Column(
modifier = Modifier.fillMaxSize().padding(20.dp),
verticalArrangement = Arrangement.Bottom,
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(
onClick = onRetourClick,
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
)
) {
Text("Retour")
}
}
}
fun comparerMots(motsGlossaire: List<Mot>, motsCode: List<String>): Int {
var motsTrouves = 0
motsCode.forEach { motCode ->
motsGlossaire.forEach { mot ->
if (motCode.equals(mot.nom, ignoreCase = true)) {
motsTrouves++
}
}
}
println(motsTrouves*100/motsCode.size)
return motsTrouves*100/motsCode.size
}
var mostUsedWordList = mutableMapOf<String, Int>()
@Composable
@Preview
fun app() {
MaterialTheme {
val currentPage = remember { mutableStateOf("accueil") }
when (currentPage.value) {
"accueil" -> {
homePage(
@ -147,7 +221,7 @@ fun app() {
},
onJavaScriptClick = {
selectFile(jsExtensions) { filePath ->
parser(filePath) // Change by parser functions
mostUsedWordList = parser(filePath) // Change by parser functions
}
}
)

View File

@ -47,7 +47,7 @@ fun splitLanguages(file : String){
fun parser(fileName : String) {
fun parser(fileName : String) : MutableMap<String, Int> {
val delimiter1 = " "
val regex = "[^a-zA-Z^é^à]".toRegex()
val array = mutableListOf<String>()
@ -61,8 +61,10 @@ fun parser(fileName : String) {
}
val map = jsWords(array.groupingBy { it }.eachCount())
val sortedMap = map.toList().take(10).sortedBy { (_, value) -> value }.toMap()
var sortedMap = map.toList().take(10).sortedBy { (_, value) -> value }.toMap()
sortedMap.forEach() { (t, u) -> println("$t : $u") } // affiche le nombre d'occurence de chaque mot
sortedMap = sortedMap.toMutableMap()
return sortedMap
}