Search in sources :

Example 81 with TaxonImpl

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

the class LinkerTrustyNanoPubsTest method populateDataset.

public NodeFactoryWithDatasetContext populateDataset(DatasetImpl dataset) throws NodeFactoryException {
    TaxonIndex taxonIndex = getOrCreateTaxonIndex();
    // see https://github.com/jhpoelen/eol-globi-data/wiki/Nanopubs
    StudyImpl study = new StudyImpl("some study", "some source", "http://doi.org/123.23/222", "some study citation");
    NodeFactoryWithDatasetContext factory = new NodeFactoryWithDatasetContext(nodeFactory, dataset);
    Interaction interaction = factory.createInteraction(factory.createStudy(study));
    TaxonImpl donaldTaxon = new TaxonImpl("donald duck", "NCBI:1234");
    Specimen donald = factory.createSpecimen(interaction, donaldTaxon);
    donald.classifyAs(taxonIndex.getOrCreateTaxon(donaldTaxon));
    Taxon mickeyTaxon = new TaxonImpl("mickey mouse", "NCBI:4444");
    Taxon mickeyTaxonEOL = taxonIndex.getOrCreateTaxon(new TaxonImpl("mickey mouse", "EOL:567"));
    NodeUtil.connectTaxa(mickeyTaxon, (TaxonNode) mickeyTaxonEOL, getGraphDb(), RelTypes.SAME_AS);
    Specimen mickey = factory.createSpecimen(interaction, mickeyTaxonEOL);
    mickey.classifyAs(taxonIndex.getOrCreateTaxon(mickeyTaxonEOL));
    donald.ate(mickey);
    return factory;
}
Also used : Specimen(org.eol.globi.domain.Specimen) Interaction(org.eol.globi.domain.Interaction) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) StudyImpl(org.eol.globi.domain.StudyImpl) TaxonIndex(org.eol.globi.data.TaxonIndex) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext)

Example 82 with TaxonImpl

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

the class NameResolverTest method doNameResolving.

@Test
public void doNameResolving() 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("Animalia", "WORMS:2"));
    human.ate(animal);
    Specimen fish = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Arius felis", "WORMS:158711"));
    human.ate(fish);
    assertNull(taxonIndex.findTaxonById("NCBI:9606"));
    assertNull(taxonIndex.findTaxonByName("Homo sapiens"));
    final NameResolver nameResolver = new NameResolver(getGraphDb(), new NonResolvingTaxonIndex(getGraphDb()));
    nameResolver.setBatchSize(1L);
    nameResolver.resolve();
    assertAnimalia(taxonIndex.findTaxonById("WORMS:2"));
    assertThat(taxonIndex.findTaxonByName("Arius felis"), is(notNullValue()));
    Taxon homoSapiens = taxonIndex.findTaxonByName("Homo sapiens");
    assertNotNull(homoSapiens);
    assertThat(homoSapiens.getExternalId(), is("NCBI:9606"));
}
Also used : Specimen(org.eol.globi.domain.Specimen) NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) StudyImpl(org.eol.globi.domain.StudyImpl) Test(org.junit.Test)

Example 83 with TaxonImpl

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

the class TaxonLookupServiceImpl method findTaxon.

private Taxon[] findTaxon(String fieldName1, String fieldValue) throws IOException {
    Taxon[] terms = new TaxonImpl[0];
    if (StringUtils.isNotBlank(fieldValue) && indexSearcher != null) {
        PhraseQuery query = new PhraseQuery();
        query.add(new Term(fieldName1, fieldValue));
        TopDocs docs = indexSearcher.search(query, getMaxHits());
        if (docs.totalHits > 0) {
            int maxResults = Math.min(docs.totalHits, getMaxHits());
            terms = new TaxonImpl[maxResults];
            for (int i = 0; i < maxResults; i++) {
                ScoreDoc scoreDoc = docs.scoreDocs[i];
                Document foundDoc = indexSearcher.doc(scoreDoc.doc);
                Taxon term = new TaxonImpl();
                Fieldable idField = foundDoc.getFieldable(FIELD_ID);
                if (idField != null) {
                    term.setExternalId(idField.stringValue());
                }
                Fieldable rankPathField = foundDoc.getFieldable(FIELD_RANK_PATH);
                if (rankPathField != null) {
                    term.setPath(rankPathField.stringValue());
                }
                Fieldable rankPathIdsField = foundDoc.getFieldable(FIELD_RANK_PATH_IDS);
                if (rankPathIdsField != null) {
                    term.setPathIds(rankPathIdsField.stringValue());
                }
                Fieldable rankPathNamesField = foundDoc.getFieldable(FIELD_RANK_PATH_NAMES);
                if (rankPathNamesField != null) {
                    term.setPathNames(rankPathNamesField.stringValue());
                }
                Fieldable commonNamesFields = foundDoc.getFieldable(FIELD_COMMON_NAMES);
                if (commonNamesFields != null) {
                    term.setCommonNames(commonNamesFields.stringValue());
                }
                Fieldable fieldName = foundDoc.getFieldable(FIELD_RECOMMENDED_NAME);
                if (fieldName != null) {
                    term.setName(fieldName.stringValue());
                }
                terms[i] = term;
            }
        }
    }
    return terms;
}
Also used : TopDocs(org.apache.lucene.search.TopDocs) PhraseQuery(org.apache.lucene.search.PhraseQuery) Fieldable(org.apache.lucene.document.Fieldable) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) Term(org.apache.lucene.index.Term) Document(org.apache.lucene.document.Document) ScoreDoc(org.apache.lucene.search.ScoreDoc)

Example 84 with TaxonImpl

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

the class TaxonCacheService method findTerms.

@Override
public void findTerms(List<Term> terms, TermMatchListener termMatchListener) throws PropertyEnricherException {
    lazyInit();
    for (Term term : terms) {
        String nodeIdAndName = term.getName();
        String[] split = StringUtils.split(nodeIdAndName, '|');
        String name = (split != null && split.length > 1) ? split[1] : nodeIdAndName;
        Long nodeId = (split != null && split.length > 1 && NumberUtils.isDigits(split[0])) ? Long.parseLong(split[0]) : null;
        if (!resolveName(termMatchListener, term.getId(), nodeId)) {
            if (StringUtils.isNotBlank(nodeIdAndName)) {
                if (!resolveName(termMatchListener, name, nodeId)) {
                    termMatchListener.foundTaxonForName(nodeId, name, new TaxonImpl(name, term.getId()), NameType.NONE);
                }
            }
        }
    }
}
Also used : TaxonImpl(org.eol.globi.domain.TaxonImpl) Term(org.eol.globi.domain.Term)

Example 85 with TaxonImpl

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

the class TaxonCacheParser method parseLine.

public static Taxon parseLine(LabeledCSVParser labeledCSVParser) {
    Taxon taxa = new TaxonImpl();
    taxa.setExternalId(CSVTSVUtil.valueOrNull(labeledCSVParser, "id"));
    taxa.setName(CSVTSVUtil.valueOrNull(labeledCSVParser, "name"));
    taxa.setRank(CSVTSVUtil.valueOrNull(labeledCSVParser, "rank"));
    taxa.setPath(CSVTSVUtil.valueOrNull(labeledCSVParser, "path"));
    taxa.setPathIds(CSVTSVUtil.valueOrNull(labeledCSVParser, "pathIds"));
    taxa.setPathNames(CSVTSVUtil.valueOrNull(labeledCSVParser, "pathNames"));
    taxa.setCommonNames(CSVTSVUtil.valueOrNull(labeledCSVParser, "commonNames"));
    taxa.setExternalUrl(CSVTSVUtil.valueOrNull(labeledCSVParser, "externalUrl"));
    taxa.setThumbnailUrl(CSVTSVUtil.valueOrDefault(labeledCSVParser, "thumbnailUrl", MISSING_THUMBNAIL));
    return taxa;
}
Also used : Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl)

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