Skip to content

Commit

Permalink
Merge pull request #9 from Paulanerus/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Paulanerus authored Jan 29, 2025
2 parents 4254f44 + 0501483 commit f5cc5fb
Show file tree
Hide file tree
Showing 36 changed files with 1,335 additions and 533 deletions.
91 changes: 79 additions & 12 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ align with the project's overall setup.
local dependency:

```kotlin
implementation(files("libs/api-0.32.2.jar"))
implementation(files("libs/api-0.40.2.jar"))
```

4. Reload the Gradle project.
Expand All @@ -27,14 +27,15 @@ To create your first plugin, follow these steps:

```kotlin
class PluginMain : IPlugin {
override fun init() {
override fun init(storageProvider: IStorageProvider) {
println("Hello world from plugin.")
}
}
```

The `init` function is executed when the application starts or the plugin is loaded via the interface. Use this function
to initialize external services or perform setup tasks.
to initialize external services or perform setup tasks. The StorageProvider instance can be used to access imported
data.

2. Annotate the class with `@PluginMetadata` to declare the plugin's metadata. You can include additional information
like the version, author, or a short description.
Expand Down Expand Up @@ -163,20 +164,78 @@ class PluginMain : IPlugin {
This setup allows the user to search for `@countries:USA`, and TextExplorer will return all entries that match any of
the variants declared for "USA."

## Pre filtering

Pre-filters can be used to select objects matching a condition before searching with the initial query. For this
purpose, a data class needs to be annotated with `@PreFilter` and must have a link to another class that stores
additional
information. One can say a pre-filter acts on datasets, resembling a bridge between two data sets.

An example could be a set of entries where information is stored indicating whether a quote contains certain words:

**occurrence.csv**

```text
quote_id,occurrence,word_id
77,false,12
78,true,12
```

**words.csv**

```text
word_id,word,type
12,House,Noun
```

**quotes.csv**

```text
quote_id,quote,author
...
77,...,...
78,...,...
...
```

For this example a reference implementation would look like this:

```kotlin
@PreFilter(key = "quote_id", linkKey = "type", value = "occurrence")
@DataSource("occurrences")
data class Occurrence(val quote_id: Long, val occurrence: Int, @Link(Word::class) val word_id: Int)

@DataSource("words")
data class Word(val word_id: Long, val word: String, val type: String)

@DataSource("quotes")
data class Quote(@Unique(true) val quote_id: Long, @Index(Language.ENGLISH) val quote: String, val author: String)
```

`@PreFilter` has three parameters: key, linkKey, and value. The key field must match the identifier of a class that has a
field marked with `@Index`, which will be used to retrieve the actual objects. linkKey determines the column for the first
value in the request and must match a field from the linked class (e.g., Word in this example). The last parameter,
value, specifies the column in the pre-filter dataset.

A query for this example would look like this: `@occurrences:Noun:false`. This query would return the quote with the
quote_id 77.

## Tagging API

The Tagging API allows you to highlight specific words (e.g., names) within the Tagging View.

To implement this functionality, simply implement the tag function from the Taggable interface in your Plugin Main class.
To implement this functionality, simply implement the tag function from the Taggable interface in your Plugin Main
class.
This function takes the field name and its corresponding value as parameters.

Additionally, annotate the function with `@ViewFilter`, which specifies a filter name and the fields it accepts.
Additionally, annotate the function with `@ViewFilter`, which specifies a filter name and the fields it accepts. The
alwaysShow field can be used to make certain columns always visible
Optionally, you can use the global parameter to apply the tags to the DiffView.

To highlight the name "Tom" in every field, the implementation would look like this:

```kotlin
@ViewFilter("Name Highlighter", fields = ["quote"], global = true)
@ViewFilter("Name Highlighter", fields = ["quote"], alwaysShow = ["author_id"], global = true)
override fun tag(field: String, value: String): Map<String, Tag> = mapOf("Tom" to Tag("NAME", Color.blue))
```

Expand All @@ -186,13 +245,21 @@ In this example:
+ The word "Tom" is mapped to the Tag with the identifier `NAME` and the color blue.
+ Every occurrence of "Tom" in the quote field will be highlighted in blue.

## Pre filtering
## Drawable

The Drawable interface allows you to extend the user interface of your application. Since UI extension capabilities vary
based on the UI framework in use, this interface does not include any pre-defined functions. However, when using the
standard UI implementation with Compose, the UI will invoke functions like:

**Not yet implemented**
````kotlin
fun composeContent(entries: List<Map<String, String>>): @Composable () -> Unit = {
//Compose components
}
````

## Access plugin data
to extend the user interface.

**Not yet implemented**
**Important:** The Drawable interface and the exact structure of the function are required.

## Export plugin

Expand All @@ -218,11 +285,11 @@ gradlew.bat jar
@PluginMetadata("demo", author = "Author", version = "1.0.0", description = "A short description.")
class PluginMain : IPlugin, Taggable {

override fun init() {
override fun init(storageProvider: IStorageProvider) {
println("Hello world from plugin.")
}

@ViewFilter("Name Highlighter", fields = ["quote"], global = true)
@ViewFilter("Name Highlighter", fields = ["quote"], alwaysShow = ["author_id"], global = true)
override fun tag(field: String, value: String): Map<String, Tag> = mapOf("Tom" to Tag("NAME", Color.blue))
}
```
Expand Down
5 changes: 0 additions & 5 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ repositories {

dependencies {
implementation(kotlin("stdlib"))

testImplementation(kotlin("test"))
}

tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(21)
}
5 changes: 3 additions & 2 deletions api/src/main/kotlin/dev/paulee/api/data/Data.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.paulee.api.data

import dev.paulee.api.data.provider.StorageType
import kotlin.reflect.KClass

enum class Language {
Expand Down Expand Up @@ -55,7 +56,7 @@ annotation class Variant(val base: String, val variants: Array<String>)
annotation class PreFilter(val key: String, val linkKey: String, val value: String)

@Target(AnnotationTarget.CLASS)
annotation class RequiresData(val name: String, val sources: Array<KClass<*>> = [])
annotation class RequiresData(val name: String, val sources: Array<KClass<*>> = [], val storage: StorageType = StorageType.SQLITE)

@Target(AnnotationTarget.CLASS)
annotation class DataSource(val file: String)
Expand All @@ -73,4 +74,4 @@ annotation class NullValue(val values: Array<String>)
annotation class Link(val clazz: KClass<*>)

@Target(AnnotationTarget.FUNCTION)
annotation class ViewFilter(val name: String, val fields: Array<String>, val global: Boolean = true)
annotation class ViewFilter(val name: String, val fields: Array<String> = [], val alwaysShow: Array<String> = [], val global: Boolean = true)
2 changes: 1 addition & 1 deletion api/src/main/kotlin/dev/paulee/api/data/DiffService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ data class Change(val str: String, val tokens: List<Pair<String, IntRange>>)

interface DiffService {

fun getDiff(strings: List<String>): Set<Change>
fun getDiff(strings: List<String>): List<Change>

fun getDiff(original: String, str: String): Change?

Expand Down
3 changes: 3 additions & 0 deletions api/src/main/kotlin/dev/paulee/api/data/IDataService.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.paulee.api.data

import dev.paulee.api.data.provider.IStorageProvider
import java.io.Closeable
import java.nio.file.Path

Expand All @@ -20,4 +21,6 @@ interface IDataService : Closeable {
fun getPage(query: String, pageCount: Int): Pair<List<Map<String, String>>, Map<String, List<Map<String, String>>>>

fun getPageCount(query: String): Pair<Long, Set<String>>

fun createStorageProvider(dataInfo: RequiresData, path: Path): IStorageProvider?
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import java.nio.file.Path

enum class StorageType {
SQLITE,
BINARY,
}

interface IStorageProvider : Closeable {

fun init(dataInfo: RequiresData, path: Path): Int
fun init(dataInfo: RequiresData, path: Path, lock: Boolean = false): Int

fun insert(name: String, entry: List<Map<String, String>>)

Expand Down
11 changes: 7 additions & 4 deletions api/src/main/kotlin/dev/paulee/api/plugin/IPluginService.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.paulee.api.plugin

import dev.paulee.api.data.IDataService
import dev.paulee.api.data.RequiresData
import dev.paulee.api.data.ViewFilter
import java.nio.file.Path
Expand All @@ -8,21 +9,23 @@ interface IPluginService {

fun loadFromDirectory(path: Path): Int

fun loadPlugin(path: Path, init: Boolean = false): IPlugin?
fun loadPlugin(path: Path): IPlugin?

fun getPluginMetadata(plugin: IPlugin): PluginMetadata?

fun getDataInfo(plugin: IPlugin): RequiresData?

fun initAll()
fun initAll(dataService: IDataService, path: Path)

fun getPlugins(): List<IPlugin>

fun getAllDataInfos(): Set<RequiresData>

fun getDataSources(dataInfo: String): Set<String>

fun tagFields(plugin: IPlugin, field: String, value: String): Map<String, Tag>

fun getViewFilter(plugin: IPlugin): ViewFilter?

fun getVariants(dataInfo: RequiresData?): Set<String>

fun getPreFilters(dataInfo: RequiresData?): Set<String>
}
9 changes: 6 additions & 3 deletions api/src/main/kotlin/dev/paulee/api/plugin/Plugin.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.paulee.api.plugin

import dev.paulee.api.data.provider.IStorageProvider
import java.awt.Color

@Target(AnnotationTarget.CLASS)
Expand All @@ -8,17 +9,19 @@ annotation class PluginOrder(val order: Int)
@Target(AnnotationTarget.CLASS)
annotation class PluginMetadata(
val name: String,
val version: String = "",
val version: String,
val author: String = "",
val description: String = "",
)

interface IPlugin {
fun init()
fun init(storageProvider: IStorageProvider)
}

data class Tag(val name: String, val color: Color)

interface Taggable {
fun tag(field: String, value: String): Map<String, Tag>
}
}

interface Drawable
6 changes: 0 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ dependencies {
implementation(project(":api"))
implementation(project(":core"))
implementation(project(":ui"))

testImplementation(kotlin("test"))
}

tasks.test {
useJUnitPlatform()
}

kotlin {
Expand Down
2 changes: 2 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ dependencies {
implementation("org.apache.lucene:lucene-analysis-nori:${rootProject.extra["lucene.version"]}")
implementation("org.apache.lucene:lucene-analysis-morfologik:${rootProject.extra["lucene.version"]}")
implementation("org.apache.lucene:lucene-queryparser:${rootProject.extra["lucene.version"]}")
implementation("org.apache.lucene:lucene-backward-codecs:${rootProject.extra["lucene.version"]}")

testImplementation(kotlin("test"))
}

tasks.test {
useJUnitPlatform()
}

kotlin {
jvmToolchain(21)
}
Loading

0 comments on commit f5cc5fb

Please sign in to comment.