Cristiano Ronaldo SIUUU
parent
96135cfc40
commit
27e1f40741
|
@ -150,7 +150,7 @@ fun app() {
|
|||
},
|
||||
onJavaScriptClick = {
|
||||
selectFile(jsExtensions) { filePath ->
|
||||
println("JavaScript file selected: $filePath") // Change by parser functions
|
||||
parser(filePath) // Change by parser functions
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -163,8 +163,11 @@ fun app() {
|
|||
fun selectFile(extensions: Set<String>, onFileSelected: (String) -> Unit) {
|
||||
val fileDialog = FileDialog(Frame(), "Select a file", FileDialog.LOAD)
|
||||
fileDialog.isMultipleMode = false // To enable selecting only one file
|
||||
fileDialog.file = "*." + extensions.joinToString(";*.")
|
||||
fileDialog.isVisible = true
|
||||
|
||||
|
||||
|
||||
val selectedFile = fileDialog.file
|
||||
val selectedDirectory = fileDialog.directory
|
||||
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package main
|
||||
|
||||
import java.io.File
|
||||
|
||||
|
||||
fun delStrings(line : String) : String {
|
||||
val regex = "\".*?\"".toRegex()
|
||||
return regex.replace(line, "")
|
||||
}
|
||||
|
||||
fun takeOnlyJs(fileName: String): String {
|
||||
val extension = fileName.split(".")[1]
|
||||
if ("html" == extension){
|
||||
return File(fileName).readText().split("<script>")[1].split("</script>")[0]
|
||||
}
|
||||
return File(fileName).readText()
|
||||
}
|
||||
|
||||
fun jsWords(code : Map<String,Int>) : Map<String,Int>{
|
||||
val js = File("C:\\Users\\thoma\\Desktop\\sample.txt").readText().toString().split(",")
|
||||
|
||||
return code.filter { it.key !in js }
|
||||
}
|
||||
|
||||
fun splitLanguages(file : String){
|
||||
val extension = file.split(".")[1]
|
||||
if ("html" == extension) {
|
||||
val js = File(file).readText().split("<script>")[1].split("</script>")[0]
|
||||
val css = File(file).readText().split("<style>")[1].split("</style>")[0]
|
||||
val newHtml = File(file).readText().replace("<script>$js</script>", "<script src=\"javascript.js\"></script>")
|
||||
.replace("<style>$css</style>", "<link href=\"css.css\" rel=\"stylesheet\" />")
|
||||
|
||||
|
||||
if (js != "") {
|
||||
File("C:\\Users\\thoma\\Desktop\\test2\\javascript.js").writeText(js)
|
||||
}
|
||||
|
||||
if (newHtml != File(file).readText()) {
|
||||
File("C:\\Users\\thoma\\Desktop\\test2\\html.html").writeText(newHtml)
|
||||
}
|
||||
if (css != "") {
|
||||
File("C:\\Users\\thoma\\Desktop\\test2\\css.css").writeText(css)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun parser(fileName : String) {
|
||||
val delimiter1 = " "
|
||||
val regex = "[^a-zA-Z]".toRegex()
|
||||
val array = mutableListOf<String>()
|
||||
|
||||
val line = delStrings(takeOnlyJs(fileName)).toString().replace(regex, " ").toString()
|
||||
line.split(delimiter1).forEach {
|
||||
|
||||
if (it != "") {
|
||||
array.add(it)
|
||||
}
|
||||
}
|
||||
val map = jsWords(array.groupingBy { it }.eachCount())
|
||||
|
||||
val sortedMap = map.toList().take(10).sortedBy { (_, value) -> value }.toMap()
|
||||
sortedMap.forEach() { (t, u) -> println("$t : $u") } // affiche le nombre d'occurence de chaque mot
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue