Skip to content

Commit

Permalink
Merge pull request #505 from geneontology/issue-502
Browse files Browse the repository at this point in the history
Dump model on each save.
  • Loading branch information
kltm authored Dec 2, 2022
2 parents bce7e99 + 4040baf commit 14f8f0c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.semanticweb.owlapi.rio.RioMemoryTripleSource;
import org.semanticweb.owlapi.rio.RioRenderer;

import javax.annotation.Nonnull;
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
Expand Down Expand Up @@ -63,7 +64,7 @@ public class BlazegraphMolecularModelManager<METADATA> extends CoreMolecularMode
* @throws OWLOntologyCreationException
* @throws IOException
*/
public BlazegraphMolecularModelManager(OWLOntology tbox, CurieHandler curieHandler, String modelIdPrefix, String pathToJournal, String pathToExportFolder, String pathToOntologyJournal, boolean downloadOntologyJournal)
public BlazegraphMolecularModelManager(OWLOntology tbox, CurieHandler curieHandler, String modelIdPrefix, @Nonnull String pathToJournal, String pathToExportFolder, String pathToOntologyJournal, boolean downloadOntologyJournal)
throws OWLOntologyCreationException, IOException {
super(tbox, pathToOntologyJournal, downloadOntologyJournal);
if (curieHandler == null) {
Expand Down Expand Up @@ -198,6 +199,11 @@ public void saveModel(ModelContainer m)
this.writeModelToDatabase(ont, modelId);
// reset modified flag for abox after successful save
m.setAboxModified(false);
// dump stored model to export file
if (this.pathToExportFolder != null) {
File folder = new File(this.pathToExportFolder);
dumpStoredModel(modelId, folder);
}
} finally {
if (changes != null) {
List<OWLOntologyChange> invertedChanges = ReverseChangeGenerator
Expand All @@ -210,7 +216,6 @@ public void saveModel(ModelContainer m)
}
}


private void writeModelToDatabase(OWLOntology model, IRI modelId) throws RepositoryException, IOException {
// Only one thread at a time can use the unisolated connection.
synchronized (repo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ public void testImportDump() throws Exception {
BlazegraphMolecularModelManager<Void> m3 = createBlazegraphMolecularModelManager();

/* Import the test turtle file */
m3.importModelToDatabase(new File(sourceModelPath), false);
String modelId = m3.importModelToDatabase(new File(sourceModelPath), false);
/* Dump back triples in the model to temporary files */
for (IRI modelId : m3.getStoredModelIds())
m3.dumpStoredModel(modelId, folder.getRoot());

compareDumpUsingJena(new File(sourceModelPath), folder.getRoot(), null);
m3.dumpStoredModel(IRI.create(modelId), folder.getRoot());
File dumpedModel = folder.getRoot().toPath().resolve(modelId.toString().replace("http://model.geneontology.org/", "") + ".ttl").toFile();
compareDumpUsingJena(new File(sourceModelPath), dumpedModel, null);
m3.dispose();
}

Expand Down Expand Up @@ -253,7 +252,7 @@ private void testModelAddRemove(BlazegraphMolecularModelManager<Void> m3, ModelC
}

/**
* Dump stored model and and read back the dumped ttl files; check whether the model is properly reconstructed
* Dump stored model and read back the dumped ttl files; check whether the model is properly reconstructed
* from ttl files. Double-check whether the model is properly dumped using Jena.
*
* @param m3
Expand Down Expand Up @@ -285,7 +284,8 @@ private void testModelImport(BlazegraphMolecularModelManager<Void> m3, ModelCont
}

/* Compare the model constructed from dump files with the model constructed using pre-dumped files */
compareDumpUsingJena(new File("src/test/resources/mmg/basic-fullcycle-dump.ttl"), folder.getRoot(), modelId.toString());
File dumpedModel = folder.getRoot().toPath().resolve(modelId.toString().replace("http://model.geneontology.org/", "") + ".ttl").toFile();
compareDumpUsingJena(new File("src/test/resources/mmg/basic-fullcycle-dump.ttl"), dumpedModel, modelId.toString());
m3.dispose();
}

Expand Down Expand Up @@ -330,9 +330,7 @@ private void compareDumpUsingJena(File sourceFile, File targetFile, String targe
String[] extensions = new String[]{"ttl"};
Model targetModel = ModelFactory.createDefaultModel();
extensions = new String[]{"ttl"};
List<File> files = (List<File>) FileUtils.listFiles(targetFile, extensions, true);
for (File file : files)
targetModel.read(file.getCanonicalPath());
targetModel.read(targetFile.getCanonicalPath());

/*
* The modelId is randomly generated for every time we create a new model and the modelId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class MolecularModelManagerTest {
}

private MolecularModelManager<Void> createM3(OWLOntology tbox, File journal) throws OWLOntologyCreationException, IOException {
return new MolecularModelManager<Void>(tbox, curieHandler, "http://testmodel.geneontology.org/", journal.getAbsolutePath(), null, go_lego_journal_file, true);
return new MolecularModelManager<Void>(tbox, curieHandler, "http://testmodel.geneontology.org/", journal.getAbsolutePath(), folder.getRoot().getAbsolutePath(), go_lego_journal_file, true);
}

@Test
Expand Down

0 comments on commit 14f8f0c

Please sign in to comment.