coordinates,
+ Number scale, Color fillColor, Color strokeColor, Color outsideColor) {
+ this.filename = filename;
+ this.label = label;
+ this.coordinates = coordinates;
+ this.scale = scale;
+ this.fillColor = fillColor;
+ this.strokeColor = strokeColor;
this.outsideColor = outsideColor;
}
}
-}
+
+ /**
+ * Describes a directed edge between two vertices identified by their
+ * zero-based index in the {@code entries} list.
+ *
+ * All fields except {@code fromIndex} and {@code toIndex} are optional.
+ * If no edges are provided in the source, the edge list stays empty
+ * and the edge DB table is never created, keeping full backward compatibility.
+ */
+ private static class Edge {
+ /** Source vertex — zero-based index into the {@code entries} list. */
+ private final int fromIndex;
+ /** Target vertex — zero-based index into the {@code entries} list. */
+ private final int toIndex;
+ /** Optional numeric weight / distance / cost associated with the edge. */
+ private final Number number;
+ /** Optional human-readable label shown alongside the edge. */
+ private final String label;
+ /** Display color of the edge line; defaults to {@link Color#GRAY}. */
+ private final Color color;
+ /** Source filename — kept for traceability in the DB. */
+ private final String filename;
+
+ private Edge(String filename, int fromIndex, int toIndex,
+ Number number, String label, Color color) {
+ this.filename = filename;
+ this.fromIndex = fromIndex;
+ this.toIndex = toIndex;
+ this.number = number;
+ this.label = label;
+ this.color = color;
+ }
+ }
+
+ private record PointData(double x, double y) {}
+}
\ No newline at end of file
diff --git a/src/main/java/org/texttechnologylab/udav/generators/TextFormatting.java b/src/main/java/org/texttechnologylab/udav/generators/TextFormatting.java
index 3de9f870..f2b892ff 100644
--- a/src/main/java/org/texttechnologylab/udav/generators/TextFormatting.java
+++ b/src/main/java/org/texttechnologylab/udav/generators/TextFormatting.java
@@ -73,7 +73,7 @@ public void setup_step1() throws SQLException {
SourceUIMA sourceUIMA = (SourceUIMA) source;
this.UIMAsofaID = settings.getStringSettingOrDefault("sofaID", null);
String sofaFile = settings.getStringSettingOrDefault("sofaFile", null);
- if (sofaFile == null) {
+ if (sofaFile == null || sofaFile.isBlank()) {
Set allFiles = sourceUIMA.determineAllSourceFiles();
settings.defineFilterListUniversalSetString("files", allFiles);
FilterList filterListSourceFiles = settings.generateStringFilterList("files");
@@ -181,6 +181,12 @@ public void writeToDB() throws SQLException {
Field END_SEGS = DSL.field(DSL.name(schema, DBConstants.TABLENAME_GENERATORDATA_TYPESEGMENTS, DBConstants.TABLEATTR_GENERATORDATA_END), Integer.class);
Field CAT_SEGS = DSL.field(DSL.name(schema, DBConstants.TABLENAME_GENERATORDATA_TYPESEGMENTS, DBConstants.TABLEATTR_GENERATORDATA_CATEGORY), String.class);
+ // Replace previous rows for this generator to keep saves idempotent.
+ dsl.deleteFrom(T_SEGS).where(GID_SEGS.eq(id)).execute();
+ dsl.deleteFrom(T_COLOR).where(GID_COLOR.eq(id)).execute();
+ dsl.deleteFrom(T_STYLE).where(GID_STYLE.eq(id)).execute();
+ dsl.deleteFrom(T_TEXT).where(GID_TEXT.eq(id)).execute();
+
// ---------- Insert text ----------
dsl.insertInto(T_TEXT)
.columns(GID_TEXT, TXT_TEXT)
diff --git a/src/main/java/org/texttechnologylab/udav/generators/sources/SourceJson.java b/src/main/java/org/texttechnologylab/udav/generators/sources/SourceJson.java
index db8968bc..db5100b3 100644
--- a/src/main/java/org/texttechnologylab/udav/generators/sources/SourceJson.java
+++ b/src/main/java/org/texttechnologylab/udav/generators/sources/SourceJson.java
@@ -4,11 +4,18 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
+import org.jooq.DSLContext;
+import org.jooq.Field;
+import org.jooq.Table;
+import org.jooq.impl.DSL;
+import org.texttechnologylab.udav.db.SchemaObjectNames;
import org.texttechnologylab.udav.generators.settings.GeneratorSettings;
import org.texttechnologylab.udav.pipeline.JSONView;
+import org.texttechnologylab.udav.sources.DBAccess;
import java.io.IOException;
-import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -23,9 +30,9 @@ public class SourceJson extends Source {
protected final JSONView singleFileJSONView;
protected final Map filenameToJsonView; // TODO: Use or remove
- public SourceJson(String filepath) throws IOException {
+ public SourceJson(String filepath, DBAccess dbAccess) throws IOException, SQLException {
this.singleFileName = SOURCE_FILES_PATH + "/" + filepath.trim();
- this.singleFileJSONView = readJsonViewFromFile(singleFileName);
+ this.singleFileJSONView = readJsonViewFromDB(singleFileName, dbAccess);
this.filenameToJsonView = null;
}
public SourceJson(String normalizedFilepath, JSONView jsonView) {
@@ -49,6 +56,25 @@ public List