Search in sources :

Example 56 with CypherQuery

use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.

the class CypherQueryBuilderTest method statsWithBBox.

@Test
public void statsWithBBox() throws IOException {
    HashMap<String, String[]> params = new HashMap<String, String[]>() {

        {
            put("bbox", new String[] { "-67.87,12.79,-57.08,23.32" });
        }
    };
    CypherQuery query = spatialInfo(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 sourceTaxon<-[:CLASSIFIED_AS]-sourceSpecimen<-[c:COLLECTED]-study, sourceSpecimen-[interact]->targetSpecimen-[:CLASSIFIED_AS]->targetTaxon, sourceSpecimen-[:COLLECTED_AT]->loc WHERE not(has(interact.inverted)) RETURN count(distinct(study)) as `number of distinct studies`, count(interact) as `number of interactions`, count(distinct(sourceTaxon.name)) as `number of distinct source taxa (e.g. predators)`, count(distinct(targetTaxon.name)) as `number of distinct target taxa (e.g. prey)`, count(distinct(study.source)) as `number of distinct study sources`, count(c.dateInUnixEpoch?) as `number of interactions with timestamp`, count(distinct(loc)) as `number of distinct locations`, count(distinct(sourceTaxon.name + type(interact) + targetTaxon.name)) as `number of distinct interactions`"));
    assertThat(query.getParams().toString(), is("{}"));
}
Also used : HashMap(java.util.HashMap) CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Example 57 with CypherQuery

use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.

the class CypherQueryBuilderTest method findInteractionForTargetTaxaOnlyByInteractionType.

@Test
public void findInteractionForTargetTaxaOnlyByInteractionType() 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, true) + EXTERNAL_WHERE_CLAUSE_MAMMALIA + EXPECTED_RETURN_CLAUSE;
    CypherQuery query = buildInteractionQuery(params, MULTI_TAXON_ALL);
    assertThat(query.getQuery(), is(expectedQuery));
    assertThat(query.getParams().toString(), is("{source_taxon_name=path:\\\"Arthropoda\\\", target_taxon_name=path:\\\"Mammalia\\\"}"));
}
Also used : HashMap(java.util.HashMap) CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Example 58 with CypherQuery

use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.

the class CypherQueryBuilderTest method findInteractionsAccordingToWithSourceTaxaOnlyAndExactMatchOnly.

@Test
public void findInteractionsAccordingToWithSourceTaxaOnlyAndExactMatchOnly() throws IOException {
    HashMap<String, String[]> params = new HashMap<String, String[]>() {

        {
            put("exactNameMatchOnly", new String[] { "true" });
            put("accordingTo", new String[] { "inaturalist" });
            put("sourceTaxon", 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 (has(sourceTaxon.name) AND sourceTaxon.name IN ['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).*, source_taxon_name=name:\\\"Arthropoda\\\"}")));
}
Also used : HashMap(java.util.HashMap) CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Example 59 with CypherQuery

use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.

the class CypherQueryBuilderTest method findInteractionsAccordingToWithSourceTaxonIdTargetTaxonIdAndNameOnlyAndExactMatchOnlyIncludeObservations2.

@Test
public void findInteractionsAccordingToWithSourceTaxonIdTargetTaxonIdAndNameOnlyAndExactMatchOnlyIncludeObservations2() throws IOException {
    HashMap<String, String[]> params = new HashMap<String, String[]>() {

        {
            put("exactNameMatchOnly", new String[] { "true" });
            put("sourceTaxon", new String[] { "Arthropoda" });
            put("targetTaxon", new String[] { "EOL:123", "some name" });
            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 ['some name'])" + " OR (has(targetTaxon.externalId) AND targetTaxon.externalId IN ['EOL:123'])" + " RETURN sourceTaxon.name as source_taxon_name,targetTaxon.name as target_taxon_name"));
    assertThat(query.getParams().toString(), is(is("{source_taxon_name=name:\\\"Arthropoda\\\", target_taxon_name=externalId:\\\"EOL:123\\\" OR name:\\\"some name\\\"}")));
}
Also used : HashMap(java.util.HashMap) CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Example 60 with CypherQuery

use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.

the class CypherQueryBuilderTest method findTaxaAtLocationsDistinctNoSpatialInteractTypesParam.

@Test
public void findTaxaAtLocationsDistinctNoSpatialInteractTypesParam() throws IOException {
    HashMap<String, String[]> params = new HashMap<String, String[]>() {

        {
            put("interactionType", new String[] { "preysOn", "parasiteOf" });
        }
    };
    CypherQuery query = CypherQueryBuilder.createDistinctTaxaInLocationQuery(params);
    assertThat(query.getQuery(), is("START taxon = node:taxons('*:*') MATCH 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));
}
Also used : HashMap(java.util.HashMap) CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Aggregations

CypherQuery (org.eol.globi.util.CypherQuery)109 Test (org.junit.Test)92 HashMap (java.util.HashMap)66 Matchers.containsString (org.hamcrest.Matchers.containsString)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Map (java.util.Map)4 ResultField (org.eol.globi.server.util.ResultField)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 TreeMap (java.util.TreeMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 JsonNode (org.codehaus.jackson.JsonNode)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 InteractionTypeExternal (org.eol.globi.server.util.InteractionTypeExternal)1 ResultFormatterCSV (org.eol.globi.server.util.ResultFormatterCSV)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1