Search in sources :

Example 6 with CypherQuery

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

the class CypherQueryBuilderTest method findInteractionsAccordingToWithTargetTaxaOnlyEmptySource.

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

        {
            put("accordingTo", new String[] { "http://inaturalist.org/bla" });
            put("sourceTaxon", new String[] { "" });
            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}) 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=(\\\\Qhttp://inaturalist.org/bla\\\\E), target_taxon_name=path:\\\"Arthropoda\\\"}")));
}
Also used : HashMap(java.util.HashMap) CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Example 7 with CypherQuery

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

the class CypherQueryBuilderTest method findInteractionsTaxaInteractionIndexTargetTaxaNumberOfInteractionsExcludeChildTaxa.

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

        {
            put("excludeChildTaxa", new String[] { "true" });
            put("targetTaxon", new String[] { "Arthropoda" });
            put("field", new String[] { "source_taxon_name", "target_taxon_name", "number_of_interactions" });
        }
    };
    CypherQuery query = buildInteractionQuery(params, MULTI_TAXON_DISTINCT_BY_NAME_ONLY);
    assertThat(query.getQuery(), is("START targetTaxon = node:taxons({target_taxon_name}) " + "MATCH sourceTaxon-[interaction:" + InteractUtil.interactionsCypherClause(INTERACTS_WITH) + "]->targetTaxon " + "RETURN sourceTaxon.name as source_taxon_name,targetTaxon.name as target_taxon_name,interaction.count as number_of_interactions"));
    Map<String, String> expected = new HashMap<String, String>() {

        {
            put("target_taxon_name", "name:\\\"Arthropoda\\\"");
        }
    };
    assertThat(query.getParams(), is(expected));
}
Also used : HashMap(java.util.HashMap) CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Example 8 with CypherQuery

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

the class CypherQueryBuilderTest method assertFindInteractionsAccordingToWithTaxa.

protected void assertFindInteractionsAccordingToWithTaxa(Map<String, String[]> fieldParams) {
    HashMap<String, String[]> params = new HashMap<String, String[]>() {

        {
            put("accordingTo", new String[] { "inaturalist" });
            put("targetTaxon", new String[] { "Arthropoda" });
            put("sourceTaxon", new String[] { "Arthropoda" });
        }
    };
    params.putAll(fieldParams);
    CypherQuery query = buildInteractionQuery(params, MULTI_TAXON_DISTINCT);
    assertThat(query.getQuery(), is(EXPECTED_ACCORDING_TO_START_CLAUSE + EXPECTED_MATCH_CLAUSE_DISTINCT + "WHERE " + hasTargetTaxon("Arthropoda") + "AND " + hasSourceTaxon("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=path:\\\"Arthropoda\\\", target_taxon_name=path:\\\"Arthropoda\\\"}")));
}
Also used : HashMap(java.util.HashMap) CypherQuery(org.eol.globi.util.CypherQuery)

Example 9 with CypherQuery

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

the class CypherQueryBuilderTest method findInteractionCountOfEnhydraIncludeObservations.

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

        {
            put("sourceTaxon", new String[] { "Enhydra" });
            put("targetTaxon", new String[] { "Arthropoda" });
            put("field", new String[] { "target_taxon_name", "study_citation" });
        }
    };
    CypherQuery query = buildInteractionQuery(params, MULTI_TAXON_ALL);
    assertThat(query.getQuery(), is("START sourceTaxon = node:taxonPaths({source_taxon_name}) " + EXPECTED_MATCH_CLAUSE_ALL + "WHERE " + hasTargetTaxon("Arthropoda") + "RETURN targetTaxon.name as target_taxon_name,study.citation? as study_citation"));
    assertThat(query.getParams().toString(), is(is("{source_taxon_name=path:\\\"Enhydra\\\", target_taxon_name=path:\\\"Arthropoda\\\"}")));
}
Also used : HashMap(java.util.HashMap) CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Example 10 with CypherQuery

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

the class CypherQueryBuilderTest method stats.

@Test
public void stats() throws IOException {
    CypherQuery query = spatialInfo(null);
    assertThat(query.getQuery(), is("START study = node:studies('*:*') " + "MATCH sourceTaxon<-[:CLASSIFIED_AS]-sourceSpecimen<-[c:COLLECTED]-study, sourceSpecimen-[interact]->targetSpecimen-[:CLASSIFIED_AS]->targetTaxon " + "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`, NULL 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 : 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