Search in sources :

Example 1 with StudyImporterForSPIRE

use of org.eol.globi.data.StudyImporterForSPIRE in project eol-globi-data by jhpoelen.

the class ExporterRDFTest method exportSPIRE.

@Test
public void exportSPIRE() throws IOException, StudyImporterException {
    StudyImporterForSPIRE importer = new StudyImporterForSPIRE(null, nodeFactory);
    importer.setFilter(recordNumber -> recordNumber < 5);
    importer.setDataset(new DatasetLocal());
    importStudy(importer);
    List<Study> studies = NodeUtil.findAllStudies(getGraphDb());
    Taxon taxon = taxonIndex.getOrCreateTaxon(new TaxonImpl("some taxon", null));
    Taxon sameAsTaxon = taxonIndex.getOrCreateTaxon(new TaxonImpl("bugus same as taxon", "EOL:123"));
    Transaction tx = getGraphDb().beginTx();
    try {
        assertThat(taxon, is(notNullValue()));
        ((NodeBacked) taxon).getUnderlyingNode().createRelationshipTo(((NodeBacked) sameAsTaxon).getUnderlyingNode(), NodeUtil.asNeo4j(RelTypes.SAME_AS));
        tx.success();
    } finally {
        tx.finish();
    }
    File file = File.createTempFile("spire-as-light-globi", ".nq");
    try {
        Writer writer = new FileWriter(file);
        ExporterRDF turtleExporter = new ExporterRDF();
        for (Study study : studies) {
            turtleExporter.exportStudy(study, writer, true);
        }
        writer.flush();
        writer.close();
        assertTrue(file.exists());
        String content = IOUtils.toString(new FileInputStream(file));
        assertThat(content, not(containsString("no:match")));
        assertThat(content, containsString("http://purl.obolibrary.org/obo/ENVO_"));
    } finally {
        FileUtils.deleteQuietly(file);
    }
}
Also used : Study(org.eol.globi.domain.Study) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) FileWriter(java.io.FileWriter) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) DatasetLocal(org.eol.globi.service.DatasetLocal) FileInputStream(java.io.FileInputStream) StudyImporterForSPIRE(org.eol.globi.data.StudyImporterForSPIRE) Transaction(org.neo4j.graphdb.Transaction) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer) Test(org.junit.Test)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 Writer (java.io.Writer)1 StudyImporterForSPIRE (org.eol.globi.data.StudyImporterForSPIRE)1 Study (org.eol.globi.domain.Study)1 Taxon (org.eol.globi.domain.Taxon)1 TaxonImpl (org.eol.globi.domain.TaxonImpl)1 DatasetLocal (org.eol.globi.service.DatasetLocal)1 Test (org.junit.Test)1 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)1 Transaction (org.neo4j.graphdb.Transaction)1