annotate app/query.service.ts @ 35:b47614a9d23d

fix cut and paste error.
author casties
date Wed, 03 Feb 2016 18:40:30 +0100
parents e19d4c5e10a1
children e8dc6a4c6773
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
1 import {Injectable} from 'angular2/core';
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
2 import {Http, Headers} from 'angular2/http';
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
3
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
4 import 'rxjs/Rx'; // import all RxJS operators
22
9343e43a17d1 build with jspm now.
casties
parents: 21
diff changeset
5 //import 'rxjs/add/operator/map';
1
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
6
34
e19d4c5e10a1 restricted selectable options for first query step.
casties
parents: 32
diff changeset
7 import {QueryMode, QUERY_MODES, FIRST_QUERY_MODES} from './query-mode';
5
b06a5d61afed new query state stuff.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 3
diff changeset
8 import {QueryState} from './query-state';
b06a5d61afed new query state stuff.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 3
diff changeset
9 import {QueryStep} from './query-step';
30
193271b6b9d2 configure attributes per result type. select number of items per result page.
casties
parents: 25
diff changeset
10 import {getResultType} from './result-type';
193271b6b9d2 configure attributes per result type. select number of items per result page.
casties
parents: 25
diff changeset
11 import {ISMI_RESULT_TYPES} from './ismi-result-types';
1
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
12
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
13 @Injectable()
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
14 export class QueryService {
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
15
35
b47614a9d23d fix cut and paste error.
casties
parents: 34
diff changeset
16 public neo4jBaseUrl = 'https://ismi-dev.mpiwg-berlin.mpg.de/neo4j-ismi/db/data';
b47614a9d23d fix cut and paste error.
casties
parents: 34
diff changeset
17 //public neo4jBaseUrl = 'http://localhost:7474/db/data';
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
18 public neo4jAuthentication = {'user': 'neo4j', 'password': 'neo5j'};
32
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
19 public typeAttribute = '_type';
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
20 public excludedAttributes = {};
18
65bb467abcc6 inverse relations are now generated on the fly.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 17
diff changeset
21 public invRelPrefix = '<- ';
7
6cd6c09032aa object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 6
diff changeset
22 public state: QueryState;
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
23 public objectTypes: string[];
2
80270f5a5735 more tinkering.
casties
parents: 1
diff changeset
24
5
b06a5d61afed new query state stuff.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 3
diff changeset
25 constructor(private _http: Http) {
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
26 // init query state
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
27 this.state = new QueryState();
7
6cd6c09032aa object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 6
diff changeset
28 }
6cd6c09032aa object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 6
diff changeset
29
8
fa646ee46c19 more query generation.
casties
parents: 7
diff changeset
30 setup() {
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
31 this.setupObjectTypes();
8
fa646ee46c19 more query generation.
casties
parents: 7
diff changeset
32 }
fa646ee46c19 more query generation.
casties
parents: 7
diff changeset
33
7
6cd6c09032aa object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 6
diff changeset
34 getState() {
6cd6c09032aa object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 6
diff changeset
35 return this.state;
5
b06a5d61afed new query state stuff.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 3
diff changeset
36 }
1
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
37
34
e19d4c5e10a1 restricted selectable options for first query step.
casties
parents: 32
diff changeset
38 getQueryModes(index: number): QueryMode[] {
e19d4c5e10a1 restricted selectable options for first query step.
casties
parents: 32
diff changeset
39 if (index == 0) {
e19d4c5e10a1 restricted selectable options for first query step.
casties
parents: 32
diff changeset
40 return FIRST_QUERY_MODES;
e19d4c5e10a1 restricted selectable options for first query step.
casties
parents: 32
diff changeset
41 } else {
e19d4c5e10a1 restricted selectable options for first query step.
casties
parents: 32
diff changeset
42 return QUERY_MODES;
e19d4c5e10a1 restricted selectable options for first query step.
casties
parents: 32
diff changeset
43 }
1
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
44 }
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
45
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
46 /**
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
47 * return the first set of options for the given query mode.
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
48 */
3
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
49 getQueryOptions(queryMode: QueryMode) {
15
f84ff6781e57 added att_num_range query type.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 14
diff changeset
50 var options = [];
18
65bb467abcc6 inverse relations are now generated on the fly.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 17
diff changeset
51 if (queryMode == null) return options;
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
52 if (queryMode.id === 'type_is') {
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
53 options = this.objectTypes;
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
54 } else if (queryMode.id === 'relation_is') {
21
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
55 options = this.state.resultRelations;
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
56 } else if (queryMode.id === 'att_contains') {
21
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
57 options = this.filterAttributes(this.state.resultAttributes);
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
58 } else if (queryMode.id === 'att_contains_norm') {
21
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
59 options = this.filterAttributes(this.state.resultAttributes, true);
15
f84ff6781e57 added att_num_range query type.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 14
diff changeset
60 } else if (queryMode.id === 'att_num_range') {
21
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
61 options = this.filterAttributes(this.state.resultAttributes);
1
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
62 }
5
b06a5d61afed new query state stuff.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 3
diff changeset
63 console.debug("getQueryOptions returns: ", options);
b06a5d61afed new query state stuff.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 3
diff changeset
64 return options;
1
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
65 }
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
66
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
67 /**
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
68 * fetch all object types from Neo4j and store in this.objectTypes.
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
69 */
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
70 setupObjectTypes() {
3
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
71 var query = `MATCH (n) WITH DISTINCT labels(n) AS labels
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
72 UNWIND labels AS label
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
73 RETURN DISTINCT label ORDER BY label`;
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
74
17
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
75 var res = this.fetchCypherResults([query]);
3
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
76 res.subscribe(
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
77 data => {
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
78 console.debug("neo4j data=", data);
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
79 this.objectTypes = data.results[0].data.map(elem => elem.row[0]).filter(elem => elem[0] != "_");
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
80 console.debug("object types=", this.objectTypes);
3
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
81 },
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
82 err => console.error("neo4j error=", err),
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
83 () => console.debug('neo4j query Complete')
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
84 );
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
85 }
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
86
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
87 /**
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
88 * Set the query step at index.
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
89 */
6
9f5473536a98 more query generation.
casties
parents: 5
diff changeset
90 setQueryStep(index: number, step: QueryStep) {
7
6cd6c09032aa object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 6
diff changeset
91 this.state.steps[index] = step;
6
9f5473536a98 more query generation.
casties
parents: 5
diff changeset
92 }
9f5473536a98 more query generation.
casties
parents: 5
diff changeset
93
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
94 /**
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
95 * Create the cypher queries for the current query state.
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
96 *
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
97 * Updates the queries for results, attributes and relations.
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
98 */
6
9f5473536a98 more query generation.
casties
parents: 5
diff changeset
99 createCypherQuery() {
10
66dce99cef4e attribute contains works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 9
diff changeset
100 var queryMatch = '';
66dce99cef4e attribute contains works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 9
diff changeset
101 var queryWhere = '';
66dce99cef4e attribute contains works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 9
diff changeset
102 var queryReturn = '';
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
103 var queryParams = {};
10
66dce99cef4e attribute contains works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 9
diff changeset
104 var resultQuery = '';
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
105 var attributesQuery = '';
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
106 var relationsQuery = '';
7
6cd6c09032aa object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 6
diff changeset
107 var returnType = '';
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
108 var nIdx = 1;
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
109 this.state.steps.forEach((step, stepIdx) => {
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
110 var mode = step.mode.id;
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
111 var params = step.params;
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
112
14
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
113 /*
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
114 * step: object type is
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
115 */
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
116 if (mode === 'type_is') {
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
117 queryMatch = `MATCH (n${nIdx}:${params.objectType})`;
10
66dce99cef4e attribute contains works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 9
diff changeset
118 queryWhere = '';
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
119 queryReturn = `RETURN n${nIdx}`;
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
120 returnType = 'node';
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
121 }
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
122
14
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
123 /*
32
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
124 * step: object id is
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
125 */
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
126 if (mode === 'id_is') {
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
127 if (!queryMatch) {
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
128 // first step - use match clause
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
129 queryMatch = `MATCH (n${nIdx} {ismi_id: {att_val${stepIdx}}})`;
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
130 queryParams[`att_val${stepIdx}`] = parseInt(params.value, 10);
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
131 queryWhere = '';
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
132 queryReturn = `RETURN n${nIdx}`;
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
133 returnType = 'node';
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
134 } else {
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
135 // use where clause
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
136 if (!queryWhere) {
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
137 queryWhere = 'WHERE ';
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
138 } else {
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
139 queryWhere += ' AND ';
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
140 }
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
141 queryWhere += `n${nIdx}.ismi_id = {att_val${stepIdx}}`;
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
142 queryParams[`att_val${stepIdx}`] = parseInt(params.value, 10);
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
143 }
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
144 }
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
145
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
146 /*
14
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
147 * step: relation type is
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
148 */
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
149 if (mode === 'relation_is') {
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
150 nIdx += 1;
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
151 var rel = params.relationType;
18
65bb467abcc6 inverse relations are now generated on the fly.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 17
diff changeset
152 if (rel.indexOf(this.invRelPrefix) == 0) {
65bb467abcc6 inverse relations are now generated on the fly.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 17
diff changeset
153 // inverse relation
65bb467abcc6 inverse relations are now generated on the fly.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 17
diff changeset
154 rel = rel.substr(this.invRelPrefix.length);
65bb467abcc6 inverse relations are now generated on the fly.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 17
diff changeset
155 queryMatch += `<-[:${rel}]-(n${nIdx})`;
65bb467abcc6 inverse relations are now generated on the fly.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 17
diff changeset
156 } else {
19
d75224bb8147 remove quotes for inverse relations.
casties
parents: 18
diff changeset
157 queryMatch += `-[:${rel}]->(n${nIdx})`;
18
65bb467abcc6 inverse relations are now generated on the fly.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 17
diff changeset
158 }
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
159 queryReturn = `RETURN n${nIdx}`;
8
fa646ee46c19 more query generation.
casties
parents: 7
diff changeset
160 returnType = 'node';
fa646ee46c19 more query generation.
casties
parents: 7
diff changeset
161 }
10
66dce99cef4e attribute contains works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 9
diff changeset
162
14
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
163 /*
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
164 * step: attribute contains(_norm)
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
165 */
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
166 if (mode === 'att_contains' || mode === 'att_contains_norm') {
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
167 if (!queryWhere) {
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
168 queryWhere = 'WHERE ';
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
169 } else {
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
170 queryWhere += ' AND ';
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
171 }
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
172 if (params.attribute === 'ismi_id') {
14
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
173 // ismi_id is integer
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
174 queryWhere += `n${nIdx}.ismi_id = {att_val${stepIdx}}`;
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
175 queryParams[`att_val${stepIdx}`] = parseInt(params.value, 10);
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
176 } else {
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
177 if (mode === 'att_contains_norm') {
14
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
178 // match _n_attribute with normValue
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
179 queryWhere += `lower(n${nIdx}._n_${params.attribute}) CONTAINS lower({att_val${stepIdx}})`;
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
180 queryParams[`att_val${stepIdx}`] = params.normValue;
14
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
181 } else {
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
182 queryWhere += `lower(n${nIdx}.${params.attribute}) CONTAINS lower({att_val${stepIdx}})`;
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
183 queryParams[`att_val${stepIdx}`] = params.value;
14
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
184 }
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
185 }
10
66dce99cef4e attribute contains works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 9
diff changeset
186 }
66dce99cef4e attribute contains works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 9
diff changeset
187
15
f84ff6781e57 added att_num_range query type.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 14
diff changeset
188 /*
f84ff6781e57 added att_num_range query type.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 14
diff changeset
189 * step: attribute number range
f84ff6781e57 added att_num_range query type.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 14
diff changeset
190 */
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
191 if (mode === 'att_num_range') {
15
f84ff6781e57 added att_num_range query type.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 14
diff changeset
192 if (!queryWhere) {
f84ff6781e57 added att_num_range query type.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 14
diff changeset
193 queryWhere = 'WHERE ';
f84ff6781e57 added att_num_range query type.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 14
diff changeset
194 } else {
f84ff6781e57 added att_num_range query type.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 14
diff changeset
195 queryWhere += ' AND ';
f84ff6781e57 added att_num_range query type.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 14
diff changeset
196 }
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
197 queryWhere += `toint(n${nIdx}.${params.attribute}) >= toint({att_nlo${stepIdx}})`
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
198 + ` AND toint(n${nIdx}.${params.attribute}) <= toint({att_nhi${stepIdx}})`;
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
199 queryParams[`att_nlo${stepIdx}`] = params.numLo;
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
200 queryParams[`att_nhi${stepIdx}`] = params.numHi;
15
f84ff6781e57 added att_num_range query type.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 14
diff changeset
201 }
f84ff6781e57 added att_num_range query type.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 14
diff changeset
202
9
402c7229dc7c more query generation.
casties
parents: 8
diff changeset
203 });
18
65bb467abcc6 inverse relations are now generated on the fly.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 17
diff changeset
204 // compose query
32
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
205 resultQuery = queryMatch + (queryWhere ? '\n'+queryWhere : '') + '\n' + queryReturn;
18
65bb467abcc6 inverse relations are now generated on the fly.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 17
diff changeset
206 // compose query for attributes of result
15
f84ff6781e57 added att_num_range query type.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 14
diff changeset
207 attributesQuery = queryMatch + ' ' + queryWhere + ` WITH DISTINCT keys(n${nIdx}) AS atts`
f84ff6781e57 added att_num_range query type.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 14
diff changeset
208 + ` UNWIND atts AS att RETURN DISTINCT att ORDER BY att`;
18
65bb467abcc6 inverse relations are now generated on the fly.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 17
diff changeset
209 // compose query for relations of result
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
210 relationsQuery = queryMatch + '-[r]-() ' + queryWhere + ' RETURN DISTINCT type(r)';
10
66dce99cef4e attribute contains works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 9
diff changeset
211 this.state.resultCypherQuery = resultQuery;
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
212 this.state.cypherQueryParams = queryParams;
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
213 this.state.attributesCypherQuery = attributesQuery;
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
214 this.state.relationsCypherQuery = relationsQuery;
7
6cd6c09032aa object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 6
diff changeset
215 this.state.resultTypes = returnType;
6cd6c09032aa object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 6
diff changeset
216 }
6cd6c09032aa object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 6
diff changeset
217
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
218 /**
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
219 * Create and run the cypher queries for the current query state.
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
220 *
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
221 * Updates the results and nextQuery attributes and relations.
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
222 */
7
6cd6c09032aa object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 6
diff changeset
223 updateQuery() {
6cd6c09032aa object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 6
diff changeset
224 this.createCypherQuery();
13
98b435bb6c0c more query work.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 12
diff changeset
225 this.state.resultInfo = 'loading...';
16
7d82ca32833c omit some attributes from list.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 15
diff changeset
226 /*
7d82ca32833c omit some attributes from list.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 15
diff changeset
227 * run query for result table
7d82ca32833c omit some attributes from list.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 15
diff changeset
228 */
17
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
229 var queries = [this.state.resultCypherQuery];
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
230 var params = [this.state.cypherQueryParams];
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
231 if (this.state.attributesCypherQuery) {
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
232 queries.push(this.state.attributesCypherQuery);
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
233 params.push(this.state.cypherQueryParams);
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
234 }
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
235 if (this.state.relationsCypherQuery) {
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
236 queries.push(this.state.relationsCypherQuery);
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
237 params.push(this.state.cypherQueryParams);
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
238 }
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
239 var res = this.fetchCypherResults(queries, params);
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
240 res.subscribe(
7
6cd6c09032aa object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 6
diff changeset
241 data => {
10
66dce99cef4e attribute contains works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 9
diff changeset
242 console.debug("neo4j result data=", data);
17
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
243 var resIdx = 0;
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
244 /*
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
245 * results for result table
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
246 */
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
247 this.state.results = data.results[resIdx].data.map(elem => elem.row[0]);
7
6cd6c09032aa object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 6
diff changeset
248 this.state.numResults = this.state.results.length;
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
249 // count all types
32
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
250 let resTypes = {};
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
251 this.state.results.forEach((r) => {
32
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
252 let t = r[this.typeAttribute];
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
253 if (resTypes[t] == null) {
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
254 resTypes[t] = 1;
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
255 } else {
32
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
256 resTypes[t] += 1;
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
257 }
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
258 });
32
4c046f3244ec new 'id_is' query type. new '_type' attribute.
casties
parents: 30
diff changeset
259 let info = '';
11
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
260 for (var t in resTypes) {
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
261 info += t + '(' + resTypes[t] + ') ';
6989cd00e8d7 relations work now as well as longer queries.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 10
diff changeset
262 }
14
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
263 info = info.substr(0, info.length-1);
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
264 this.state.resultInfo = info;
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
265 // save info also in last step
7dc7ea95ca26 show result types below query steps.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 13
diff changeset
266 this.state.steps[this.state.steps.length-1].resultInfo = info;
17
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
267 /*
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
268 * results for attribute list
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
269 */
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
270 if (this.state.attributesCypherQuery) {
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
271 resIdx += 1;
30
193271b6b9d2 configure attributes per result type. select number of items per result page.
casties
parents: 25
diff changeset
272 let atts = data.results[resIdx].data.map(elem => elem.row[0]);
193271b6b9d2 configure attributes per result type. select number of items per result page.
casties
parents: 25
diff changeset
273 this.state.resultAttributes = atts;
193271b6b9d2 configure attributes per result type. select number of items per result page.
casties
parents: 25
diff changeset
274 // the following assumes only one type in the result
193271b6b9d2 configure attributes per result type. select number of items per result page.
casties
parents: 25
diff changeset
275 for (let t in resTypes) {
193271b6b9d2 configure attributes per result type. select number of items per result page.
casties
parents: 25
diff changeset
276 this.state.resultType = getResultType(t, ISMI_RESULT_TYPES);
193271b6b9d2 configure attributes per result type. select number of items per result page.
casties
parents: 25
diff changeset
277 break;
193271b6b9d2 configure attributes per result type. select number of items per result page.
casties
parents: 25
diff changeset
278 }
193271b6b9d2 configure attributes per result type. select number of items per result page.
casties
parents: 25
diff changeset
279 this.state.resultColumns = this.state.resultType.getColumns(atts);
17
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
280 }
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
281 /*
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
282 * results for relations list
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
283 */
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
284 if (this.state.relationsCypherQuery) {
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
285 resIdx += 1;
18
65bb467abcc6 inverse relations are now generated on the fly.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 17
diff changeset
286 var rels = data.results[resIdx].data.map(elem => elem.row[0])
17
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
287 .filter(elem => elem[0] != "_");
18
65bb467abcc6 inverse relations are now generated on the fly.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 17
diff changeset
288 // add inverse relations
65bb467abcc6 inverse relations are now generated on the fly.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 17
diff changeset
289 var invrels = rels.concat(rels.map((r) => this.invRelPrefix + r));
21
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
290 this.state.resultRelations = invrels;
17
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
291 }
7
6cd6c09032aa object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 6
diff changeset
292 },
10
66dce99cef4e attribute contains works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 9
diff changeset
293 err => console.error("neo4j result error=", err),
66dce99cef4e attribute contains works now.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 9
diff changeset
294 () => console.debug('neo4j result query Complete')
7
6cd6c09032aa object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 6
diff changeset
295 );
6
9f5473536a98 more query generation.
casties
parents: 5
diff changeset
296 }
9f5473536a98 more query generation.
casties
parents: 5
diff changeset
297
21
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
298
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
299 filterAttributes(attributes: string[], normalized=false) {
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
300 var atts = [];
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
301 if (normalized) {
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
302 attributes.forEach((att) => {
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
303 if (att.substr(0, 3) == "_n_") {
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
304 atts.push(att.substr(3));
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
305 }
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
306 });
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
307 } else {
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
308 atts = attributes.filter(elem => elem[0] != "_" && !this.excludedAttributes[elem]);
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
309 }
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
310 return atts;
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
311 }
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
312
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
313 /**
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
314 * Run the given queries on the Neo4J server.
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
315 *
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
316 * Returns an Observable with the results.
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
317 */
17
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
318 fetchCypherResults(queries: string[], params=[{}]) {
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
319 console.debug("fetching cypher queries: ", queries);
1
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
320 var headers = new Headers();
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
321 var auth = this.neo4jAuthentication;
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 19
diff changeset
322 headers.append('Authorization', 'Basic ' + btoa(`${auth.user}:${auth.password}`));
1
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
323 headers.append('Content-Type', 'application/json');
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
324 headers.append('Accept', 'application/json');
3
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
325 // put headers in options
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
326 var opts = {'headers': headers};
17
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
327 // unpack queries into statements
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
328 var statements = queries.map((q, i) => {
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
329 return {'statement': q, 'parameters': (params[i])?params[i]:{}};
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
330 });
3
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
331 // create POST data from query
17
f6af2c8347de send multiple cypher queries in one request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 16
diff changeset
332 var data = JSON.stringify({'statements': statements});
3
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
333 // make post request asynchronously
9
402c7229dc7c more query generation.
casties
parents: 8
diff changeset
334 var resp = this._http.post(this.neo4jBaseUrl+'/transaction/commit', data, opts)
3
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
335 // filter result as JSON
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
336 .map(res => res.json());
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
337 // return Observable
c741a00d38de first list of object types :-)
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 2
diff changeset
338 return resp;
1
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
339 }
13
98b435bb6c0c more query work.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents: 12
diff changeset
340
1
59b7c3afcc6b first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff changeset
341 }