Add Wikibase schema exporter, for issue #1776

This commit is contained in:
Antonin Delpeuch 2018-10-28 15:19:22 +01:00
parent 3fb282852d
commit e85f7d36e0
2 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,31 @@
package org.openrefine.wikidata.exporters;
import java.io.IOException;
import java.io.Writer;
import java.util.Properties;
import org.json.JSONWriter;
import org.openrefine.wikidata.schema.WikibaseSchema;
import com.google.refine.browsing.Engine;
import com.google.refine.exporters.WriterExporter;
import com.google.refine.model.Project;
public class SchemaExporter implements WriterExporter {
@Override
public String getContentType() {
return "application/octet-stream";
}
@Override
public void export(Project project, Properties options, Engine engine, Writer writer) throws IOException {
WikibaseSchema schema = (WikibaseSchema) project.overlayModels.get("wikibaseSchema");
if (schema == null) {
schema = new WikibaseSchema();
}
JSONWriter jsonWriter = new JSONWriter(writer);
schema.write(jsonWriter, new Properties());
}
}

View File

@ -0,0 +1,30 @@
package org.openrefine.wikidata.exporters;
import static org.openrefine.wikidata.testing.JacksonSerializationTest.assertJsonEquals;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Properties;
import org.testng.annotations.Test;
import com.google.refine.browsing.Engine;
import com.google.refine.model.Project;
import com.google.refine.tests.RefineTest;
public class SchemaExporterTest extends RefineTest {
private SchemaExporter exporter = new SchemaExporter();
@Test
public void testNoSchema()
throws IOException {
Project project = this.createCSVProject("a,b\nc,d");
Engine engine = new Engine(project);
StringWriter writer = new StringWriter();
Properties properties = new Properties();
exporter.export(project, properties, engine, writer);
assertJsonEquals("{\"itemDocuments\":[]}", writer.toString());
}
}