use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.
the class CypherQueryBuilderTest method findNumberOfStudiesForDistinctInteractionsAccordingTo.
@Test
public void findNumberOfStudiesForDistinctInteractionsAccordingTo() throws IOException {
HashMap<String, String[]> params = new HashMap<String, String[]>() {
{
put("targetTaxon", new String[] { "Arthropoda" });
put("accordingTo", new String[] { "someSource" });
put("field", new String[] { "source_taxon_name", "target_taxon_name", "number_of_interactions", "number_of_studies", "number_of_sources" });
}
};
CypherQuery query = buildInteractionQuery(params, MULTI_TAXON_DISTINCT);
assertThat(query.getQuery(), is("START study = node:studies('*:*') " + "WHERE (has(study.externalId) AND study.externalId =~ {accordingTo}) OR (has(study.citation) AND study.citation =~ {accordingTo}) OR (has(study.source) AND study.source =~ {accordingTo}) " + "WITH study " + "MATCH sourceTaxon<-[:CLASSIFIED_AS]-sourceSpecimen-[interaction:" + createInteractionTypeSelector(Collections.emptyList()) + "]" + "->targetSpecimen-[:CLASSIFIED_AS]->targetTaxon, sourceSpecimen<-[collected_rel:COLLECTED]-study " + "WHERE (has(targetTaxon.externalIds) AND targetTaxon.externalIds =~ '(.*(Arthropoda).*)') " + "WITH distinct targetTaxon, interaction.label as iType, sourceTaxon, count(interaction) as interactionCount, count(distinct(id(study))) as studyCount, count(distinct(study.source?)) as sourceCount " + "RETURN sourceTaxon.name as source_taxon_name,targetTaxon.name as target_taxon_name,interactionCount as number_of_interactions,studyCount as number_of_studies,sourceCount as number_of_sources"));
Map<String, String> expected = new HashMap<String, String>() {
{
put("target_taxon_name", "path:\\\"Arthropoda\\\"");
put("accordingTo", ".*(\\\\QsomeSource\\\\E).*");
}
};
assertThat(query.getParams(), is(expected));
}
use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.
the class CypherQueryBuilderTest method findInteractionsAccordingToNoTaxa.
@Test
public void findInteractionsAccordingToNoTaxa() throws IOException {
HashMap<String, String[]> params = new HashMap<String, String[]>() {
{
put("accordingTo", new String[] { "inaturalist" });
put("field", new String[] { "source_taxon_name", "target_taxon_name" });
}
};
CypherQuery query = buildInteractionQuery(params, MULTI_TAXON_DISTINCT);
assertThat(query.getQuery(), is("START study = node:studies('*:*') WHERE (has(study.externalId) AND study.externalId =~ {accordingTo}) OR (has(study.citation) AND study.citation =~ {accordingTo}) OR (has(study.source) AND study.source =~ {accordingTo}) WITH study " + EXPECTED_MATCH_CLAUSE_DISTINCT + "WITH distinct targetTaxon, interaction.label as iType, sourceTaxon RETURN sourceTaxon.name as source_taxon_name,targetTaxon.name as target_taxon_name"));
assertThat(query.getParams().toString(), is(is("{accordingTo=.*(\\\\Qinaturalist\\\\E).*}")));
}
use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.
the class CypherQueryBuilderTest method findTaxaAtLocationsKillDistinctInteractionTypes.
@Test
public void findTaxaAtLocationsKillDistinctInteractionTypes() throws IOException {
HashMap<String, String[]> params = new HashMap<String, String[]>() {
{
put("bbox", new String[] { "-67.87,12.79,-57.08,23.32" });
put("interactionType", new String[] { "kills", "parasiteOf" });
}
};
CypherQuery query = CypherQueryBuilder.createDistinctTaxaInLocationQuery(params);
assertThat(query.getQuery(), is("START loc = node:locations('latitude:*') WHERE has(loc.latitude) AND has(loc.longitude) AND loc.latitude < 23.32 AND loc.longitude > -67.87 AND loc.latitude > 12.79 AND loc.longitude < -57.08 WITH loc MATCH taxon<-[:CLASSIFIED_AS]-specimen-[:COLLECTED_AT]->loc, taxon-[:" + InteractUtil.interactionsCypherClause(KILLS, PARASITE_OF) + "]->otherTaxon RETURN distinct(taxon.name?) as taxon_name, taxon.commonNames? as taxon_common_names, taxon.externalId? as taxon_external_id, taxon.path? as taxon_path, taxon.pathIds? as taxon_path_ids, taxon.pathNames? as taxon_path_ranks"));
assertThat(query.getParams().isEmpty(), is(true));
}
use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.
the class CypherQueryBuilderTest method findInteractionForTargetTaxaOnlyByInteractionTypeDistinct.
@Test
public void findInteractionForTargetTaxaOnlyByInteractionTypeDistinct() throws IOException {
HashMap<String, String[]> params = new HashMap<String, String[]>() {
{
put("sourceTaxon", new String[] { "Arthropoda" });
put("targetTaxon", new String[] { "Mammalia" });
put("interactionType", new String[] { "preysOn", "parasiteOf" });
}
};
String expectedQuery = "START sourceTaxon = node:taxonPaths({source_taxon_name}) " + expectedMatchClause(expectedInteractionClause(PREYS_UPON, PARASITE_OF), false, false) + EXTERNAL_WHERE_CLAUSE_MAMMALIA + EXPECTED_RETURN_CLAUSE_DISTINCT;
CypherQuery query = buildInteractionQuery(params, MULTI_TAXON_DISTINCT);
assertThat(query.getQuery(), is(expectedQuery));
assertThat(query.getParams().toString(), is("{source_taxon_name=path:\\\"Arthropoda\\\", target_taxon_name=path:\\\"Mammalia\\\"}"));
}
use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.
the class CypherQueryBuilderTest method locationsAccordingTo.
@Test
public void locationsAccordingTo() {
Map<String, String> params = new HashMap<String, String>() {
{
put("accordingTo", "some source");
}
};
final CypherQuery locationsQuery = locations(params);
assertThat(locationsQuery.getQuery(), is(EXPECTED_ACCORDING_TO_START_CLAUSE + "MATCH study-[:COLLECTED]->specimen-[:COLLECTED_AT]->location WITH DISTINCT(location) as loc RETURN loc.latitude? as latitude, loc.longitude? as longitude, loc.footprintWKT? as footprintWKT"));
assertThat(locationsQuery.getParams().toString(), is("{accordingTo=.*(\\\\Qsome source\\\\E).*}"));
}
Aggregations