import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
import org.simantics.databoard.binding.Binding;
import org.simantics.databoard.binding.mutable.Variant;
import org.simantics.databoard.container.DataContainer;
import org.simantics.databoard.container.DataContainers;
+import org.simantics.graph.representation.PrettyPrintTG;
import org.simantics.graph.representation.TransferableGraph1;
/**
*/
public class FixExportedOntology {
- static void convertExportedSharedOntologyIntoBundleOntology(Path input, Path output) throws Exception {
+ static TransferableGraph1 convertExportedSharedOntologyIntoBundleOntology(Path input, Path output) throws Exception {
System.out.format("Converting exported shared ontology%n\t" + input.toString() + "%nto bundle-compatible ontology%n\t" + output.toString());
try (InputStream is = new BufferedInputStream(Files.newInputStream(input), 128*1024)) {
DataInput dis = new DataInputStream(is);
DataContainers.writeFile(output.toFile(), new DataContainer(
container.format, container.version,
container.metadata, new Variant(TransferableGraph1.BINDING, graph)));
+
+ return graph;
+
}
}
public static void main(String[] args) throws Exception {
- if (args.length < 1) {
- System.out.println("Required arguments: <input .sharedOntology file> [<output .tg file>]");
- } else if (args.length < 2) {
+ if (args.length == 0) {
+ System.out.println("Required arguments: <input .sharedLibrary file> [<output .tg file>]");
+ } else if (args.length == 1) {
Path input = Paths.get(args[0]);
- Path output = input.getParent().resolve(input.getName(input.getNameCount()-1) + ".fixed");
- convertExportedSharedOntologyIntoBundleOntology(input, output);
+ Path output1 = input.getParent().resolve("graph.tg");
+ TransferableGraph1 tg = convertExportedSharedOntologyIntoBundleOntology(input, output1);
+ String listing = PrettyPrintTG.print(tg, false);
+ Path output2 = Paths.get(args[0].substring(0, args[0].length() - ".sharedLibrary".length()) + ".pgraph");
+ Files.write(output2, listing.getBytes(),StandardOpenOption.CREATE);
} else {
convertExportedSharedOntologyIntoBundleOntology(Paths.get(args[0]), Paths.get(args[1]));
}