Search in sources :

Example 1 with TermLookupService

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

the class StudyImporterForGoMexSI2 method addObservations.

private void addObservations(Map<String, Map<String, String>> predatorIdToPredatorSpecimen, Map<String, Study> refIdToStudyMap, Map<String, List<Map<String, String>>> predatorUIToPreyLists, Study metaStudy) throws StudyImporterException {
    String locationResource = getLocationsResourcePath();
    try {
        TermLookupService cmecsService = new CMECSService();
        LabeledCSVParser parser = parserFactory.createParser(locationResource, CharsetConstant.UTF8);
        while (parser.getLine() != null) {
            String refId = getMandatoryValue(locationResource, parser, "DATA_ID");
            if (!refIdToStudyMap.containsKey(refId)) {
                getLogger().warn(metaStudy, "failed to find study for ref id [" + refId + "] on related to observation location in [" + locationResource + ":" + parser.getLastLineNumber() + "]");
            } else {
                Study study = refIdToStudyMap.get(refId);
                String specimenId = getMandatoryValue(locationResource, parser, "PRED_ID");
                Location location = parseLocation(locationResource, parser);
                Location locationNode = nodeFactory.getOrCreateLocation(location);
                enrichLocation(metaStudy, locationResource, cmecsService, parser, locationNode);
                String predatorId = refId + specimenId;
                Map<String, String> predatorProperties = predatorIdToPredatorSpecimen.get(predatorId);
                if (predatorProperties == null) {
                    getLogger().warn(study, "failed to lookup predator [" + refId + ":" + specimenId + "] for location at [" + locationResource + ":" + (parser.getLastLineNumber() + 1) + "]");
                } else {
                    addObservation(predatorUIToPreyLists, parser, study, locationNode, predatorId, predatorProperties);
                }
            }
        }
    } catch (IOException e) {
        throw new StudyImporterException("failed to open resource [" + locationResource + "]", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) TermLookupService(org.eol.globi.service.TermLookupService) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException) Location(org.eol.globi.domain.Location)

Example 2 with TermLookupService

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

the class NodeFactoryNeo4jTest method createAndFindEnvironment.

@Test
public void createAndFindEnvironment() throws NodeFactoryException {
    getNodeFactory().setEnvoLookupService(new TermLookupService() {

        @Override
        public List<Term> lookupTermByName(String name) throws TermLookupServiceException {
            ArrayList<Term> terms = new ArrayList<>();
            terms.add(new TermImpl("NS:" + name, StringUtils.replace(name, " ", "_")));
            return terms;
        }
    });
    Location location = getNodeFactory().getOrCreateLocation(new LocationImpl(0.0, 1.0, 2.0, null));
    List<Environment> first = getNodeFactory().getOrCreateEnvironments(location, "BLA:123", "this and that");
    location = getNodeFactory().getOrCreateLocation(new LocationImpl(0.0, 1.0, 2.0, null));
    List<Environment> second = getNodeFactory().getOrCreateEnvironments(location, "BLA:123", "this and that");
    assertThat(first.size(), is(second.size()));
    assertThat(((NodeBacked) first.get(0)).getNodeID(), is(((NodeBacked) second.get(0)).getNodeID()));
    EnvironmentNode foundEnvironment = getNodeFactory().findEnvironment("this_and_that");
    assertThat(foundEnvironment, is(notNullValue()));
    List<Environment> environments = location.getEnvironments();
    assertThat(environments.size(), is(1));
    Environment environment = environments.get(0);
    NodeBacked environmentNode = (NodeBacked) environment;
    assertThat(environmentNode.getNodeID(), is(foundEnvironment.getNodeID()));
    assertThat(environment.getName(), is("this_and_that"));
    assertThat(environment.getExternalId(), is("NS:this and that"));
    Location anotherLocation = getNodeFactory().getOrCreateLocation(new LocationImpl(48.2, 123.1, null, null));
    LocationNode anotherLocationNode = (LocationNode) anotherLocation;
    assertThat(anotherLocationNode.getEnvironments().size(), is(0));
    anotherLocationNode.addEnvironment((EnvironmentNode) environment);
    assertThat(anotherLocationNode.getEnvironments().size(), is(1));
    // don't add environment that has already been associated
    anotherLocationNode.addEnvironment(environment);
    assertThat(anotherLocationNode.getEnvironments().size(), is(1));
    getNodeFactory().getOrCreateEnvironments(anotherLocation, "BLA:124", "that");
    assertThat(anotherLocationNode.getEnvironments().size(), is(2));
}
Also used : TermLookupServiceException(org.eol.globi.service.TermLookupServiceException) ArrayList(java.util.ArrayList) TermLookupService(org.eol.globi.service.TermLookupService) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

TermLookupService (org.eol.globi.service.TermLookupService)2 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Location (org.eol.globi.domain.Location)1 Study (org.eol.globi.domain.Study)1 TermLookupServiceException (org.eol.globi.service.TermLookupServiceException)1 Test (org.junit.Test)1