use of net.idea.loom.nm.nanowiki.ENanoMapperRDFReader in project ambit-mirror by ideaconsult.
the class ENanoMapperRDF2Test method testRoundtrip.
@Test
public void testRoundtrip() throws Exception {
ENanoMapperRDFReader reader = null;
Request hack = new Request();
hack.setRootRef(new Reference("http://localhost/ambit2"));
SubstanceRDFReporter r = new SubstanceRDFReporter(hack, MediaType.TEXT_RDF_N3);
Model model = ModelFactory.createDefaultModel();
r.header(model, null);
r.setOutput(model);
try {
reader = new ENanoMapperRDFReader(new InputStreamReader(new FileInputStream(getRDFFile())), "DEMO");
while (reader.hasNext()) {
IStructureRecord record = reader.nextRecord();
Assert.assertTrue(record instanceof SubstanceRecord);
r.processItem((SubstanceRecord) record);
}
r.footer(model, null);
File output = new File(System.getProperty("java.io.tmpdir") + "/" + "enmrdf_export2.ttl");
System.out.println("Exported to " + output.getAbsolutePath());
OutputStream writer = new FileOutputStream(output);
RDFDataMgr.write(writer, model, RDFFormat.TURTLE);
} finally {
if (reader != null)
reader.close();
}
}
use of net.idea.loom.nm.nanowiki.ENanoMapperRDFReader in project ambit-mirror by ideaconsult.
the class Context method createParser.
protected IRawReader<IStructureRecord> createParser(InputStream stream, boolean xlsx) throws Exception {
_parsertype mode = getParserType();
InputStream in = null;
if (gzipped)
in = new GZIPInputStream(stream);
else
in = stream;
if (mode == null) {
logger_cli.log(Level.INFO, "MSG_IMPORT", new Object[] { "parser type not specified, assuming", xlsx ? "xlsx" : "xls" });
return new GenericExcelParser(in, jsonConfig, xlsx);
} else
switch(mode) {
case enmrdf:
return new ENanoMapperRDFReader(new InputStreamReader(in), "ENM3");
case nanowiki:
return new NanoWikiRDFReader(new InputStreamReader(in));
default:
if (jsonConfig == null)
throw new FileNotFoundException("JSON config file not specified!");
return new GenericExcelParser(in, jsonConfig, xlsx, prefix);
}
}
use of net.idea.loom.nm.nanowiki.ENanoMapperRDFReader in project ambit-mirror by ideaconsult.
the class ENanoMapperRDF2Test method testRead.
@Test
public void testRead() throws Exception {
ENanoMapperRDFReader reader = null;
try {
reader = new ENanoMapperRDFReader(new InputStreamReader(new FileInputStream(getRDFFile())), "DEMO");
while (reader.hasNext()) {
IStructureRecord record = reader.nextRecord();
Assert.assertTrue(record instanceof SubstanceRecord);
System.out.println("Substance: " + ((SubstanceRecord) record).toJSON(""));
}
} finally {
if (reader != null)
reader.close();
}
}
use of net.idea.loom.nm.nanowiki.ENanoMapperRDFReader in project ambit-mirror by ideaconsult.
the class ENanoMapperRDFTest method testRead.
@Test
public void testRead() throws Exception {
ENanoMapperRDFReader reader = null;
try {
reader = new ENanoMapperRDFReader(new InputStreamReader(new FileInputStream(getRDFFile())), "DEMO");
while (reader.hasNext()) {
IStructureRecord record = reader.nextRecord();
Assert.assertTrue(record instanceof SubstanceRecord);
System.out.println("Substance: " + ((SubstanceRecord) record).toJSON(""));
}
} finally {
if (reader != null)
reader.close();
}
}
use of net.idea.loom.nm.nanowiki.ENanoMapperRDFReader in project ambit-mirror by ideaconsult.
the class ENanoMapperRDFTest method testRoundtrip.
@Test
public void testRoundtrip() throws Exception {
ENanoMapperRDFReader reader = null;
Request hack = new Request();
hack.setRootRef(new Reference("http://localhost/ambit2"));
SubstanceRDFReporter r = new SubstanceRDFReporter(hack, MediaType.TEXT_RDF_N3);
Model model = ModelFactory.createDefaultModel();
r.header(model, null);
r.setOutput(model);
try {
reader = new ENanoMapperRDFReader(new InputStreamReader(new FileInputStream(getRDFFile())), "DEMO");
while (reader.hasNext()) {
IStructureRecord record = reader.nextRecord();
Assert.assertTrue(record instanceof SubstanceRecord);
r.processItem((SubstanceRecord) record);
}
r.footer(model, null);
File output = new File(System.getProperty("java.io.tmpdir") + "/" + "enmrdf_export.ttl");
System.out.println("Exported to " + output.getAbsolutePath());
OutputStream writer = new FileOutputStream(output);
RDFDataMgr.write(writer, model, RDFFormat.TURTLE);
} finally {
if (reader != null)
reader.close();
}
}
Aggregations