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;
}
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"));
}
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;
}
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);
}
}
}
}
}
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;
}
Aggregations