Mercurial > hg > ng2-query-ismi
changeset 18:65bb467abcc6
inverse relations are now generated on the fly.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 21 Jan 2016 20:07:32 +0100 |
parents | f6af2c8347de |
children | d75224bb8147 |
files | app/query.service.ts |
diffstat | 1 files changed, 17 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/app/query.service.ts Thu Jan 21 19:30:57 2016 +0100 +++ b/app/query.service.ts Thu Jan 21 20:07:32 2016 +0100 @@ -15,6 +15,7 @@ public openMindBaseUrl = 'https://ismi-dev.mpiwg-berlin.mpg.de/om4-ismi/'; //public openMindBaseUrl = 'http://localhost:18080/ismi-richfaces/'; public excludedAttributes = {'type': true}; + public invRelPrefix = '<- '; public state: QueryState; public ismiObjectTypes: any; @@ -46,6 +47,7 @@ getQueryOptions(queryMode: QueryMode) { var options = []; + if (queryMode == null) return options; if (queryMode.id === 'type_is') { options = this.ismiObjectTypes; } else if (queryMode.id === 'relation_is') { @@ -109,7 +111,14 @@ */ if (step.mode.id === 'relation_is') { nIdx += 1; - queryMatch += `-[:\`${step.relationType}\`]->(n${nIdx})`; + var rel = step.relationType; + if (rel.indexOf(this.invRelPrefix) == 0) { + // inverse relation + rel = rel.substr(this.invRelPrefix.length); + queryMatch += `<-[:${rel}]-(n${nIdx})`; + } else { + queryMatch += `-[:\`${rel}\`]->(n${nIdx})`; + } queryReturn = `RETURN n${nIdx}`; returnType = 'node'; } @@ -155,9 +164,12 @@ } }); + // compose query resultQuery = queryMatch + '\n' + queryWhere + '\n' + queryReturn; + // compose query for attributes of result attributesQuery = queryMatch + ' ' + queryWhere + ` WITH DISTINCT keys(n${nIdx}) AS atts` + ` UNWIND atts AS att RETURN DISTINCT att ORDER BY att`; + // compose query for relations of result relationsQuery = queryMatch + '-[r]-() ' + queryWhere + ' RETURN DISTINCT type(r)'; this.state.resultCypherQuery = resultQuery; this.state.cypherQueryParams = queryParams; @@ -222,8 +234,11 @@ */ if (this.state.relationsCypherQuery) { resIdx += 1; - this.state.nextQueryRelations = data.results[resIdx].data.map(elem => elem.row[0]) + var rels = data.results[resIdx].data.map(elem => elem.row[0]) .filter(elem => elem[0] != "_"); + // add inverse relations + var invrels = rels.concat(rels.map((r) => this.invRelPrefix + r)); + this.state.nextQueryRelations = invrels; } }, err => console.error("neo4j result error=", err),