Skip to content

Commit 4ba1482

Browse files
author
anquetil
committed
proposal to wrap corese.core.print.ResultFormat into a CoreseResultformat
1 parent 57e2f71 commit 4ba1482

2 files changed

Lines changed: 46 additions & 12 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package fr.inria.corese.command.utils.coreseCoreWrapper;
2+
3+
import java.io.IOException;
4+
5+
import fr.inria.corese.core.kgram.core.Mappings;
6+
import fr.inria.corese.core.print.ResultFormat;
7+
import fr.inria.corese.core.sparql.api.ResultFormatDef;
8+
9+
public class CoreseResultFormat {
10+
11+
protected ResultFormat format;
12+
13+
public CoreseResultFormat(CoreseRdfGraph graph) {
14+
format = ResultFormat.create(graph.getGraph());
15+
}
16+
17+
public CoreseResultFormat(Mappings mappings) {
18+
format = ResultFormat.create(mappings);
19+
}
20+
21+
public void setSelectFormat(ResultFormatDef.format coreseFormat) {
22+
format.setSelectFormat(coreseFormat);
23+
}
24+
25+
public void setConstructFormat(ResultFormatDef.format coreseFormat) {
26+
format.setConstructFormat(coreseFormat);
27+
}
28+
29+
public void write(String path) {
30+
try {
31+
format.write(path);
32+
} catch (IOException e) {
33+
throw new IllegalArgumentException("Failed to open export file: " + path.toString(), e);
34+
}
35+
}
36+
37+
38+
}

src/main/java/fr/inria/corese/command/utils/exporter/AbstractExporter.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import java.nio.file.Path;
55

66
import fr.inria.corese.command.utils.coreseCoreWrapper.CoreseRdfGraph;
7+
import fr.inria.corese.command.utils.coreseCoreWrapper.CoreseResultFormat;
78
import fr.inria.corese.core.kgram.core.Mappings;
8-
import fr.inria.corese.core.print.ResultFormat;
99
import fr.inria.corese.core.sparql.api.ResultFormatDef;
1010
import picocli.CommandLine.Model.CommandSpec;
1111

@@ -64,7 +64,7 @@ public AbstractExporter(CommandSpec spec, boolean verbose, Path output) throws I
6464
* @param graph Graph to export.
6565
*/
6666
protected void exportToFile(Path path, ResultFormatDef.format coreseFormat, String formatName, CoreseRdfGraph graph) {
67-
ResultFormat resultFormater = ResultFormat.create(graph.getGraph());
67+
CoreseResultFormat resultFormater = new CoreseResultFormat(graph);
6868
exportToFile(path, coreseFormat, formatName, resultFormater);
6969
}
7070

@@ -76,7 +76,7 @@ protected void exportToFile(Path path, ResultFormatDef.format coreseFormat, Stri
7676
* @param graph Graph to export.
7777
*/
7878
protected void exportToStdout(ResultFormatDef.format coreseFormat, String formatName, CoreseRdfGraph graph) {
79-
ResultFormat resultFormater = ResultFormat.create(graph.getGraph());
79+
CoreseResultFormat resultFormater = new CoreseResultFormat(graph);
8080
exportToStdout(coreseFormat, formatName, resultFormater);
8181
}
8282

@@ -89,7 +89,7 @@ protected void exportToStdout(ResultFormatDef.format coreseFormat, String format
8989
* @param mappings Mappings to export.
9090
*/
9191
protected void exportToFile(Path path, ResultFormatDef.format coreseFormat, String formatName, Mappings mappings) {
92-
ResultFormat resultFormater = ResultFormat.create(mappings);
92+
CoreseResultFormat resultFormater = new CoreseResultFormat(mappings);
9393
exportToFile(path, coreseFormat, formatName, resultFormater);
9494
}
9595

@@ -101,7 +101,7 @@ protected void exportToFile(Path path, ResultFormatDef.format coreseFormat, Stri
101101
* @param mappings Mappings to export.
102102
*/
103103
protected void exportToStdout(ResultFormatDef.format coreseFormat, String formatName, Mappings mappings) {
104-
ResultFormat resultFormater = ResultFormat.create(mappings);
104+
CoreseResultFormat resultFormater = new CoreseResultFormat(mappings);
105105
exportToStdout(coreseFormat, formatName, resultFormater);
106106
}
107107

@@ -118,16 +118,12 @@ protected void exportToStdout(ResultFormatDef.format coreseFormat, String format
118118
* @param ResultFormat Result formater.
119119
*/
120120
private void exportToFile(Path path,
121-
ResultFormatDef.format coreseFormat, String formatName, ResultFormat resultFormater) {
121+
ResultFormatDef.format coreseFormat, String formatName, CoreseResultFormat resultFormater) {
122122

123123
resultFormater.setSelectFormat(coreseFormat);
124124
resultFormater.setConstructFormat(coreseFormat);
125125

126-
try {
127-
resultFormater.write(path.toString());
128-
} catch (Exception e) {
129-
throw new IllegalArgumentException("Failed to open export file: " + path.toString(), e);
130-
}
126+
resultFormater.write(path.toString());
131127

132128
if (this.verbose) {
133129
this.spec.commandLine().getErr()
@@ -143,7 +139,7 @@ private void exportToFile(Path path,
143139
* @param formatName Name of the format.
144140
* @param ResultFormat Result formater.
145141
*/
146-
private void exportToStdout(ResultFormatDef.format coreseFormat, String formatName, ResultFormat resultFormater) {
142+
private void exportToStdout(ResultFormatDef.format coreseFormat, String formatName, CoreseResultFormat resultFormater) {
147143

148144
// Configure the result formater
149145
resultFormater.setSelectFormat(coreseFormat);

0 commit comments

Comments
 (0)