use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.
the class StudyImporterForGoMexSI2 method addObservations.
private void addObservations(Map<String, Map<String, String>> predatorIdToPredatorSpecimen, Map<String, Study> refIdToStudyMap, Map<String, List<Map<String, String>>> predatorUIToPreyLists, Study metaStudy) throws StudyImporterException {
String locationResource = getLocationsResourcePath();
try {
TermLookupService cmecsService = new CMECSService();
LabeledCSVParser parser = parserFactory.createParser(locationResource, CharsetConstant.UTF8);
while (parser.getLine() != null) {
String refId = getMandatoryValue(locationResource, parser, "DATA_ID");
if (!refIdToStudyMap.containsKey(refId)) {
getLogger().warn(metaStudy, "failed to find study for ref id [" + refId + "] on related to observation location in [" + locationResource + ":" + parser.getLastLineNumber() + "]");
} else {
Study study = refIdToStudyMap.get(refId);
String specimenId = getMandatoryValue(locationResource, parser, "PRED_ID");
Location location = parseLocation(locationResource, parser);
Location locationNode = nodeFactory.getOrCreateLocation(location);
enrichLocation(metaStudy, locationResource, cmecsService, parser, locationNode);
String predatorId = refId + specimenId;
Map<String, String> predatorProperties = predatorIdToPredatorSpecimen.get(predatorId);
if (predatorProperties == null) {
getLogger().warn(study, "failed to lookup predator [" + refId + ":" + specimenId + "] for location at [" + locationResource + ":" + (parser.getLastLineNumber() + 1) + "]");
} else {
addObservation(predatorUIToPreyLists, parser, study, locationNode, predatorId, predatorProperties);
}
}
}
} catch (IOException e) {
throw new StudyImporterException("failed to open resource [" + locationResource + "]", e);
}
}
use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.
the class NodeFactoryWithDatasetContextTest method getOrCreateStudy.
@Test
public void getOrCreateStudy() throws NodeFactoryException {
NodeFactory factory = Mockito.mock(NodeFactory.class);
Dataset dataset = new DatasetImpl("some/namespace", URI.create("some:uri"));
NodeFactoryWithDatasetContext factoryWithDS = new NodeFactoryWithDatasetContext(factory, dataset);
factoryWithDS.getOrCreateStudy(new StudyImpl("some title"));
ArgumentCaptor<Study> argument = ArgumentCaptor.forClass(Study.class);
verify(factory).getOrCreateStudy(argument.capture());
assertEquals("globi:some/namespace", argument.getValue().getSourceId());
assertEquals("some title", argument.getValue().getTitle());
}
use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.
the class GraphExporterImpl method exportDataOntology.
private void exportDataOntology(List<Study> studies, String baseDir) throws StudyImporterException {
try {
ExporterRDF studyExporter = new ExporterRDF();
OutputStreamWriter writer = openStream(baseDir + "globi.nq.gz");
int total = studies.size();
int count = 1;
for (Study study : studies) {
studyExporter.exportStudy(study, writer, true);
if (count % 50 == 0) {
LOG.info("added triples for [" + count + "] of [" + total + "] studies...");
}
count++;
}
LOG.info("adding triples for [" + total + "] of [" + total + "] studies.");
LOG.info("writing nquads archive...");
closeStream(baseDir + "globi.nq.gz", writer);
} catch (IOException e) {
throw new StudyImporterException("failed to export as owl", e);
}
}
use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.
the class GraphExporterImpl method exportNames.
private void exportNames(List<Study> studies, String baseDir, StudyExporter exporter, String filename) throws StudyImporterException {
try {
String filePath = baseDir + filename;
OutputStreamWriter writer = openStream(filePath);
for (Study study : studies) {
boolean includeHeader = studies.indexOf(study) == 0;
exporter.exportStudy(study, writer, includeHeader);
}
closeStream(filePath, writer);
} catch (IOException e) {
throw new StudyImporterException("failed to export unmatched source taxa", e);
}
}
use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.
the class ExporterSiteMapForNames method export.
@Override
public void export(GraphDatabaseService graphDatabase, String baseDir) throws StudyImporterException {
Set<String> names = new HashSet<String>();
names.add("Homo sapiens");
// just do it once
final List<Study> allStudies = NodeUtil.findAllStudies(graphDatabase);
for (Study allStudy : allStudies) {
final Iterable<Relationship> specimens = NodeUtil.getSpecimens(allStudy);
for (Relationship specimen : specimens) {
final Iterable<Relationship> relationships = specimen.getEndNode().getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
if (relationships.iterator().hasNext()) {
final Node endNode = relationships.iterator().next().getEndNode();
final TaxonNode taxonNode = new TaxonNode(endNode);
names.add(taxonNode.getName());
}
}
}
final String queryParamName = "interactionType=interactsWith&sourceTaxon=";
final String siteMapLocation = "https://depot.globalbioticinteractions.org/snapshot/target/data/sitemap/names/";
SiteMapUtils.generateSiteMap(names, baseDir, queryParamName, siteMapLocation);
}
Aggregations