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