comparison app/query.service.ts @ 32:4c046f3244ec

new 'id_is' query type. new '_type' attribute.
author casties
date Tue, 02 Feb 2016 19:20:44 +0100
parents 193271b6b9d2
children e19d4c5e10a1
comparison
equal deleted inserted replaced
31:4926885f8a99 32:4c046f3244ec
14 export class QueryService { 14 export class QueryService {
15 15
16 //public neo4jBaseUrl = 'https://ismi-dev.mpiwg-berlin.mpg.de/neo4j-ismi/db/data'; 16 //public neo4jBaseUrl = 'https://ismi-dev.mpiwg-berlin.mpg.de/neo4j-ismi/db/data';
17 public neo4jBaseUrl = 'http://localhost:7474/db/data'; 17 public neo4jBaseUrl = 'http://localhost:7474/db/data';
18 public neo4jAuthentication = {'user': 'neo4j', 'password': 'neo5j'}; 18 public neo4jAuthentication = {'user': 'neo4j', 'password': 'neo5j'};
19 public excludedAttributes = {'type': true}; 19 public typeAttribute = '_type';
20 public excludedAttributes = {};
20 public invRelPrefix = '<- '; 21 public invRelPrefix = '<- ';
21 public state: QueryState; 22 public state: QueryState;
22 public objectTypes: string[]; 23 public objectTypes: string[];
23 24
24 constructor(private _http: Http) { 25 constructor(private _http: Http) {
114 queryReturn = `RETURN n${nIdx}`; 115 queryReturn = `RETURN n${nIdx}`;
115 returnType = 'node'; 116 returnType = 'node';
116 } 117 }
117 118
118 /* 119 /*
120 * step: object id is
121 */
122 if (mode === 'id_is') {
123 if (!queryMatch) {
124 // first step - use match clause
125 queryMatch = `MATCH (n${nIdx} {ismi_id: {att_val${stepIdx}}})`;
126 queryParams[`att_val${stepIdx}`] = parseInt(params.value, 10);
127 queryWhere = '';
128 queryReturn = `RETURN n${nIdx}`;
129 returnType = 'node';
130 } else {
131 // use where clause
132 if (!queryWhere) {
133 queryWhere = 'WHERE ';
134 } else {
135 queryWhere += ' AND ';
136 }
137 queryWhere += `n${nIdx}.ismi_id = {att_val${stepIdx}}`;
138 queryParams[`att_val${stepIdx}`] = parseInt(params.value, 10);
139 }
140 }
141
142 /*
119 * step: relation type is 143 * step: relation type is
120 */ 144 */
121 if (mode === 'relation_is') { 145 if (mode === 'relation_is') {
122 nIdx += 1; 146 nIdx += 1;
123 var rel = params.relationType; 147 var rel = params.relationType;
172 queryParams[`att_nhi${stepIdx}`] = params.numHi; 196 queryParams[`att_nhi${stepIdx}`] = params.numHi;
173 } 197 }
174 198
175 }); 199 });
176 // compose query 200 // compose query
177 resultQuery = queryMatch + '\n' + queryWhere + '\n' + queryReturn; 201 resultQuery = queryMatch + (queryWhere ? '\n'+queryWhere : '') + '\n' + queryReturn;
178 // compose query for attributes of result 202 // compose query for attributes of result
179 attributesQuery = queryMatch + ' ' + queryWhere + ` WITH DISTINCT keys(n${nIdx}) AS atts` 203 attributesQuery = queryMatch + ' ' + queryWhere + ` WITH DISTINCT keys(n${nIdx}) AS atts`
180 + ` UNWIND atts AS att RETURN DISTINCT att ORDER BY att`; 204 + ` UNWIND atts AS att RETURN DISTINCT att ORDER BY att`;
181 // compose query for relations of result 205 // compose query for relations of result
182 relationsQuery = queryMatch + '-[r]-() ' + queryWhere + ' RETURN DISTINCT type(r)'; 206 relationsQuery = queryMatch + '-[r]-() ' + queryWhere + ' RETURN DISTINCT type(r)';
217 * results for result table 241 * results for result table
218 */ 242 */
219 this.state.results = data.results[resIdx].data.map(elem => elem.row[0]); 243 this.state.results = data.results[resIdx].data.map(elem => elem.row[0]);
220 this.state.numResults = this.state.results.length; 244 this.state.numResults = this.state.results.length;
221 // count all types 245 // count all types
222 var resTypes = {}; 246 let resTypes = {};
223 this.state.results.forEach((r) => { 247 this.state.results.forEach((r) => {
224 if (resTypes[r.type] == null) { 248 let t = r[this.typeAttribute];
225 resTypes[r.type] = 1; 249 if (resTypes[t] == null) {
250 resTypes[t] = 1;
226 } else { 251 } else {
227 resTypes[r.type] += 1; 252 resTypes[t] += 1;
228 } 253 }
229 }); 254 });
230 var info = ''; 255 let info = '';
231 for (var t in resTypes) { 256 for (var t in resTypes) {
232 info += t + '(' + resTypes[t] + ') '; 257 info += t + '(' + resTypes[t] + ') ';
233 } 258 }
234 info = info.substr(0, info.length-1); 259 info = info.substr(0, info.length-1);
235 this.state.resultInfo = info; 260 this.state.resultInfo = info;