Mercurial > hg > ng2-query-ismi
comparison app/query.service.ts @ 39:7578b21cdf2e
make relation types configurable.
relations can have custom labels for incoming or outgoing direction.
author | casties |
---|---|
date | Sun, 14 Feb 2016 19:40:07 +0100 |
parents | e8dc6a4c6773 |
children | 896ae7eefb33 |
comparison
equal
deleted
inserted
replaced
38:313a5360c2d3 | 39:7578b21cdf2e |
---|---|
7 import {QueryMode, QUERY_MODES, FIRST_QUERY_MODES} from './query-mode'; | 7 import {QueryMode, QUERY_MODES, FIRST_QUERY_MODES} from './query-mode'; |
8 import {QueryState} from './query-state'; | 8 import {QueryState} from './query-state'; |
9 import {QueryStep} from './query-step'; | 9 import {QueryStep} from './query-step'; |
10 import {getResultType} from './result-type'; | 10 import {getResultType} from './result-type'; |
11 import {ISMI_RESULT_TYPES} from './ismi-result-types'; | 11 import {ISMI_RESULT_TYPES} from './ismi-result-types'; |
12 import {getRelationType} from './ismi-relation-types'; | |
12 | 13 |
13 @Injectable() | 14 @Injectable() |
14 export class QueryService { | 15 export class QueryService { |
15 | 16 |
16 public neo4jBaseUrl = 'https://ismi-dev.mpiwg-berlin.mpg.de/neo4j-ismi/db/data'; | 17 //public neo4jBaseUrl = 'https://ismi-dev.mpiwg-berlin.mpg.de/neo4j-ismi/db/data'; |
17 //public neo4jBaseUrl = 'http://localhost:7474/db/data'; | 18 public neo4jBaseUrl = 'http://localhost:7474/db/data'; |
18 public neo4jAuthentication = {'user': 'neo4j', 'password': 'neo5j'}; | 19 public neo4jAuthentication = {'user': 'neo4j', 'password': 'neo5j'}; |
19 public typeAttribute = '_type'; | 20 public typeAttribute = '_type'; |
20 public excludedAttributes = {}; | 21 public excludedAttributes = {}; |
21 public invRelPrefix = '<- '; | |
22 public state: QueryState; | 22 public state: QueryState; |
23 public objectTypes: string[]; | 23 public objectTypes: string[]; |
24 | 24 |
25 constructor(private _http: Http) { | 25 constructor(private _http: Http) { |
26 // init query state | 26 // init query state |
147 /* | 147 /* |
148 * step: relation type is | 148 * step: relation type is |
149 */ | 149 */ |
150 if (mode === 'relation_is') { | 150 if (mode === 'relation_is') { |
151 nIdx += 1; | 151 nIdx += 1; |
152 var rel = params.relationType; | 152 let rel = params.relationType; |
153 if (rel.indexOf(this.invRelPrefix) == 0) { | 153 if (rel.isOutgoing()) { |
154 queryMatch += `-[:\`${rel.getName()}\`]->(n${nIdx})`; | |
155 } else { | |
154 // inverse relation | 156 // inverse relation |
155 rel = rel.substr(this.invRelPrefix.length); | 157 queryMatch += `<-[:\`${rel.getName()}\`]-(n${nIdx})`; |
156 queryMatch += `<-[:${rel}]-(n${nIdx})`; | 158 } |
157 } else { | 159 queryReturn = `RETURN DISTINCT n${nIdx}`; |
158 queryMatch += `-[:${rel}]->(n${nIdx})`; | |
159 } | |
160 queryReturn = `RETURN n${nIdx}`; | |
161 returnType = 'node'; | 160 returnType = 'node'; |
162 } | 161 } |
163 | 162 |
164 /* | 163 /* |
165 * step: attribute contains(_norm) | 164 * step: attribute contains(_norm) |
290 */ | 289 */ |
291 if (this.state.outRelsCypherQuery) { | 290 if (this.state.outRelsCypherQuery) { |
292 // outgoing aka forward relations | 291 // outgoing aka forward relations |
293 resIdx += 1; | 292 resIdx += 1; |
294 let rels = data.results[resIdx].data.map(elem => elem.row[0]) | 293 let rels = data.results[resIdx].data.map(elem => elem.row[0]) |
295 .filter(elem => elem[0] != "_"); | 294 .filter(elem => elem[0] != "_") |
295 .map(elem => getRelationType(elem, true)); | |
296 this.state.resultRelations = rels; | 296 this.state.resultRelations = rels; |
297 } | 297 } |
298 if (this.state.inRelsCypherQuery) { | 298 if (this.state.inRelsCypherQuery) { |
299 // incoming aka reverse relations | 299 // incoming aka reverse relations |
300 resIdx += 1; | 300 resIdx += 1; |
301 let rels = data.results[resIdx].data.map(elem => elem.row[0]) | 301 let rels = data.results[resIdx].data.map(elem => elem.row[0]) |
302 .filter(elem => elem[0] != "_") | 302 .filter(elem => elem[0] != "_") |
303 .map((r) => this.invRelPrefix + r); | 303 .map(elem => getRelationType(elem, false)); |
304 this.state.resultRelations = this.state.resultRelations.concat(rels); | 304 this.state.resultRelations = this.state.resultRelations.concat(rels); |
305 } | 305 } |
306 }, | 306 }, |
307 err => console.error("neo4j result error=", err), | 307 err => console.error("neo4j result error=", err), |
308 () => console.debug('neo4j result query Complete') | 308 () => console.debug('neo4j result query Complete') |