All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.zone.cogni.semanticz.shaclviz.export.TgfExporter.kt Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
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