Search in sources :

Example 1 with Taxon

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

the class TaxonUtil method mapToTaxon.

public static Taxon mapToTaxon(Map<String, String> properties) {
    Taxon taxon = new TaxonImpl();
    mapToTaxon(properties, taxon);
    return taxon;
}
Also used : Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl)

Example 2 with Taxon

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

the class TaxonUtilTest method toTaxonImage.

@Test
public void toTaxonImage() {
    TaxonImage image = new TaxonImage();
    Taxon taxon = new TaxonImpl("Donald duckus", "EOL:123");
    taxon.setCommonNames("bla @en | boo @de");
    taxon.setPath("one | two | three");
    Map<String, String> taxonMap = new TreeMap<String, String>(TaxonUtil.taxonToMap(taxon));
    taxonMap.put(PropertyAndValueDictionary.THUMBNAIL_URL, "http://foo/bar/thumb");
    taxonMap.put(PropertyAndValueDictionary.EXTERNAL_URL, "http://foo/bar");
    TaxonImage enrichedImage = TaxonUtil.enrichTaxonImageWithTaxon(taxonMap, image);
    assertThat(enrichedImage.getCommonName(), is("bla"));
    assertThat(enrichedImage.getTaxonPath(), is("one | two | three"));
    assertThat(enrichedImage.getInfoURL(), is("http://foo/bar"));
    assertThat(enrichedImage.getThumbnailURL(), is("http://foo/bar/thumb"));
    assertThat(enrichedImage.getPageId(), is("123"));
    assertThat(enrichedImage.getImageURL(), is(nullValue()));
}
Also used : TaxonImage(org.eol.globi.domain.TaxonImage) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 3 with Taxon

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

the class LinkerTermMatcher method handleBatch.

private void handleBatch(final GraphDatabaseService graphDb, TermMatcher termMatcher, final Map<Long, TaxonNode> nodeMap, int counter) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    String msgPrefix = "batch #" + counter / BATCH_SIZE;
    LOG.info(msgPrefix + " preparing...");
    List<String> nodeIdAndNames = new ArrayList<String>();
    for (Map.Entry<Long, TaxonNode> entry : nodeMap.entrySet()) {
        String name = entry.getKey() + "|" + entry.getValue().getName();
        nodeIdAndNames.add(name);
    }
    try {
        if (nodeIdAndNames.size() > 0) {
            termMatcher.findTermsForNames(nodeIdAndNames, new TermMatchListener() {

                @Override
                public void foundTaxonForName(Long nodeId, String name, Taxon taxon, NameType relType) {
                    TaxonNode taxonNode = nodeMap.get(nodeId);
                    if (taxonNode != null && NameType.NONE != relType && !TaxonUtil.likelyHomonym(taxon, taxonNode)) {
                        NodeUtil.connectTaxa(taxon, taxonNode, graphDb, RelTypes.forType(relType));
                    }
                }
            });
        }
    } catch (PropertyEnricherException ex) {
        LOG.error(msgPrefix + " problem matching terms", ex);
    }
    stopWatch.stop();
    LOG.info(msgPrefix + " completed in [" + stopWatch.getTime() + "] ms (" + (1.0 * stopWatch.getTime() / BATCH_SIZE) + " ms/name )");
    nodeMap.clear();
}
Also used : PropertyEnricherException(org.eol.globi.service.PropertyEnricherException) TaxonNode(org.eol.globi.domain.TaxonNode) Taxon(org.eol.globi.domain.Taxon) ArrayList(java.util.ArrayList) NameType(org.eol.globi.domain.NameType) StopWatch(org.apache.commons.lang.time.StopWatch) HashMap(java.util.HashMap) Map(java.util.Map) TermMatchListener(org.eol.globi.taxon.TermMatchListener)

Example 4 with Taxon

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

the class NonResolvingTaxonIndex method addNoMatchTaxon.

protected TaxonNode addNoMatchTaxon(Taxon origTaxon) throws NodeFactoryException {
    Taxon noMatchTaxon = TaxonUtil.copy(origTaxon);
    noMatchTaxon.setName(isNonEmptyTaxonNameOrId(origTaxon.getName()) ? origTaxon.getName() : PropertyAndValueDictionary.NO_NAME);
    noMatchTaxon.setExternalId(isNonEmptyTaxonNameOrId(origTaxon.getExternalId()) ? origTaxon.getExternalId() : PropertyAndValueDictionary.NO_MATCH);
    return createAndIndexTaxon(origTaxon, noMatchTaxon);
}
Also used : Taxon(org.eol.globi.domain.Taxon)

Example 5 with Taxon

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

the class StudyImporterForGoMexSI2IT method assertThatSomeDataIsImported.

private static void assertThatSomeDataIsImported(NodeFactory nodeFactory, TaxonIndex taxonIndex) throws StudyImporterException, NodeFactoryException {
    Study study = nodeFactory.findStudy("Divita et al 1983");
    assertSpecimenProperties(((NodeBacked) study).getUnderlyingNode().getGraphDatabase());
    assertNotNull(study);
    assertThat(study.getTitle(), is("Divita et al 1983"));
    assertThat(study.getExternalId(), is(ExternalIdUtil.urlForExternalId("GAME:2689")));
    assertThat(study.getCitation(), is("Regina Divita, Mischelle Creel, Peter Sheridan. 1983. Foods of coastal fishes during brown shrimp Penaeus aztecus, migration from Texas estuaries (June - July 1981)."));
    assertNotNull(nodeFactory.findStudy("Beaumariage 1973"));
    assertNotNull(nodeFactory.findStudy("Baughman, 1943"));
    assertNotNull(taxonIndex.findTaxonByName("Chloroscombrus chrysurus"));
    assertNotNull(taxonIndex.findTaxonByName("Micropogonias undulatus"));
    assertNotNull(taxonIndex.findTaxonByName("Amphipoda"));
    assertNotNull(taxonIndex.findTaxonByName("Crustacea"));
    Taxon taxon = taxonIndex.findTaxonByName("Scomberomorus cavalla");
    List<String> preyList = new ArrayList<String>();
    final List<String> titles = new ArrayList<String>();
    Iterable<Relationship> classifiedAsRels = ((NodeBacked) taxon).getUnderlyingNode().getRelationships(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
    int count = 0;
    for (Relationship classifiedAsRel : classifiedAsRels) {
        Node predatorSpecimen = classifiedAsRel.getStartNode();
        Specimen predator = new SpecimenNode(predatorSpecimen);
        Iterable<Relationship> stomachContents = NodeUtil.getStomachContents(predator);
        for (Relationship prey : stomachContents) {
            Relationship singleRelationship = prey.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING);
            preyList.add((String) singleRelationship.getEndNode().getProperty("name"));
        }
        count++;
        Relationship collectedBy = predatorSpecimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED), Direction.INCOMING);
        assertThat(collectedBy, is(notNullValue()));
        String title = (String) collectedBy.getStartNode().getProperty("title");
        titles.add(title);
    }
    assertThat(count > 7, is(true));
    assertThat(preyList, hasItem("Organic matter"));
    assertThat(preyList, hasItem("Triglidae"));
    assertThat(preyList, hasItem("Sparidae"));
    assertThat(titles, hasItem("Beaumariage 1973"));
    assertThat(titles, hasItem("Blanton et al 1972"));
    assertNotNull(taxon);
    final String footprintWKT = WKT_FOOTPRINT2;
    LocationImpl expectedLocation = new LocationImpl(29.346953, -92.980614, -13.641, footprintWKT);
    expectedLocation.setLocality("Louisiana inner continental shelf");
    Location location = nodeFactory.findLocation(expectedLocation);
    assertThat(location, is(notNullValue()));
    assertThat(location.getFootprintWKT(), is(footprintWKT));
    assertThat(location.getLocality(), is("Louisiana inner continental shelf"));
    assertNotNull(location);
    List<Environment> environments = location.getEnvironments();
    assertThat(environments.size(), not(is(0)));
    assertThat(environments.get(0).getExternalId(), is("http://cmecscatalog.org/classification/aquaticSetting/13"));
    assertThat(environments.get(0).getName(), is("Marine Nearshore Subtidal"));
    assertNotNull(nodeFactory.findStudy("GoMexSI"));
}
Also used : Study(org.eol.globi.domain.Study) Taxon(org.eol.globi.domain.Taxon) JsonNode(org.codehaus.jackson.JsonNode) Node(org.neo4j.graphdb.Node) SpecimenNode(org.eol.globi.domain.SpecimenNode) ArrayList(java.util.ArrayList) SpecimenNode(org.eol.globi.domain.SpecimenNode) Specimen(org.eol.globi.domain.Specimen) NodeBacked(org.eol.globi.domain.NodeBacked) Relationship(org.neo4j.graphdb.Relationship) LocationImpl(org.eol.globi.domain.LocationImpl) Environment(org.eol.globi.domain.Environment) Location(org.eol.globi.domain.Location)

Aggregations

Taxon (org.eol.globi.domain.Taxon)106 Test (org.junit.Test)69 TaxonImpl (org.eol.globi.domain.TaxonImpl)42 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)20 Study (org.eol.globi.domain.Study)16 TaxonNode (org.eol.globi.domain.TaxonNode)13 Matchers.containsString (org.hamcrest.Matchers.containsString)13 NameType (org.eol.globi.domain.NameType)12 Relationship (org.neo4j.graphdb.Relationship)12 Specimen (org.eol.globi.domain.Specimen)11 StudyImpl (org.eol.globi.domain.StudyImpl)10 TermMatchListener (org.eol.globi.taxon.TermMatchListener)10 Node (org.neo4j.graphdb.Node)10 GlobalNamesService (org.eol.globi.taxon.GlobalNamesService)9 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)8 Map (java.util.Map)7 IOException (java.io.IOException)6 LocationImpl (org.eol.globi.domain.LocationImpl)6 BufferedReader (java.io.BufferedReader)4