Search in sources :

Example 1 with ENanoMapperRDFReader

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();
    }
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) InputStreamReader(java.io.InputStreamReader) ENanoMapperRDFReader(net.idea.loom.nm.nanowiki.ENanoMapperRDFReader) Reference(org.restlet.data.Reference) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Request(org.restlet.Request) Model(com.hp.hpl.jena.rdf.model.Model) SubstanceRecord(ambit2.base.data.SubstanceRecord) SubstanceRDFReporter(ambit2.rest.substance.SubstanceRDFReporter) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 2 with ENanoMapperRDFReader

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);
        }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GenericExcelParser(net.enanomapper.parser.GenericExcelParser) InputStreamReader(java.io.InputStreamReader) ENanoMapperRDFReader(net.idea.loom.nm.nanowiki.ENanoMapperRDFReader) GZIPInputStream(java.util.zip.GZIPInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) NanoWikiRDFReader(net.idea.loom.nm.nanowiki.NanoWikiRDFReader)

Example 3 with ENanoMapperRDFReader

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();
    }
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) InputStreamReader(java.io.InputStreamReader) ENanoMapperRDFReader(net.idea.loom.nm.nanowiki.ENanoMapperRDFReader) SubstanceRecord(ambit2.base.data.SubstanceRecord) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 4 with ENanoMapperRDFReader

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();
    }
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) InputStreamReader(java.io.InputStreamReader) ENanoMapperRDFReader(net.idea.loom.nm.nanowiki.ENanoMapperRDFReader) SubstanceRecord(ambit2.base.data.SubstanceRecord) FileInputStream(java.io.FileInputStream) DbUnitTest(ambit2.db.processors.test.DbUnitTest) Test(org.junit.Test)

Example 5 with ENanoMapperRDFReader

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();
    }
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) InputStreamReader(java.io.InputStreamReader) ENanoMapperRDFReader(net.idea.loom.nm.nanowiki.ENanoMapperRDFReader) Reference(org.restlet.data.Reference) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Request(org.restlet.Request) Model(com.hp.hpl.jena.rdf.model.Model) SubstanceRecord(ambit2.base.data.SubstanceRecord) SubstanceRDFReporter(ambit2.rest.substance.SubstanceRDFReporter) File(java.io.File) FileInputStream(java.io.FileInputStream) DbUnitTest(ambit2.db.processors.test.DbUnitTest) Test(org.junit.Test)

Aggregations

FileInputStream (java.io.FileInputStream)6 InputStreamReader (java.io.InputStreamReader)6 ENanoMapperRDFReader (net.idea.loom.nm.nanowiki.ENanoMapperRDFReader)6 IStructureRecord (ambit2.base.interfaces.IStructureRecord)5 SubstanceRecord (ambit2.base.data.SubstanceRecord)4 Test (org.junit.Test)4 File (java.io.File)3 DbUnitTest (ambit2.db.processors.test.DbUnitTest)2 SubstanceRDFReporter (ambit2.rest.substance.SubstanceRDFReporter)2 Model (com.hp.hpl.jena.rdf.model.Model)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 GenericExcelParser (net.enanomapper.parser.GenericExcelParser)2 NanoWikiRDFReader (net.idea.loom.nm.nanowiki.NanoWikiRDFReader)2 Request (org.restlet.Request)2 Reference (org.restlet.data.Reference)2 LiteratureEntry (ambit2.base.data.LiteratureEntry)1 EffectRecord (ambit2.base.data.study.EffectRecord)1 Protocol (ambit2.base.data.study.Protocol)1 StructureRecordValidator (ambit2.base.data.study.StructureRecordValidator)1