starting with project/corpus
parent
4ae5c3bf58
commit
e4bae5aa45
|
|
@ -0,0 +1,12 @@
|
||||||
|
package de.itkl.assetmanager
|
||||||
|
|
||||||
|
import de.itkl.assetmanager.implementation.FilesystemAssetManager
|
||||||
|
import de.itkl.assetmanager.implementation.FilesystemProjectManager
|
||||||
|
import de.itkl.assetmanager.interfaces.AssetManager
|
||||||
|
import de.itkl.assetmanager.interfaces.ProjectManager
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
val assetManagerModule = module {
|
||||||
|
single<ProjectManager> { FilesystemProjectManager() }
|
||||||
|
single<AssetManager> { FilesystemAssetManager() }
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
package de.itkl.assetmanager.implementation
|
||||||
|
|
||||||
|
import de.itkl.assetmanager.interfaces.AssetManager
|
||||||
|
import de.itkl.assetmanager.interfaces.Assets
|
||||||
|
import de.itkl.assetmanager.interfaces.Project
|
||||||
|
import de.itkl.assetmanager.interfaces.ProjectManager
|
||||||
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import org.koin.core.component.inject
|
||||||
|
import java.nio.file.Paths
|
||||||
|
import kotlin.io.path.isDirectory
|
||||||
|
import kotlin.io.path.isRegularFile
|
||||||
|
import kotlin.io.path.listDirectoryEntries
|
||||||
|
|
||||||
|
private val Log = KotlinLogging.logger { }
|
||||||
|
|
||||||
|
class FilesystemProjectManager : ProjectManager {
|
||||||
|
override suspend fun load(name: String): Project {
|
||||||
|
val path = Paths.get(name)
|
||||||
|
check(path.isDirectory()) {
|
||||||
|
"Currently only directories as corpora are supported"
|
||||||
|
}
|
||||||
|
val documents =
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
path.listDirectoryEntries()
|
||||||
|
.filter { it.isRegularFile() }
|
||||||
|
.map { it.toAbsolutePath() }
|
||||||
|
.map { it.toString() }
|
||||||
|
}
|
||||||
|
return FilesystemProject(
|
||||||
|
name = name,
|
||||||
|
displayName = path.fileName.toString(),
|
||||||
|
documentNames = documents)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FilesystemProject(
|
||||||
|
override val name: String,
|
||||||
|
override val displayName: String,
|
||||||
|
override val documentNames: List<String>
|
||||||
|
) : Project, KoinComponent {
|
||||||
|
|
||||||
|
private val assetManager: AssetManager by inject()
|
||||||
|
override suspend fun assetsOf(documentName: String): Assets {
|
||||||
|
return assetManager.assets(documentName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
package de.itkl.assetmanager.interfaces
|
package de.itkl.assetmanager.interfaces
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manage the assets for one document
|
||||||
|
*/
|
||||||
interface AssetManager {
|
interface AssetManager {
|
||||||
suspend fun assets(name: String): Assets
|
suspend fun assets(name: String): Assets
|
||||||
suspend fun delete(name: String)
|
suspend fun delete(name: String)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package de.itkl.assetmanager.interfaces
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A set of documents. Each can hold its own assets
|
||||||
|
*/
|
||||||
|
interface Project {
|
||||||
|
val name: String
|
||||||
|
val displayName: String
|
||||||
|
val documentNames: List<String>
|
||||||
|
suspend fun assetsOf(documentName: String): Assets
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package de.itkl.assetmanager.interfaces
|
||||||
|
|
||||||
|
interface ProjectManager {
|
||||||
|
suspend fun load(name: String): Project
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ dependencies {
|
||||||
api(project(":libraries:core-api"))
|
api(project(":libraries:core-api"))
|
||||||
api("org.apache.lucene:lucene-analysis-common:9.9.0")
|
api("org.apache.lucene:lucene-analysis-common:9.9.0")
|
||||||
api("io.github.piruin:geok:1.2.2")
|
api("io.github.piruin:geok:1.2.2")
|
||||||
|
api(project(":libraries:assetmanager"))
|
||||||
implementation("com.github.doyaaaaaken:kotlin-csv-jvm:1.9.2")
|
implementation("com.github.doyaaaaaken:kotlin-csv-jvm:1.9.2")
|
||||||
implementation("com.google.guava:guava:32.1.3-jre")
|
implementation("com.google.guava:guava:32.1.3-jre")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package de.itkl.textprocessing
|
||||||
|
|
||||||
|
import de.itkl.assetmanager.interfaces.Project
|
||||||
|
import de.itkl.assetmanager.interfaces.ProjectManager
|
||||||
|
import de.itkl.core_api.interfaces.FileProcessor
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import org.koin.core.component.inject
|
||||||
|
import org.koin.java.KoinJavaComponent.inject
|
||||||
|
|
||||||
|
|
||||||
|
class CorpusFactory : KoinComponent {
|
||||||
|
private val projectManager: ProjectManager by inject()
|
||||||
|
suspend fun load(name: String): Corpus {
|
||||||
|
return Corpus(projectManager.load(name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Corpus(private val project: Project) : KoinComponent {
|
||||||
|
val displayName get() = project.displayName
|
||||||
|
val documentNames get() = project.documentNames
|
||||||
|
|
||||||
|
suspend fun process(fileProcessor: FileProcessor) {
|
||||||
|
TODO("NEXT")
|
||||||
|
}
|
||||||
|
suspend fun document(name: String): Document {
|
||||||
|
TODO()
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue