# HG changeset patch # User Robert Casties # Date 1453403252 -3600 # Node ID 65bb467abcc617d9bbe7a25fba391918afbe205c # Parent f6af2c8347de5947d5601d42b63935849ce4b59b inverse relations are now generated on the fly. diff -r f6af2c8347de -r 65bb467abcc6 app/query.service.ts --- 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),