Add Kotlin parsing
parent
1b775e06d4
commit
e87a25e7a2
|
@ -26,6 +26,8 @@ import java.io.File
|
|||
import java.io.FileInputStream
|
||||
import java.io.FileWriter
|
||||
import java.io.IOException
|
||||
import javax.swing.JFileChooser
|
||||
import javax.swing.filechooser.FileSystemView
|
||||
|
||||
|
||||
data class Glossary(val name: String, val jsonFilePath: String)
|
||||
|
@ -354,6 +356,21 @@ fun selectFile(extensions: Set<String>, onFileSelected: (String) -> Unit) {
|
|||
frame.dispose()
|
||||
}
|
||||
|
||||
|
||||
fun selectDirectory(onDirectorySelected: (String) -> Unit) {
|
||||
val fileChooser = JFileChooser(FileSystemView.getFileSystemView().homeDirectory)
|
||||
fileChooser.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY
|
||||
|
||||
val returnValue = fileChooser.showDialog(null, "Select")
|
||||
if (returnValue == JFileChooser.APPROVE_OPTION) {
|
||||
val selectedDirectory = fileChooser.selectedFile.absolutePath
|
||||
println("Selected directory: $selectedDirectory")
|
||||
onDirectorySelected(selectedDirectory)
|
||||
} else {
|
||||
println("Open command cancelled by user.")
|
||||
}
|
||||
}
|
||||
|
||||
fun exportToCSV(glossary: Glossary, csvFilePath: String) {
|
||||
val glossary = loadDatasFromFile(glossary.jsonFilePath)
|
||||
val csvContent = buildString {
|
||||
|
|
|
@ -10,7 +10,6 @@ import androidx.compose.ui.graphics.Color
|
|||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.*
|
||||
import main.AppState.selectedGlossary
|
||||
import java.awt.FileDialog
|
||||
import java.awt.Frame
|
||||
import java.io.File
|
||||
|
@ -182,6 +181,13 @@ fun app() {
|
|||
choixLangagePage(
|
||||
languageManager,
|
||||
onBackClick = { currentPage.value = "accueil" },
|
||||
onKotlinClick = {
|
||||
selectDirectory() { onDirectorySelected ->
|
||||
mostUsedWordList = directoryParse(onDirectorySelected) // Change by parser functions
|
||||
println("Kotlin directory selected: $onDirectorySelected")
|
||||
currentPage.value = "occurrence"
|
||||
}
|
||||
},
|
||||
onPythonClick = {
|
||||
selectFile(pythonExtensions) { filePath ->
|
||||
println("Python file selected: $filePath") // Change by parser functions
|
||||
|
@ -194,7 +200,7 @@ fun app() {
|
|||
},
|
||||
onJavaScriptClick = {
|
||||
selectFile(jsExtensions) { filePath ->
|
||||
mostUsedWordList = parser(filePath) // Change by parser functions
|
||||
mostUsedWordList = parserJS(filePath) // Change by parser functions
|
||||
isJavaScriptFileSelected = true
|
||||
}
|
||||
},
|
||||
|
|
|
@ -16,6 +16,7 @@ import main.component.dropdownButtonComponent
|
|||
fun choixLangagePage(
|
||||
languageManager: LanguageManager,
|
||||
onBackClick: () -> Unit,
|
||||
onKotlinClick: () -> Unit,
|
||||
onPythonClick: () -> Unit,
|
||||
onJavaClick: () -> Unit,
|
||||
onJavaScriptClick: () -> Unit,
|
||||
|
@ -42,6 +43,19 @@ fun choixLangagePage(
|
|||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
|
||||
) {
|
||||
Button(
|
||||
onClick = onKotlinClick,
|
||||
modifier = Modifier
|
||||
.width(150.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
),
|
||||
enabled = true
|
||||
) {
|
||||
Text("Kotlin")
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onPythonClick,
|
||||
modifier = Modifier
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package main
|
||||
|
||||
import androidx.compose.ui.text.toLowerCase
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
|
||||
fun delStrings(line : String) : String {
|
||||
|
@ -45,11 +43,13 @@ fun splitLanguages(file : String){
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun parser(fileName : String) : MutableMap<String, Int> {
|
||||
fun parserJS(fileName : String) : MutableMap<String, Int> {
|
||||
val delimiter1 = " "
|
||||
val regex = "[^a-zA-Z^éà]".toRegex()
|
||||
val array = mutableListOf<String>()
|
||||
|
@ -70,3 +70,41 @@ fun parser(fileName : String) : MutableMap<String, Int> {
|
|||
|
||||
}
|
||||
|
||||
fun ktWords(code : Map<String,Int>) : Map<String,Int>{
|
||||
val js = File("src/main/kotlin/main/sampleKt.txt").readText().split(",")
|
||||
|
||||
return code.filter { it.key !in js }
|
||||
}
|
||||
fun parserKt(fileName : String) : MutableMap<String, Int> {
|
||||
val delimiter1 = " "
|
||||
val regex = "[^a-zA-Z^éà]".toRegex()
|
||||
val array = mutableListOf<String>()
|
||||
|
||||
val line = delStrings(File(fileName).readText()).replace(regex, " ")
|
||||
line.split(delimiter1).forEach {
|
||||
|
||||
if (it != "") {
|
||||
array.add(it)
|
||||
}
|
||||
}
|
||||
val map = ktWords(array.groupingBy { it }.eachCount())
|
||||
|
||||
return map.toMutableMap()
|
||||
}
|
||||
|
||||
|
||||
fun directoryParse(directory : String) : MutableMap<String, Int> {
|
||||
val files = File(directory).walk().filter { it.isFile }.toList()
|
||||
val map = mutableMapOf<String, Int>()
|
||||
files.forEach {
|
||||
|
||||
|
||||
if (it.extension == "kt" && it.toString().contains("bin") == false) {
|
||||
println(it.absolutePath)
|
||||
val map2 = parserKt(it.toString())
|
||||
map2.forEach { (t, u) -> map[t] = map.getOrDefault(t, 0) + u }
|
||||
}
|
||||
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
androidx,abstract,actual,annotation,anonymous,apply,as,as?,assert,break,by,byte,catch,char,class,companion,const,constructor,continue,crossinline,data,delegate,do,double,dynamic,else,enum,expect,external,false,field,file,final,finally,float,for,fun,get,if,implements,import,in,infix,init,inline,inner,interface,internal,is,it,lateinit,long,module,native,new,noinline,null,object,open,operator,out,override,package,private,protected,public,receiver,reified,return,sealed,set,short,super,suspend,tailrec,this,throw,true,try,typealias,typeof,val,var,vararg,when,where,while,abstract,actual,annotation,anonymous,apply,as,as?,assert,break,by,byte,catch,char,class,companion,const,constructor,continue,crossinline,data,delegate,do,double,dynamic,else,enum,expect,external,false,field,file,final,finally,float,for,fun,get,if,implements,import,in,infix,init,inline,inner,interface,internal,is,it,lateinit,long,module,native,new,noinline,null,object,open,operator,out,override,package,private,protected,public,receiver,reified,return,sealed,set,short,super,suspend,tailrec,this,throw,true,try,typealias,typeof,val,var,vararg,when,where,while,AccessibleObject,BitSet,Calendar,Date,GregorianCalendar,Locale,Objects,Observable,Optional,Random,Timer,TimeZone,UUID,Vector,AbstractCollection,AbstractList,AbstractMap,AbstractQueue,AbstractSequentialList,AbstractSet,ArrayList,Arrays,Base64,Calendar,Collections,Comparator,Date,DateFormat,DateFormatSymbols,DecimalFormat,EnumMap,EnumSet,GregorianCalendar,HashMap,HashSet,Hashtable,IdentityHashMap,LinkedHashMap,LinkedHashSet,LinkedList,ListResourceBundle,Locale,Objects,Observable,Optional,PriorityQueue,Properties,PropertyPermission,Random,ResourceBundle,Scanner,SimpleTimeZone,Stack,StringTokenizer,Timer,TimeZone,TreeMap,TreeSet,UUID,Vector,WeakHashMap,AssertionError,Exception,RuntimeException,ArithmeticException,ArrayIndexOutOfBoundsException,ClassCastException,ClassNotFoundException,CloneNotSupportedException,EnumConstantNotPresentException,IllegalAccessException,IllegalArgumentException,IllegalMonitorStateException,IllegalStateException,IllegalThreadStateException,IndexOutOfBoundsException,InstantiationException,InterruptedException,NegativeArraySizeException,NoSuchFieldException,NoSuchMethodException,NullPointerException,NumberFormatException,ReflectiveOperationException,SecurityException,StringIndexOutOfBoundsException,TypeNotPresentException,UnsupportedOperationException
|
|
@ -63,11 +63,11 @@ class ParserTest {
|
|||
val puissance4File = "src/test/resources/puissance4.html"
|
||||
|
||||
// Call the parser function
|
||||
parser(puissance4File)
|
||||
parserJS(puissance4File)
|
||||
|
||||
// Verify the output by capturing the printed content
|
||||
val printedContent = captureStandardOutput {
|
||||
parser(puissance4File)
|
||||
parserJS(puissance4File)
|
||||
}
|
||||
|
||||
// Assert the expected output based on the content of your sample HTML file
|
||||
|
|
Loading…
Reference in New Issue