Skip to content

Commit e6f424a

Browse files
committed
Enabled the SPARQL CSV output format
1 parent 95cdc4a commit e6f424a

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

sesamize/src/main/java/net/fortytwo/sesametools/sesamize/Sesamize.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ private static void printVersion() {
6464
}
6565

6666
public static void main(final String[] args) {
67-
System.out.println("length: " + args.length);
68-
for (String s : args) System.out.println("\t" + s);
69-
7067
if (args.length < 1) {
7168
printUsageAndExit(1, "missing command");
7269
}

sesamize/src/main/java/net/fortytwo/sesametools/sesamize/SesamizeArgs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public String getOption(final String defaultValue,
8080
public SparqlResultFormat getSparqlResultFormat(final SparqlResultFormat defaultValue,
8181
final String... alternatives) {
8282
String s = getOption(null, alternatives);
83-
return null == s ? defaultValue : SparqlResultFormat.lookupByNickname(s);
83+
return null == s ? defaultValue : SparqlResultFormat.lookupByNickname(s.toLowerCase());
8484
}
8585

8686
public RDFFormat getRDFFormat(final RDFFormat defaultValue,

sesamize/src/main/java/net/fortytwo/sesametools/sesamize/SparqlResultFormat.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
public enum SparqlResultFormat {
77
// Note: the XML format is defined first, so that it is the default format.
88
XML("application/sparql-results+xml", "xml"),
9+
CSV("text/csv", "csv"),
910
JSON("application/sparql-results+json", "json"),
10-
TAB("text/tab-delimited-values", "tab"); // ~
11+
TAB("text/tab-delimited-values", "tab", "tsv");
1112

1213
private final String mediaType;
1314
private final String[] nicknames;

sesamize/src/main/java/net/fortytwo/sesametools/sesamize/commands/Select.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.eclipse.rdf4j.query.resultio.TupleQueryResultWriter;
1212
import org.eclipse.rdf4j.query.resultio.sparqljson.SPARQLResultsJSONWriter;
1313
import org.eclipse.rdf4j.query.resultio.sparqlxml.SPARQLResultsXMLWriter;
14+
import org.eclipse.rdf4j.query.resultio.text.csv.SPARQLResultsCSVWriter;
1415
import org.eclipse.rdf4j.query.resultio.text.tsv.SPARQLResultsTSVWriter;
1516
import org.eclipse.rdf4j.repository.Repository;
1617
import org.eclipse.rdf4j.repository.RepositoryConnection;
@@ -46,7 +47,6 @@ public Select() {
4647

4748
@Override
4849
public void execute(SesamizeArgs args) throws Exception {
49-
System.out.println("select...");
5050
File inputFile = new File(args.nonOptions.get(1));
5151

5252
RDFFormat inputFormat = args.getRDFFormat(inputFile, RDFFormat.RDFXML, "i", "inputFormat");
@@ -58,7 +58,6 @@ public void execute(SesamizeArgs args) throws Exception {
5858

5959
executeSparqlSelectQuery(query, inputFile, System.out, inputFormat, outputFormat, getBaseURI(args));
6060
}
61-
System.out.println("...done");
6261
}
6362

6463
private void executeSparqlSelectQuery(final String query,
@@ -70,6 +69,9 @@ private void executeSparqlSelectQuery(final String query,
7069
TupleQueryResultWriter w;
7170

7271
switch (outFormat) {
72+
case CSV:
73+
w = new SPARQLResultsCSVWriter(out);
74+
break;
7375
case JSON:
7476
w = new SPARQLResultsJSONWriter(out);
7577
break;

0 commit comments

Comments
 (0)