mirror of
https://github.com/slhaf/Partner.git
synced 2026-06-28 01:59:17 +08:00
feat(impression): Add ActiveEntity to support runtime entity-discovering and block production
This commit is contained in:
@@ -0,0 +1,70 @@
|
|||||||
|
package work.slhaf.partner.core.cognition.impression
|
||||||
|
|
||||||
|
import org.w3c.dom.Document
|
||||||
|
import org.w3c.dom.Element
|
||||||
|
import work.slhaf.partner.core.cognition.context.BlockContent
|
||||||
|
import java.util.concurrent.atomic.AtomicReference
|
||||||
|
|
||||||
|
class ActiveEntity @JvmOverloads constructor(
|
||||||
|
timestamp: Long = System.currentTimeMillis(),
|
||||||
|
private val _evidences: MutableList<String> = mutableListOf(),
|
||||||
|
) : BlockContent("active_entity_$timestamp", "impression") {
|
||||||
|
val evidences: List<String> get() = _evidences
|
||||||
|
|
||||||
|
private val _subject = AtomicReference("UNKNOWN")
|
||||||
|
val subject: String get() = _subject.get()
|
||||||
|
|
||||||
|
private val _projectedFeatures: MutableMap<String, Double> = mutableMapOf()
|
||||||
|
val projectedFeatures: Map<String, Double> get() = _projectedFeatures
|
||||||
|
|
||||||
|
private val _projectedImpressions: MutableMap<String, Double> = mutableMapOf()
|
||||||
|
val projectedImpressions: Map<String, Double> get() = _projectedImpressions
|
||||||
|
|
||||||
|
fun addEvidence(evidence: String) = synchronized(_evidences) {
|
||||||
|
_evidences.add(evidence)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateSubject(subject: String) = _subject.set(subject)
|
||||||
|
|
||||||
|
fun addProjectedFeatures(vararg features: Pair<String, Double>) = synchronized(_projectedFeatures) {
|
||||||
|
features.forEach { _projectedFeatures[it.first] = it.second }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addProjectedImpressions(vararg impressions: Pair<String, Double>) = synchronized(_projectedImpressions) {
|
||||||
|
impressions.forEach { _projectedImpressions[it.first] = it.second }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun fillXml(document: Document, root: Element) {
|
||||||
|
appendTextElement(document, root, "subject", subject)
|
||||||
|
|
||||||
|
appendListElement(
|
||||||
|
document,
|
||||||
|
root,
|
||||||
|
"evidences",
|
||||||
|
"evidence",
|
||||||
|
synchronized(_evidences) { _evidences.toList() }
|
||||||
|
)
|
||||||
|
|
||||||
|
appendListElement(
|
||||||
|
document,
|
||||||
|
root,
|
||||||
|
"projected_features",
|
||||||
|
"feature",
|
||||||
|
synchronized(_projectedFeatures) { _projectedFeatures.entries.toList() }
|
||||||
|
) { entry ->
|
||||||
|
setAttribute("confidence", entry.value.toString())
|
||||||
|
textContent = entry.key
|
||||||
|
}
|
||||||
|
|
||||||
|
appendListElement(
|
||||||
|
document,
|
||||||
|
root,
|
||||||
|
"projected_impressions",
|
||||||
|
"impression",
|
||||||
|
synchronized(_projectedImpressions) { _projectedImpressions.entries.toList() }
|
||||||
|
) { entry ->
|
||||||
|
setAttribute("confidence", entry.value.toString())
|
||||||
|
textContent = entry.key
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import kotlin.concurrent.withLock
|
|||||||
|
|
||||||
class Entity @JvmOverloads constructor(
|
class Entity @JvmOverloads constructor(
|
||||||
val uuid: String = UUID.randomUUID().toString(),
|
val uuid: String = UUID.randomUUID().toString(),
|
||||||
|
private val subject: String,
|
||||||
private val relations: MutableMap<String, MutableMap<String, Double>> = mutableMapOf(),
|
private val relations: MutableMap<String, MutableMap<String, Double>> = mutableMapOf(),
|
||||||
private val impressions: MutableMap<String, IndexableData> = mutableMapOf(),
|
private val impressions: MutableMap<String, IndexableData> = mutableMapOf(),
|
||||||
private val features: MutableMap<String, IndexableData> = mutableMapOf()
|
private val features: MutableMap<String, IndexableData> = mutableMapOf()
|
||||||
|
|||||||
Reference in New Issue
Block a user