use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.
the class CypherQueryBuilderTest method findInteractionsAccordingToWithSourceTaxonIdOnlyAndExactMatchOnlyIncludeObservations2.
@Test
public void findInteractionsAccordingToWithSourceTaxonIdOnlyAndExactMatchOnlyIncludeObservations2() throws IOException {
HashMap<String, String[]> params = new HashMap<String, String[]>() {
{
put("exactNameMatchOnly", new String[] { "true" });
put("sourceTaxon", new String[] { "EOL:123" });
put("targetTaxon", new String[] { "Insecta" });
put("field", new String[] { "source_taxon_name", "target_taxon_name" });
}
};
CypherQuery query = buildInteractionQuery(params, MULTI_TAXON_ALL);
assertThat(query.getQuery(), is("START sourceTaxon = node:taxons({source_taxon_name}) " + EXPECTED_MATCH_CLAUSE_ALL + "WHERE (has(targetTaxon.name) AND targetTaxon.name IN ['Insecta'])" + " RETURN sourceTaxon.name as source_taxon_name,targetTaxon.name as target_taxon_name"));
assertThat(query.getParams().toString(), is(is("{source_taxon_name=externalId:\\\"EOL:123\\\", target_taxon_name=name:\\\"Insecta\\\"}")));
}
use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.
the class CypherQueryBuilderTest method findInteractionForSourceAndTargetTaxaLocationsDistinctTaxonNamesOnlyFlippedFields.
@Test
public void findInteractionForSourceAndTargetTaxaLocationsDistinctTaxonNamesOnlyFlippedFields() throws IOException {
HashMap<String, String[]> params = new HashMap<String, String[]>() {
{
put("sourceTaxon", new String[] { "Actinopterygii", "Chordata" });
put("targetTaxon", new String[] { "Arthropoda" });
put("bbox", new String[] { "-67.87,12.79,-57.08,23.32" });
put("field", new String[] { "target_taxon_name", "source_taxon_name", "source_taxon_path_ranks" });
}
};
CypherQuery query = buildInteractionQuery(params, MULTI_TAXON_DISTINCT);
assertThat(query.getQuery(), is("START sourceTaxon = node:taxonPaths({source_taxon_name}) " + EXPECTED_MATCH_CLAUSE_SPATIAL + "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 AND " + hasTargetTaxon("Arthropoda") + "WITH distinct targetTaxon, interaction.label as iType, sourceTaxon RETURN targetTaxon.name as target_taxon_name,sourceTaxon.name as source_taxon_name,sourceTaxon.pathNames? as source_taxon_path_ranks"));
assertThat(query.getParams().toString(), is(is("{source_taxon_name=path:\\\"Actinopterygii\\\" OR path:\\\"Chordata\\\", target_taxon_name=path:\\\"Arthropoda\\\"}")));
}
use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.
the class CypherQueryBuilderTest method findInteractionsAccordingToWithTargetTaxaOnly.
@Test
public void findInteractionsAccordingToWithTargetTaxaOnly() throws IOException {
HashMap<String, String[]> params = new HashMap<String, String[]>() {
{
put("accordingTo", new String[] { "inaturalist" });
put("targetTaxon", new String[] { "Arthropoda" });
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 + "WHERE " + hasTargetTaxon("Arthropoda") + "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).*, target_taxon_name=path:\\\"Arthropoda\\\"}")));
}
use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.
the class CypherQueryBuilderTest method findInteractionTypesForTaxon.
@Test
public void findInteractionTypesForTaxon() {
HashMap<String, String[]> params = new HashMap<String, String[]>() {
{
put("taxon", new String[] { "Actinopterygii", "Chordata" });
}
};
CypherQuery query = CypherQueryBuilder.buildInteractionTypeQuery(params);
String concatInteractionTypes = InteractUtil.allInteractionsCypherClause();
assertThat(query.getQuery(), is("START taxon = node:taxonPaths({taxon_name}) MATCH taxon-[rel:" + concatInteractionTypes + "]->otherTaxon RETURN distinct(type(rel)) as interaction_type"));
assertThat(query.getParams().toString(), is(is("{taxon_name=path:\\\"Actinopterygii\\\" OR path:\\\"Chordata\\\"}")));
}
use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.
the class CypherQueryBuilderTest method findTaxaAtLocationsDistinctInteractionTypes.
@Test
public void findTaxaAtLocationsDistinctInteractionTypes() 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[] { "preysOn", "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(PREYS_UPON, 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));
}
Aggregations