Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion subprojects/generator-cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/>
* SPDX-FileCopyrightText: 2024-2026 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/
Expand All @@ -11,6 +11,7 @@ plugins {
dependencies {
implementation(project(":refinery-generator"))
implementation(libs.jcommander)
implementation(libs.gson)
implementation(libs.slf4j)
testRuntimeOnly(libs.slf4j.simple)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2024 The Refinery Authors <https://refinery.tools/>
* SPDX-FileCopyrightText: 2023-2026 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/
Expand All @@ -17,6 +17,9 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.FileWriter;

@Parameters(commandDescription = "Generate a model from a partial model")
public class GenerateCommand implements Command {
Expand All @@ -30,6 +33,7 @@ public class GenerateCommand implements Command {
private List<String> overrideScopes = new ArrayList<>();
private long randomSeed = 1;
private int count = 1;
private boolean outputJson;

@Inject
public GenerateCommand(CliProblemLoader loader, ModelGeneratorFactory generatorFactory,
Expand Down Expand Up @@ -72,6 +76,11 @@ public void setCount(int count) {
this.count = count;
}

@Parameter(names = {"-json", "-j"}, description = "Output as JSON")
public void setOutputJson(boolean outputJson) {
this.outputJson = outputJson;
}

@Override
public int run() throws IOException {
if (count > 1 && CliUtils.isStandardStream(outputPath)) {
Expand All @@ -83,16 +92,35 @@ public int run() throws IOException {
generator.setRandomSeed(randomSeed);
generator.setMaxNumberOfSolutions(count);
generator.generate();
if (count == 1) {
serializer.saveModel(generator, outputPath);
} else {
int solutionCount = generator.getSolutionCount();
for (int i = 0; i < solutionCount; i++) {
generator.loadSolution(i);
var pathWithIndex = CliUtils.getFileNameWithIndex(outputPath, i + 1);
serializer.saveModel(generator, pathWithIndex, false);
}
}
if (outputJson) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
if (count == 1) {
try (FileWriter writer = new FileWriter(outputPath)) {
gson.toJson(generator.getObjectNet(), writer);
}
} else {
int solutionCount = generator.getSolutionCount();
for (int i = 0; i < solutionCount; i++) {
generator.loadSolution(i);
var pathWithIndex = CliUtils.getFileNameWithIndex(outputPath, i + 1);
try (FileWriter writer = new FileWriter(pathWithIndex)) {
gson.toJson(generator.getObjectNet(), writer);
}
}
}
} else {
if (count == 1) {
serializer.saveModel(generator, outputPath);
} else {
int solutionCount = generator.getSolutionCount();
for (int i = 0; i < solutionCount; i++) {
generator.loadSolution(i);
var pathWithIndex = CliUtils.getFileNameWithIndex(outputPath, i + 1);
serializer.saveModel(generator, pathWithIndex, false);
}
}
}

}
return RefineryCli.EXIT_SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*
* SPDX-FileCopyrightText: 2023-2024 The Refinery Authors <https://refinery.tools/>
* SPDX-FileCopyrightText: 2023-2026 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/
package tools.refinery.generator;

import tools.refinery.generator.dto.ObjectNetDto;
import tools.refinery.language.model.problem.Problem;
import tools.refinery.language.semantics.ProblemTrace;
import tools.refinery.language.semantics.metadata.NodesMetadata;
Expand Down Expand Up @@ -48,6 +49,8 @@ <A extends AbstractValue<A, C>, C> PartialInterpretation<A, C> getPartialInterpr

ConsistencyCheckResult checkConsistency();

ObjectNetDto getObjectNet();

Problem serialize();

Optional<Problem> trySerialize();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* SPDX-FileCopyrightText: 2026 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/

package tools.refinery.generator.dto;

import java.util.ArrayList;
import java.util.List;

public class InstanceDto {
private final Integer id;
private final String name;
private final String principalType;
private final transient TypeDto principalTypeObject;
private final List<String> types = new ArrayList<>();
private final transient List<TypeDto> typeObjects = new ArrayList<>();
private final transient List<RelationInstanceDto> outgoingRelations = new ArrayList<>();
private final transient List<RelationInstanceDto> incomingRelations = new ArrayList<>();

public InstanceDto(Integer id, TypeDto principalType, String name) {
this.id = id;
this.name = name;
this.principalTypeObject = principalType;
this.principalType = principalType.getName();
}

public String getName() {
return name;
}

public Integer getId() {
return id;
}

public TypeDto getPrincipalTypeObject() {
return principalTypeObject;
}

public List<String> getTypes() {
return types;
}

public void addType(TypeDto type) {
typeObjects.add(type);
types.add(type.getName());
}

public void addTypes(List<TypeDto> types) {
for (TypeDto type : types) {
addType(type);
}
}

public List<RelationInstanceDto> getIncomingRelations() {
return incomingRelations;
}

public List<RelationInstanceDto> getOutgoingRelations() {
return outgoingRelations;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* SPDX-FileCopyrightText: 2026 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/

package tools.refinery.generator.dto;

import java.util.List;

public class ObjectNetDto {
private final List<TypeDto> types;
private final List<RelationTypeDto> relationTypes;
private final List<InstanceDto> instances;
private final List<RelationInstanceDto> relationInstances;

public ObjectNetDto(List<TypeDto> types, List<RelationTypeDto> relationTypes, List<InstanceDto> instances, List<RelationInstanceDto> relationInstances) {
this.types = types;
this.relationTypes = relationTypes;
this.instances = instances;
this.relationInstances = relationInstances;
}

public List<TypeDto> getTypes() {
return types;
}

public List<RelationTypeDto> getRelationTypes() {
return relationTypes;
}

public List<InstanceDto> getInstances() {
return instances;
}

public List<RelationInstanceDto> getRelationInstances() {
return relationInstances;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* SPDX-FileCopyrightText: 2026 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/

package tools.refinery.generator.dto;

import tools.refinery.store.reasoning.representation.PartialRelation;

public class RelationInstanceDto {

private final transient PartialRelation relation;
private final transient RelationTypeDto type;
private final transient InstanceDto source;
private final transient InstanceDto target;

private final String relationType;
private final Integer sourceId;
private final Integer targetId;

public RelationInstanceDto(PartialRelation relation, RelationTypeDto type, InstanceDto source, InstanceDto target) {
this.relation = relation;
this.type = type;
this.source = source;
this.target = target;
this.relationType = type.getName();
this.sourceId = source.getId();
this.targetId = target.getId();

source.getOutgoingRelations().add(this);
target.getIncomingRelations().add(this);
}

public RelationTypeDto getType() {
return type;
}

public InstanceDto getSource() {
return source;
}

public InstanceDto getTarget() {
return target;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* SPDX-FileCopyrightText: 2026 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/

package tools.refinery.generator.dto;

import tools.refinery.store.reasoning.representation.PartialRelation;

public class RelationTypeDto {

public enum Kind {
CONTAINMENT,
DIRECTED_CROSS_REF,
UNDIRECTED_CROSS_REF,
OPPOSITE
}

private final transient PartialRelation relation;
private final Kind kind;
private final String name;
private final transient TypeDto source;
private final transient TypeDto target;
private final String sourceName;
private final String targetName;

public RelationTypeDto(PartialRelation relation, Kind kind, String name, TypeDto source, TypeDto target) {
this.relation = relation;
this.kind = kind;
this.name = name.substring(name.lastIndexOf(":") + 1);
this.source = source;
this.target = target;
this.sourceName = source.getName();
this.targetName = target.getName();
}

public String getName() {
return name;
}

public TypeDto getSource() {
return source;
}

public TypeDto getTarget() {
return target;
}

public PartialRelation getRelation() {
return relation;
}

public Kind getKind() {
return kind;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* SPDX-FileCopyrightText: 2026 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/

package tools.refinery.generator.dto;

import tools.refinery.store.reasoning.representation.PartialRelation;

import java.util.ArrayList;
import java.util.List;

public class TypeDto {
private final transient PartialRelation relation;
private final String name;
private final List<String> superTypes = new ArrayList<>();
private final transient List<TypeDto> superTypeObjects = new ArrayList<>();
private final transient List<TypeDto> subTypeObjects = new ArrayList<>();

public TypeDto(PartialRelation relation, String name) {
this.relation = relation;
this.name = name;
}

public String getName() {
return name;
}

public PartialRelation getPartialRelation() {
return relation;
}

public List<String> getSuperTypes() {
return superTypes;
}

public List<TypeDto> getSuperTypeObjects() {
return superTypeObjects;
}

public void addSuperType(TypeDto type) {
superTypeObjects.add(type);
superTypes.add(type.getName());
}

public void addSubType(TypeDto type) {
subTypeObjects.add(type);
}
}
Loading
Loading