Search in sources :

Example 76 with TaxonImpl

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

the class StudyImporterForSIAD method downloadAndImportResource.

private void downloadAndImportResource(String resource, String source) throws StudyImporterException {
    try {
        LabeledCSVParser labeledCSVParser = parserFactory.createParser(resource, "UTF-8");
        labeledCSVParser.changeDelimiter('\t');
        while (labeledCSVParser.getLine() != null) {
            String name = labeledCSVParser.getValueByLabel("name");
            String ref = labeledCSVParser.getValueByLabel("source");
            String title = "SIAD-" + ref;
            String citation = "ABRS 2009. Australian Faunal Directory. " + name + ". Australian Biological Resources StudyNode, Canberra. " + CitationUtil.createLastAccessedString(ref);
            StudyImpl study1 = new StudyImpl(title, source, null, citation);
            study1.setExternalId(ref);
            Study study = nodeFactory.getOrCreateStudy(study1);
            Specimen specimen = nodeFactory.createSpecimen(study, new TaxonImpl(name, null));
            String hostName = labeledCSVParser.getValueByLabel("host name");
            Specimen hostSpecimen = nodeFactory.createSpecimen(study, new TaxonImpl(hostName, null));
            InteractType type = map.get(labeledCSVParser.getValueByLabel("interaction"));
            specimen.interactsWith(hostSpecimen, type);
        }
    } catch (FileNotFoundException e) {
        throw new StudyImporterException("failed to open tmp file", e);
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to map data", e);
    } catch (IOException e) {
        throw new StudyImporterException("failed to read resource [" + resource + "]", e);
    }
}
Also used : InteractType(org.eol.globi.domain.InteractType) Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) FileNotFoundException(java.io.FileNotFoundException) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException)

Example 77 with TaxonImpl

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

the class TaxonUtil method enrich.

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

Example 78 with TaxonImpl

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

the class ResolvingTaxonIndex method resolveAndIndex.

private TaxonNode resolveAndIndex(Taxon origTaxon, Taxon taxon) throws NodeFactoryException {
    TaxonNode indexedTaxon = findTaxon(taxon);
    while (indexedTaxon == null) {
        try {
            taxon = TaxonUtil.enrich(enricher, taxon);
        } catch (PropertyEnricherException e) {
            throw new NodeFactoryException("failed to enrich taxon with name [" + taxon.getName() + "]", e);
        }
        indexedTaxon = findTaxon(taxon);
        if (indexedTaxon == null) {
            if (TaxonUtil.isResolved(taxon)) {
                indexedTaxon = createAndIndexTaxon(origTaxon, taxon);
            } else {
                String truncatedName = NodeUtil.truncateTaxonName(taxon.getName());
                if (StringUtils.equals(truncatedName, taxon.getName())) {
                    if (isIndexResolvedOnly()) {
                        break;
                    } else {
                        indexedTaxon = addNoMatchTaxon(origTaxon);
                    }
                } else {
                    taxon = new TaxonImpl();
                    taxon.setName(truncatedName);
                    indexedTaxon = findTaxonByName(taxon.getName());
                }
            }
        }
    }
    return indexedTaxon;
}
Also used : PropertyEnricherException(org.eol.globi.service.PropertyEnricherException) TaxonNode(org.eol.globi.domain.TaxonNode) NodeFactoryException(org.eol.globi.data.NodeFactoryException) TaxonImpl(org.eol.globi.domain.TaxonImpl)

Example 79 with TaxonImpl

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

the class TaxonInteractionIndexerTest method indexNoNameNoMatch.

@Test
public void indexNoNameNoMatch() throws NodeFactoryException {
    Specimen human = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Homo sapiens", PropertyAndValueDictionary.NO_MATCH));
    Specimen animal = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Canis lupus", PropertyAndValueDictionary.NO_MATCH));
    human.ate(animal);
    for (int i = 0; i < 10; i++) {
        Specimen fish = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Arius felis", null));
        human.ate(fish);
    }
    assertNull(taxonIndex.findTaxonById(PropertyAndValueDictionary.NO_MATCH));
    assertNull(taxonIndex.findTaxonByName("Homo sapiens"));
    new NameResolver(getGraphDb(), new NonResolvingTaxonIndex(getGraphDb())).resolve();
    assertNotNull(taxonIndex.findTaxonByName("Homo sapiens"));
    assertNull(taxonIndex.findTaxonById(PropertyAndValueDictionary.NO_MATCH));
    assertNull(taxonIndex.findTaxonByName(PropertyAndValueDictionary.NO_NAME));
}
Also used : Specimen(org.eol.globi.domain.Specimen) NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) Test(org.junit.Test)

Example 80 with TaxonImpl

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

the class TaxonInteractionIndexerTest method buildTaxonInterIndex.

@Test
public void buildTaxonInterIndex() throws NodeFactoryException, PropertyEnricherException {
    Specimen human = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Homo sapiens", "NCBI:9606"));
    Specimen animal = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Canis lupus", "WORMS:2"));
    human.ate(animal);
    for (int i = 0; i < 10; i++) {
        Specimen fish = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Arius felis", "WORMS:158711"));
        human.ate(fish);
    }
    assertNull(taxonIndex.findTaxonById("WORMS:2"));
    assertNull(taxonIndex.findTaxonByName("Homo sapiens"));
    new NameResolver(getGraphDb(), new NonResolvingTaxonIndex(getGraphDb())).resolve();
    new TaxonInteractionIndexer(getGraphDb()).index();
    Taxon homoSapiens = taxonIndex.findTaxonByName("Homo sapiens");
    assertNotNull(homoSapiens);
    Iterable<Relationship> rels = ((NodeBacked) homoSapiens).getUnderlyingNode().getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.ATE));
    List<String> humanFood = new ArrayList<String>();
    List<Long> counts = new ArrayList<Long>();
    List<String> labels = new ArrayList<>();
    for (Relationship rel : rels) {
        humanFood.add((String) rel.getEndNode().getProperty("name"));
        counts.add((Long) rel.getProperty("count"));
        labels.add((String) rel.getProperty("label"));
    }
    assertThat(humanFood.size(), is(4));
    assertThat(humanFood, hasItems("Arius felis", "Canis lupus"));
    assertThat(counts, hasItems(10L, 1L));
    assertThat(labels, hasItems("eats"));
}
Also used : NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) StudyImpl(org.eol.globi.domain.StudyImpl) ArrayList(java.util.ArrayList) Specimen(org.eol.globi.domain.Specimen) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Aggregations

TaxonImpl (org.eol.globi.domain.TaxonImpl)123 Specimen (org.eol.globi.domain.Specimen)59 Test (org.junit.Test)54 Taxon (org.eol.globi.domain.Taxon)42 StudyImpl (org.eol.globi.domain.StudyImpl)34 Study (org.eol.globi.domain.Study)32 Location (org.eol.globi.domain.Location)16 LocationImpl (org.eol.globi.domain.LocationImpl)15 TaxonNode (org.eol.globi.domain.TaxonNode)13 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)12 IOException (java.io.IOException)11 TermImpl (org.eol.globi.domain.TermImpl)11 StringWriter (java.io.StringWriter)9 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 HashMap (java.util.HashMap)7 NonResolvingTaxonIndex (org.eol.globi.taxon.NonResolvingTaxonIndex)7 Map (java.util.Map)5 Node (org.neo4j.graphdb.Node)5 File (java.io.File)4