changeset 14:7dc7ea95ca26

show result types below query steps.
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Thu, 21 Jan 2016 16:49:55 +0100
parents 98b435bb6c0c
children f84ff6781e57
files app/query-select.component.ts app/query.service.ts
diffstat 2 files changed, 36 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/app/query-select.component.ts	Thu Jan 21 14:47:00 2016 +0100
+++ b/app/query-select.component.ts	Thu Jan 21 16:49:55 2016 +0100
@@ -9,6 +9,7 @@
 @Component({
     selector: 'query-select',
     template: `
+<p *ngIf="resultInfo">&nbsp;&nbsp;&nbsp;result: {{resultInfo}}</p>
 <div>
     <form (ngSubmit)="onSubmit()">
         <select (change)="onSelectMode($event)">
@@ -41,13 +42,14 @@
     </form>
 </div>
         `,
-    inputs: ['index']
+    inputs: ['queryStep', 'index']
     //outputs: ['queryChanged'] // this should work but doesn't
 })
    
 export class QuerySelectComponent implements OnInit { 
     public queryStep: QueryStep;
     public index: number;
+    public resultInfo: string;
     public queryModes: QueryMode[];
     public selectedMode: QueryMode;
     public queryOptions: string[];
@@ -65,6 +67,10 @@
     setup() {
         console.log("query-select setup step=", this.queryStep);
         this.queryModes = this._queryService.getQueryModes();
+        var step = this._queryService.state.steps[this.index-1];
+        if (step != null) {
+            this.resultInfo = step.resultInfo;
+        }
         // select first mode (too early?)
         this.selectedMode = this.queryModes[0];
         this.query2Options = this._queryService.getQueryOptions(this.selectedMode);
@@ -106,17 +112,20 @@
             var att = this.selectedOption;
             var val = this.queryInput;
             if (att && val) {
+                // run search term through normalizer 
                 this._queryService.fetchNormalizedString(val)
                 .subscribe(
                     data => {
                         console.debug("openmind norm data=", data);
                         step = {'mode': this.selectedMode, 'attribute': att, 'value': val, 'normValue': data.normalized_text};
                         this._queryService.setQueryStep(this.index, step);
+                        // query has changed now
                         this.queryChanged.emit(this._queryService.getState());
                     },
                     err => console.error("openmind norm error=", err),
                     () => console.debug("openmind norm query Complete")
                 );
+                // query has not been set yet
                 return;
            }
         }
--- a/app/query.service.ts	Thu Jan 21 14:47:00 2016 +0100
+++ b/app/query.service.ts	Thu Jan 21 16:49:55 2016 +0100
@@ -91,7 +91,9 @@
         var returnType = '';
         var nIdx = 1;
         this.state.steps.forEach((step, stepIdx) => {
-            // object type is
+            /*
+             * step: object type is
+             */
             if (step.mode.id === 'type_is') {
                 queryMatch = `MATCH (n${nIdx}:${step.objectType})`;
                 queryWhere = '';
@@ -99,7 +101,9 @@
                 returnType = 'node';
             }
             
-            // relation type is
+            /*
+             * step: relation type is
+             */
             if (step.mode.id === 'relation_is') {
                 nIdx += 1;
                 queryMatch += `-[:\`${step.relationType}\`]->(n${nIdx})`;
@@ -107,25 +111,29 @@
                 returnType = 'node';
             }
             
-            // attribute contains
-            if (step.mode.id === 'att_contains') {
+            /*
+             * step: attribute contains(_norm)
+             */
+            if (step.mode.id === 'att_contains' || step.mode.id === 'att_contains_norm') {
                 if (!queryWhere) {
                     queryWhere = 'WHERE ';
                 } else {
                     queryWhere += ' AND ';
                 }
-                queryWhere += `lower(n${nIdx}.${step.attribute}) CONTAINS lower({att_val${stepIdx}})`;
-                queryParams[`att_val${stepIdx}`] = step.value;
-            }
-            
-            // attribute contains (normalized)
-            if (step.mode.id === 'att_contains_norm') {
-                if (!queryWhere) {
-                    queryWhere = 'WHERE ';
+                if (step.attribute === 'ismi_id') {
+                    // ismi_id is integer
+                    queryWhere += `n${nIdx}.ismi_id = {att_val${stepIdx}}`;                    
+                    queryParams[`att_val${stepIdx}`] = parseInt(step.value, 10);
                 } else {
-                    queryWhere += ' AND ';
+                    if (step.mode.id === 'att_contains_norm') {
+                        // match _n_attribute with normValue
+                        queryWhere += `lower(n${nIdx}._n_${step.attribute}) CONTAINS lower({att_val${stepIdx}})`;
+                        queryParams[`att_val${stepIdx}`] = step.normValue;                        
+                    } else {
+                        queryWhere += `lower(n${nIdx}.${step.attribute}) CONTAINS lower({att_val${stepIdx}})`;
+                        queryParams[`att_val${stepIdx}`] = step.value;
+                    }
                 }
-                queryWhere += `lower(n${nIdx}._n_${step.attribute}) CONTAINS lower('${step.value}')`;
             }
             
         });
@@ -164,7 +172,10 @@
                 for (var t in resTypes) {
                     info += t + '(' + resTypes[t] + ') ';   
                 }
-                this.state.resultInfo = info.substr(0, info.length-1);
+                info = info.substr(0, info.length-1);
+                this.state.resultInfo = info;
+                // save info also in last step
+                this.state.steps[this.state.steps.length-1].resultInfo = info;
             },
             err => console.error("neo4j result error=", err),
             () => console.debug('neo4j result query Complete')