
main.zone.cogni.semanticz.shaclviz.export.TgfExporter.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of semanticz-shaclviz Show documentation
Show all versions of semanticz-shaclviz Show documentation
A tool to create flexible SHACL diagrams in PlantUML or yEd
package zone.cogni.semanticz.shaclviz.export
import zone.cogni.semanticz.shaclviz.model.*
import java.io.Writer
/**
* Representation of a data model class.
*/
class TgfExporter : Exporter {
private fun renderField(field: Map.Entry): String {
return "${field.key.name}: ${field.value.cls.name} ${countInfo(field.value.min, field.value.max)} "
}
private fun countInfo(minCount: Int, maxCount: String) =
if (minCount != 0 || maxCount != "*") "[${minCount},${maxCount}]" else ""
private fun render(cls: Type) =
"${cls.name}
${
if (cls.fields.isNotEmpty()) {
"${cls.fields.toSortedMap(compareBy { it.name }).map { renderField(it) }.joinToString("")}
"
} else ""
}"
override fun export(graph: Graph, writer: Writer, hideOrphanNodes: Boolean) {
val result = graph.nodes
.filter { n -> !hideOrphanNodes || n.fields.isNotEmpty() || graph.ins(n).isNotEmpty() || graph.outs(n).isNotEmpty() }
.mapIndexed { index, c ->
"${index + 1} ${render(c)}"
}.joinToString(separator = "\n") + "\n" + "#\n" +
graph.edges.joinToString(separator = "\n") { e: Constraint ->
val propertyName =
"${e.propertyName} ${countInfo(e.minCount!!, e.maxCount!!)}"
"${graph.classIndex(e.classIri)} ${graph.classIndex(e.rangeIri?:"")} $propertyName"
}
writer.write(result)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy