Search in sources :

Example 51 with CypherQuery

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

the class TaxonSearchUtilTest method createQueryWithUnsupportedId.

@Test
public void createQueryWithUnsupportedId() {
    CypherQuery query = TaxonSearchUtil.getCypherQuery("FOO:1", new HashMap());
    assertThat(query.getVersionedQuery(), Is.is("CYPHER 2.3 START someTaxon = node:taxons({pathQuery}) MATCH someTaxon-[:SAME_AS*0..1]->taxon WHERE exists(taxon.externalId) WITH DISTINCT(taxon.externalId) as externalId, taxon.externalUrl as externalUrl RETURN externalId as taxon_external_id,externalUrl as taxon_external_url"));
    assertThat(query.getParams().toString(), Is.is("{pathQuery=name:\"FOO:1\"}"));
    validate(query);
}
Also used : HashMap(java.util.HashMap) CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Example 52 with CypherQuery

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

the class CypherQueryBuilderTest method findPlantPreyObservationsWithoutLocation.

@Test
public void findPlantPreyObservationsWithoutLocation() {
    HashMap<String, String[]> params = new HashMap<String, String[]>();
    CypherQuery query = buildInteractionQuery("Homo sapiens", "preysOn", "Plantae", params, SINGLE_TAXON_ALL);
    assertThat(query.getVersionedQuery(), is(CYPHER_VERSION + "START sourceTaxon = node:taxonPaths({source_taxon_name}) " + "MATCH sourceTaxon<-[:CLASSIFIED_AS]-sourceSpecimen-[interaction:" + InteractUtil.interactionsCypherClause(PREYS_UPON) + "]->targetSpecimen-[:CLASSIFIED_AS]->targetTaxon, " + "sourceSpecimen<-[collected_rel:COLLECTED]-study-[:IN_DATASET]->dataset " + "WHERE " + HAS_TARGET_TAXON_PLANTAE + "OPTIONAL MATCH sourceSpecimen-[:COLLECTED_AT]->loc " + expectedReturnClause()));
    assertThat(query.getParams().toString(), is("{source_taxon_name=path:\"Homo sapiens\", target_taxon_name=path:\"Plantae\"}"));
}
Also used : HashMap(java.util.HashMap) CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Example 53 with CypherQuery

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

the class CypherQueryBuilderTest method findInteractionForAnimaliaAndAnimalia.

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

        {
            put("sourceTaxon", new String[] { "Animalia" });
            put("targetTaxon", new String[] { "Animalia" });
            put("interactionType", new String[] { "interactsWith" });
            put("field", new String[] { "source_taxon_name", "source_taxon_external_id", "target_taxon_name", "target_taxon_external_id", "interaction_type", "number_of_interactions" });
        }
    };
    String expectedQuery = "START sourceTaxon = node:taxonPaths({source_taxon_name}) MATCH sourceTaxon-[interaction:INTERACTS_WITH|PREYS_UPON|PARASITE_OF|HAS_HOST|HOST_OF|POLLINATES|PERCHING_ON|ATE|SYMBIONT_OF|PREYED_UPON_BY|POLLINATED_BY|EATEN_BY|HAS_PARASITE|PERCHED_ON_BY|HAS_PATHOGEN|PATHOGEN_OF|HAS_VECTOR|VECTOR_OF|VISITED_BY|VISITS|FLOWERS_VISITED_BY|VISITS_FLOWERS_OF|INHABITED_BY|INHABITS|ADJACENT_TO|CREATES_HABITAT_FOR|IS_HABITAT_OF|LIVED_ON_BY|LIVES_ON|LIVED_INSIDE_OF_BY|LIVES_INSIDE_OF|LIVED_NEAR_BY|LIVES_NEAR|LIVED_UNDER_BY|LIVES_UNDER|LIVES_WITH|ENDOPARASITE_OF|HAS_ENDOPARASITE|HYPERPARASITE_OF|HAS_HYPERPARASITE|HYPERPARASITOID_OF|HAS_HYPERPARASITOID|ECTOPARASITE_OF|HAS_ECTOPARASITE|KLEPTOPARASITE_OF|HAS_KLEPTOPARASITE|PARASITOID_OF|HAS_PARASITOID|ENDOPARASITOID_OF|HAS_ENDOPARASITOID|ECTOPARASITOID_OF|HAS_ECTOPARASITOID|GUEST_OF|HAS_GUEST_OF|FARMED_BY|FARMS|DAMAGED_BY|DAMAGES|DISPERSAL_VECTOR_OF|HAS_DISPERAL_VECTOR|KILLED_BY|KILLS|EPIPHITE_OF|HAS_EPIPHITE|LAYS_EGGS_ON|HAS_EGGS_LAYED_ON_BY]->targetTaxon WHERE (has(targetTaxon.externalIds) AND targetTaxon.externalIds =~ '(.*(Animalia).*)') RETURN sourceTaxon.name as source_taxon_name,sourceTaxon.externalId? as source_taxon_external_id,targetTaxon.name as target_taxon_name,targetTaxon.externalId? as target_taxon_external_id,interaction.label? as interaction_type,interaction.count as number_of_interactions";
    CypherQuery query = buildInteractionQuery(params, MULTI_TAXON_DISTINCT_BY_NAME_ONLY);
    assertThat(query.getQuery(), is(expectedQuery));
    assertThat(query.getParams().toString(), is("{source_taxon_name=path:\\\"Animalia\\\", target_taxon_name=path:\\\"Animalia\\\"}"));
}
Also used : HashMap(java.util.HashMap) CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Example 54 with CypherQuery

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

the class CypherQueryBuilderTest method findInteractionsTaxaInteractionIndexInteractionTypeTargetTaxaNumberOfInteractions.

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

        {
            put("sourceTaxon", new String[] { "Mammalia" });
            put("targetTaxon", new String[] { "Arthropoda" });
            put("interactionType", new String[] { "endoparasiteOf" });
            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 sourceTaxon = node:taxonPaths({source_taxon_name}) " + "MATCH sourceTaxon-[interaction:ENDOPARASITE_OF]->targetTaxon " + "WHERE " + hasTargetTaxon("Arthropoda") + "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("source_taxon_name", "path:\\\"Mammalia\\\"");
            put("target_taxon_name", "path:\\\"Arthropoda\\\"");
        }
    };
    assertThat(query.getParams(), is(expected));
}
Also used : HashMap(java.util.HashMap) CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Example 55 with CypherQuery

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

the class CypherQueryBuilderTest method findDistinctPlantPreyWithoutLocation.

@Test
public void findDistinctPlantPreyWithoutLocation() throws IOException {
    HashMap<String, String[]> params = new HashMap<String, String[]>();
    CypherQuery query = buildInteractionQuery("Homo sapiens", "preysOn", "Plantae", params, SINGLE_TAXON_DISTINCT);
    assertThat(query.getQuery(), is("START sourceTaxon = node:taxonPaths({source_taxon_name}) MATCH sourceTaxon<-[:CLASSIFIED_AS]-sourceSpecimen-[interaction:" + InteractUtil.interactionsCypherClause(PREYS_UPON) + "]->targetSpecimen-[:CLASSIFIED_AS]->targetTaxon, sourceSpecimen<-[collected_rel:COLLECTED]-study WHERE " + HAS_TARGET_TAXON_PLANTAE + "RETURN sourceTaxon.name as source_taxon_name,interaction.label as interaction_type,collect(distinct(targetTaxon.name)) as target_taxon_name"));
    assertThat(query.getParams().toString(), is("{source_taxon_name=path:\\\"Homo sapiens\\\", target_taxon_name=path:\\\"Plantae\\\"}"));
}
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