use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.
the class CypherQueryBuilderTest method findInteractionForSourceAndTargetTaxaNoLocation.
@Test
public void findInteractionForSourceAndTargetTaxaNoLocation() throws IOException {
HashMap<String, String[]> params = new HashMap<String, String[]>() {
{
put("sourceTaxon", new String[] { "Actinopterygii", "Chordata" });
put("targetTaxon", new String[] { "Arthropoda" });
}
};
String expectedQuery = "START sourceTaxon = node:taxonPaths({source_taxon_name}) " + EXPECTED_MATCH_CLAUSE_ALL + "WHERE " + hasTargetTaxon("Arthropoda") + EXPECTED_RETURN_CLAUSE;
CypherQuery query = buildInteractionQuery(params, MULTI_TAXON_ALL);
assertThat(query.getQuery(), is(expectedQuery));
assertThat(query.getParams().toString(), 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 accordingToDataset.
@Test
public void accordingToDataset() throws IOException {
HashMap<String, String[]> params = new HashMap<String, String[]>() {
{
put("targetTaxon", new String[] { "Arthropoda" });
put("accordingTo", new String[] { "globi:some/namespace" });
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 dataset = node:datasets({accordingTo}) " + "MATCH study-[:IN_DATASET]->dataset " + "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", "namespace:(some/namespace)");
}
};
assertThat(query.getParams(), is(expected));
}
use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.
the class CypherQueryBuilderTest method findTaxaAtLocationsDistinctInteractionTypesSpecificFields.
@Test
public void findTaxaAtLocationsDistinctInteractionTypesSpecificFields() 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" });
put("field", new String[] { ResultField.TAXON_NAME.getLabel() });
}
};
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"));
assertThat(query.getParams().isEmpty(), is(true));
}
use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.
the class CypherQueryBuilderTest method findPreysOnWithLocation.
@Test
public void findPreysOnWithLocation() throws IOException {
HashMap<String, String[]> params = new HashMap<String, String[]>() {
{
put("bbox", new String[] { "-67.87,12.79,-57.08,23.32" });
}
};
CypherQuery query = buildInteractionQuery("Homo sapiens", "preysOn", "Plantae", params, SINGLE_TAXON_ALL);
assertThat(query.getQuery(), is("START sourceTaxon = node:taxonPaths({source_taxon_name}) MATCH sourceTaxon<-[:CLASSIFIED_AS]-sourceSpecimen-[interaction:PREYS_UPON]->targetSpecimen-[:CLASSIFIED_AS]->targetTaxon, sourceSpecimen<-[collected_rel:COLLECTED]-study, sourceSpecimen-[:COLLECTED_AT]->loc 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 " + HAS_TARGET_TAXON_PLANTAE + expectedReturnClause()));
assertThat(query.getParams().toString(), is("{source_taxon_name=path:\\\"Homo sapiens\\\", target_taxon_name=path:\\\"Plantae\\\"}"));
}
use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.
the class CypherQueryBuilderTest method findPlantParasiteObservationsWithoutLocation.
@Test
public void findPlantParasiteObservationsWithoutLocation() throws IOException {
HashMap<String, String[]> params = new HashMap<String, String[]>();
CypherQuery query = buildInteractionQuery("Homo sapiens", "parasiteOf", "Plantae", params, SINGLE_TAXON_ALL);
assertThat(query.getQuery(), is("START sourceTaxon = node:taxonPaths({source_taxon_name}) MATCH sourceTaxon<-[:CLASSIFIED_AS]-sourceSpecimen-[interaction:" + InteractUtil.interactionsCypherClause(PARASITE_OF) + "]->targetSpecimen-[:CLASSIFIED_AS]->targetTaxon, sourceSpecimen<-[collected_rel:COLLECTED]-study, sourceSpecimen-[?:COLLECTED_AT]->loc WHERE " + HAS_TARGET_TAXON_PLANTAE + expectedReturnClause()));
assertThat(query.getParams().toString(), is("{source_taxon_name=path:\\\"Homo sapiens\\\", target_taxon_name=path:\\\"Plantae\\\"}"));
}
Aggregations