Skip to content

Commit

Permalink
update test case for TO-eq template, issue #77
Browse files Browse the repository at this point in the history
  • Loading branch information
Heiko Dietze committed Nov 13, 2015
1 parent aba359f commit ade8886
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,15 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.bbop.termgenie.core.ioc.IOCModule;
import org.bbop.termgenie.mail.MailHandler;
import org.bbop.termgenie.mail.SimpleMailHandler;
import org.bbop.termgenie.mail.review.DefaultReviewMailHandlerModule;
import org.bbop.termgenie.ontology.AdvancedPersistenceModule;
import org.bbop.termgenie.ontology.git.CommitGitTokenModule;
import org.bbop.termgenie.ontology.impl.FileCachingIgnoreFilter.IgnoresContainsDigits;
import org.bbop.termgenie.ontology.impl.GitAwareOntologyModule;
import org.bbop.termgenie.permissions.UserPermissionsModule;
import org.bbop.termgenie.presistence.PersistenceBasicModule;
import org.bbop.termgenie.rules.XMLDynamicRulesModule;
Expand All @@ -30,7 +22,6 @@
import org.bbop.termgenie.services.freeform.FreeFormTermServiceModule;
import org.bbop.termgenie.services.review.OboTermCommitReviewServiceImpl;
import org.bbop.termgenie.services.review.TermCommitReviewServiceModule;
import org.semanticweb.owlapi.model.IRI;


public class TermGenieWebAppTOContextListener extends AbstractTermGenieContextListener {
Expand Down Expand Up @@ -64,48 +55,14 @@ public String getModuleName() {

@Override
protected IOCModule getOntologyModule() {
String configFile = "ontology-configuration_to.xml";
String repositoryURL = "https://github.com/Planteome/plant-trait-ontology.git";
String workFolder = null; // no default value

Map<IRI, String> mappedIRIs = new HashMap<IRI, String>();
mappedIRIs.put(IRI.create("http://purl.obolibrary.org/obo/to.owl"), "plant-trait-ontology.obo");

String catalogXML = null; //"src/ontology/catalog-v001.xml";

final Set<IRI> ignoreIRIs = new HashSet<IRI>();
ignoreIRIs.add(IRI.create("http://purl.obolibrary.org/obo/TEMP"));

GitAwareOntologyModule m = GitAwareOntologyModule.createAnonymousGitModule(configFile, applicationProperties);
m.setGitAwareRepositoryURL(repositoryURL);
m.setGitAwareMappedIRIs(mappedIRIs);
m.setGitAwareCatalogXML(catalogXML);
m.setGitAwareWorkFolder(workFolder);
m.setFileCacheFilter(new IgnoresContainsDigits(ignoreIRIs));
IOCModule m = ToOntologyHelper.createDefaultOntologyModule(workFolder, applicationProperties);
return m;
}

protected Map<IRI, File> getLocalMappings(String prefix) {
Map<IRI, File> localMappings = new HashMap<IRI, File>();
String localIRIMappings = IOCModule.getProperty(prefix, applicationProperties);
if (localIRIMappings != null) {
String[] localIRIMappingComponents = StringUtils.split(localIRIMappings, ','); // treat as comma separated list
for (String component : localIRIMappingComponents) {
String iri = IOCModule.getProperty(prefix+"."+component+".IRI", applicationProperties);
String file = IOCModule.getProperty(prefix+"."+component+".File", applicationProperties);
if (iri != null && file != null) {
localMappings.put(IRI.create(iri), new File(file).getAbsoluteFile());
}
}
}
return localMappings;
}

@Override
protected IOCModule getCommitModule() {
String repositoryURL = "https://github.com/Planteome/plant-trait-ontology.git";
String remoteTargetFile = "plant-trait-ontology.obo";
return CommitGitTokenModule.createOboModule(repositoryURL, remoteTargetFile, applicationProperties);
return ToOntologyHelper.getCommitModule(applicationProperties);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.bbop.termgenie.servlets;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.bbop.termgenie.core.ioc.IOCModule;
import org.bbop.termgenie.ontology.git.CommitGitTokenModule;
import org.bbop.termgenie.ontology.impl.GitAwareOntologyModule;
import org.bbop.termgenie.ontology.impl.FileCachingIgnoreFilter.IgnoresContainsDigits;
import org.semanticweb.owlapi.model.IRI;

public class ToOntologyHelper {

public static IOCModule createDefaultOntologyModule(String workFolder, Properties applicationProperties) {
String configFile = "ontology-configuration_to.xml";
String repositoryURL = "https://github.com/Planteome/plant-trait-ontology.git";

Map<IRI, String> mappedIRIs = new HashMap<IRI, String>();
mappedIRIs.put(IRI.create("http://purl.obolibrary.org/obo/to.owl"), "plant-trait-ontology.obo");

String catalogXML = "catalog-v001.xml";

final Set<IRI> ignoreIRIs = new HashSet<IRI>();
ignoreIRIs.add(IRI.create("http://purl.obolibrary.org/obo/TEMP"));

GitAwareOntologyModule m = GitAwareOntologyModule.createAnonymousGitModule(configFile, applicationProperties);
m.setGitAwareRepositoryURL(repositoryURL);
m.setGitAwareMappedIRIs(mappedIRIs);
m.setGitAwareCatalogXML(catalogXML);
m.setGitAwareWorkFolder(workFolder);
m.setFileCacheFilter(new IgnoresContainsDigits(ignoreIRIs));
return m;
}

static IOCModule getCommitModule(Properties applicationProperties) {
String repositoryURL = "https://github.com/Planteome/plant-trait-ontology.git";
String remoteTargetFile = "plant-trait-ontology.obo";
return CommitGitTokenModule.createOboModule(repositoryURL, remoteTargetFile, applicationProperties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ function eq_simple() {

var label = termname(e, TO) + ' ' + termname(q, TO);
var definition = "A trait which is associated with the "
+ termname(q, TO) + " of a " + refname(e, TO) + ".";
+ termname(q, TO) + " of " + refname(e, TO) + ".";

var synonyms = null;
// String label, List<ISynonym> results, String prefix, String infix, String suffix, String scope
synonyms = termgenie.addSynonym(label, synonyms, null, label, ' trait', 'EXACT');

var mdef = createMDef("?Q and inheres_in some ?E");
var mdef = createMDef("?Q and 'inheres in' some ?E");
mdef.addParameter('E', e, TO);
mdef.addParameter('Q', q, TO);
createTerm(label, definition, synonyms, mdef);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package org.bbop.termgenie.rules;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.bbop.termgenie.core.TemplateField;
import org.bbop.termgenie.core.TermTemplate;
import org.bbop.termgenie.core.ioc.IOCModule;
import org.bbop.termgenie.core.ioc.TermGenieGuice;
import org.bbop.termgenie.core.rules.ReasonerModule;
import org.bbop.termgenie.core.rules.TermGenerationEngine;
Expand All @@ -17,11 +24,12 @@
import org.bbop.termgenie.ontology.OntologyLoader;
import org.bbop.termgenie.ontology.OntologyTaskManager;
import org.bbop.termgenie.ontology.OntologyTaskManager.OntologyTask;
import org.bbop.termgenie.ontology.impl.OntologyModule;
import org.bbop.termgenie.servlets.ToOntologyHelper;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.obolibrary.macro.ManchesterSyntaxTool;
import org.obolibrary.oboformat.parser.OBOFormatConstants.OboFormatTag;
import org.semanticweb.owlapi.model.OWLClassExpression;

import owltools.graph.OWLGraphWrapper;
Expand All @@ -33,10 +41,21 @@ public class SimpleEntityQualityPatternTest {

private static TermGenerationEngine generationEngine;
private static OntologyLoader loader;

private static File workFolder;

private static IOCModule getOntologyModule() throws IOException {
File tempFile = File.createTempFile("junit", "", FileUtils.getTempDirectory()).getCanonicalFile();
FileUtils.deleteQuietly(tempFile);
workFolder = new File(tempFile.getParentFile(), tempFile.getName()+"-folder");
workFolder.mkdirs();
IOCModule m = ToOntologyHelper.createDefaultOntologyModule(workFolder.getAbsolutePath(), null);
return m;
}

@BeforeClass
public static void beforeClass() {
OntologyModule ontologyModule = new OntologyModule("ontology-configuration_to.xml");
public static void beforeClass() throws IOException {
IOCModule ontologyModule = getOntologyModule();
Injector injector = TermGenieGuice.createInjector(new XMLDynamicRulesModule("termgenie_rules_to.xml", false, true, true, null),
ontologyModule,
new ReasonerModule(null));
Expand All @@ -45,7 +64,11 @@ public static void beforeClass() {
loader = injector.getInstance(OntologyLoader.class);
}

@Ignore("Ontology is missing the imports")
@AfterClass
public static void afterClass() throws Exception {
FileUtils.deleteDirectory(workFolder);
}

@Test
public void testManchesterSyntaxTool() throws Exception {
OntologyTaskManager ontologyManager = loader.getOntologyManager();
Expand All @@ -56,6 +79,7 @@ protected void runCatching(OWLGraphWrapper managed) throws TaskException, Except
ManchesterSyntaxTool tool = new ManchesterSyntaxTool(managed.getSourceOntology(), managed.getSupportOntologySet());

assertNotNull(managed.getOWLObjectByLabel("inheres in"));
assertNotNull(managed.getOWLObjectByIdentifier("inheres_in"));
assertNotNull(managed.getOWLObjectByIdentifier("RO:0000052"));

assertNotNull(tool.parseManchesterExpression("'plant trait'"));
Expand All @@ -65,7 +89,7 @@ protected void runCatching(OWLGraphWrapper managed) throws TaskException, Except
OWLClassExpression expression = tool.parseManchesterExpression("PATO_0000970 and 'inheres in' some PO_0020123");
assertNotNull(expression);

expression = tool.parseManchesterExpression("PATO_0000970 and 'inheres in' some PO_0020123");
expression = tool.parseManchesterExpression("PATO_0000970 and RO_0000052 some PO_0020123");
assertNotNull(expression);

}
Expand All @@ -78,7 +102,6 @@ protected void runCatching(OWLGraphWrapper managed) throws TaskException, Except

}

@Ignore("Ontology is missing the imports")
@Test
public void test_eq_simple_1() {

Expand All @@ -88,7 +111,7 @@ public void test_eq_simple_1() {
assertEquals(1, list.size());
TermGenerationOutput output = list.get(0);
assertNull(output.getError(), output.getError());
// TODO verify output
assertEquals("root cap permeability", output.getTerm().getTagValue(OboFormatTag.TAG_NAME));
}

private List<TermGenerationInput> createEQSimpleTask(String entity, String quality) {
Expand Down

0 comments on commit ade8886

Please sign in to comment.