-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add XML, CSV and TSV result counting parser (#270)
* Add xml parser * Add link and ask * Add csv and tsv parser
- Loading branch information
Showing
13 changed files
with
1,006 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/org/aksw/iguana/cc/lang/impl/BooleanResultData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.aksw.iguana.cc.lang.impl; | ||
|
||
import org.aksw.iguana.cc.lang.LanguageProcessor; | ||
import org.aksw.iguana.cc.storage.Storable; | ||
import org.aksw.iguana.commons.rdf.IPROP; | ||
import org.aksw.iguana.commons.rdf.IRES; | ||
import org.apache.jena.rdf.model.Model; | ||
import org.apache.jena.rdf.model.ModelFactory; | ||
import org.apache.jena.rdf.model.Resource; | ||
import org.apache.jena.rdf.model.ResourceFactory; | ||
|
||
import java.util.List; | ||
|
||
public record BooleanResultData( | ||
long hash, | ||
Boolean result, | ||
List<String> links, | ||
Exception exception | ||
) implements LanguageProcessor.LanguageProcessingData, Storable.AsCSV, Storable.AsRDF { | ||
final static String[] header = new String[]{ "responseBodyHash", "boolean", "links", "exception" }; | ||
|
||
@Override | ||
public Storable.CSVData toCSV() { | ||
String resultString = ""; | ||
String exceptionString = ""; | ||
String linksString = ""; | ||
if (result != null) | ||
resultString = result.toString(); | ||
if (exception != null) | ||
exceptionString = exception().toString(); | ||
if (links != null) | ||
linksString = String.join("; ", links); | ||
|
||
String[] content = new String[]{ String.valueOf(hash), resultString, linksString, exceptionString }; | ||
String[][] data = new String[][]{ header, content }; | ||
|
||
String folderName = "sparql-ask-result-data"; | ||
List<CSVData.CSVFileData> files = List.of(new Storable.CSVData.CSVFileData("sparql-ask-result.csv", data)); | ||
return new Storable.CSVData(folderName, files); | ||
} | ||
|
||
@Override | ||
public Model toRDF() { | ||
Model m = ModelFactory.createDefaultModel(); | ||
Resource responseBodyRes = IRES.getResponsebodyResource(this.hash); | ||
if (this.result != null) { | ||
m.add(responseBodyRes, IPROP.askBoolean, ResourceFactory.createTypedLiteral(this.result)); | ||
} | ||
if (this.links != null) { | ||
for (String link : this.links) { | ||
m.add(responseBodyRes, IPROP.link, ResourceFactory.createTypedLiteral(link)); | ||
} | ||
} | ||
if (this.exception != null) { | ||
m.add(responseBodyRes, IPROP.exception, ResourceFactory.createTypedLiteral(this.exception.toString())); | ||
} | ||
|
||
return m; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/org/aksw/iguana/cc/lang/impl/ResultCountData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.aksw.iguana.cc.lang.impl; | ||
|
||
import org.aksw.iguana.cc.lang.LanguageProcessor; | ||
import org.aksw.iguana.cc.storage.Storable; | ||
import org.aksw.iguana.commons.rdf.IPROP; | ||
import org.aksw.iguana.commons.rdf.IRES; | ||
import org.apache.jena.rdf.model.Model; | ||
import org.apache.jena.rdf.model.ModelFactory; | ||
import org.apache.jena.rdf.model.Resource; | ||
import org.apache.jena.rdf.model.ResourceFactory; | ||
|
||
import java.util.List; | ||
|
||
public record ResultCountData ( | ||
long hash, | ||
long results, | ||
long bindings, | ||
List<String> variables, | ||
List<String> links, | ||
Exception exception | ||
) implements LanguageProcessor.LanguageProcessingData, Storable.AsCSV, Storable.AsRDF { | ||
final static String[] header = new String[]{ "responseBodyHash", "results", "bindings", "variables", "links", "exception" }; | ||
|
||
@Override | ||
public Storable.CSVData toCSV() { | ||
String variablesString = ""; | ||
String exceptionString = ""; | ||
String linksString = ""; | ||
if (variables != null) | ||
variablesString = String.join("; ", variables); | ||
if (exception != null) | ||
exceptionString = exception().toString(); | ||
if (links != null) | ||
linksString = String.join("; ", links); | ||
|
||
String[] content = new String[]{ String.valueOf(hash), String.valueOf(results), String.valueOf(bindings), variablesString, linksString, exceptionString }; | ||
String[][] data = new String[][]{ header, content }; | ||
|
||
String folderName = "result-count-data"; | ||
List<Storable.CSVData.CSVFileData> files = List.of(new Storable.CSVData.CSVFileData("result-count.csv", data)); | ||
return new Storable.CSVData(folderName, files); | ||
} | ||
|
||
@Override | ||
public Model toRDF() { | ||
Model m = ModelFactory.createDefaultModel(); | ||
Resource responseBodyRes = IRES.getResponsebodyResource(this.hash); | ||
m.add(responseBodyRes, IPROP.results, ResourceFactory.createTypedLiteral(this.results)) | ||
.add(responseBodyRes, IPROP.bindings, ResourceFactory.createTypedLiteral(this.bindings)); | ||
|
||
if (this.variables != null) { | ||
for (String variable : this.variables) { | ||
m.add(responseBodyRes, IPROP.variable, ResourceFactory.createTypedLiteral(variable)); | ||
} | ||
} | ||
if (this.links != null) { | ||
for (String link : this.links) { | ||
m.add(responseBodyRes, IPROP.link, ResourceFactory.createTypedLiteral(link)); | ||
} | ||
} | ||
if (this.exception != null) { | ||
m.add(responseBodyRes, IPROP.exception, ResourceFactory.createTypedLiteral(this.exception.toString())); | ||
} | ||
|
||
return m; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.