changeset 15:f84ff6781e57

added att_num_range query type.
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Thu, 21 Jan 2016 17:26:22 +0100
parents 7dc7ea95ca26
children 7d82ca32833c
files app/query-mode.ts app/query-select.component.ts app/query.service.ts
diffstat 3 files changed, 47 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/app/query-mode.ts	Thu Jan 21 16:49:55 2016 +0100
+++ b/app/query-mode.ts	Thu Jan 21 17:26:22 2016 +0100
@@ -5,8 +5,9 @@
 
 export var QUERY_MODES: QueryMode[] = [
     {id: 'type_is', label:'Object type is'},
-    {id: 'att_contains', label: 'Attribute'},
-    {id: 'att_contains_norm', label: 'Attribute (normalized)'},
+    {id: 'att_contains', label: 'Attribute (contains)'},
+    {id: 'att_contains_norm', label: 'Attribute (contains normalized)'},
+    {id: 'att_num_range', label: 'Attribute (number range)'},    
     {id: 'relation_is', label: 'Relation type is'}
 ];
         
--- a/app/query-select.component.ts	Thu Jan 21 16:49:55 2016 +0100
+++ b/app/query-select.component.ts	Thu Jan 21 17:26:22 2016 +0100
@@ -19,7 +19,7 @@
             </option>
         </select>
 
-        <span *ngIf="selectedMode.id=='type_is' || selectedMode.id=='relation_is'">
+        <span *ngIf="selectedMode && selectedMode.id=='type_is' || selectedMode.id=='relation_is'">
             <select *ngIf="queryOptions" [(ngModel)]="selectedOption" (change)="onSelectOption($event)">
                 <option></option>
                 <option *ngFor="#option of queryOptions" [value]="option">
@@ -28,7 +28,7 @@
             </select>
         </span>
 
-        <span *ngIf="selectedMode.id=='att_contains' || selectedMode.id=='att_contains_norm'">
+        <span *ngIf="selectedMode && selectedMode.id=='att_contains' || selectedMode.id=='att_contains_norm'">
             <select [(ngModel)]="selectedOption">
                 <option></option>
                 <option *ngFor="#option of queryOptions" [value]="option">
@@ -38,6 +38,20 @@
             <span>contains</span>
             <input type="text" [(ngModel)]="queryInput"/>
         </span>
+
+        <span *ngIf="selectedMode && selectedMode.id=='att_num_range'">
+            <select [(ngModel)]="selectedOption">
+                <option></option>
+                <option *ngFor="#option of queryOptions" [value]="option">
+                    {{option}}
+                </option>
+            </select>
+            <span>is between</span>
+            <input type="text" [(ngModel)]="queryInput"/>
+            <span>and</span>
+            <input type="text" [(ngModel)]="queryInput2"/>
+        </span>
+
         <button type="submit">Submit</button>
     </form>
 </div>
@@ -55,6 +69,7 @@
     public queryOptions: string[];
     public selectedOption: string;
     public queryInput: string;
+    public queryInput2: string;
     
     @Output('queryChanged') queryChanged = new EventEmitter<QueryState>();
     
@@ -108,6 +123,13 @@
             if (att && val) {
                 step = {'mode': this.selectedMode, 'attribute': att, 'value': val};
            }
+        } else if (this.selectedMode.id == 'att_num_range') {
+            var att = this.selectedOption;
+            var nlo = this.queryInput;
+            var nhi = this.queryInput2;
+            if (att && nlo && nhi) {
+                step = {'mode': this.selectedMode, 'attribute': att, 'numLo': nlo, 'numHi': nhi};
+           }
         } else if (this.selectedMode.id == 'att_contains_norm') {
             var att = this.selectedOption;
             var val = this.queryInput;
--- a/app/query.service.ts	Thu Jan 21 16:49:55 2016 +0100
+++ b/app/query.service.ts	Thu Jan 21 17:26:22 2016 +0100
@@ -44,7 +44,7 @@
     }
     
     getQueryOptions(queryMode: QueryMode) {
-        var options = ['a1', 'b1', 'c1'];
+        var options = [];
         if (queryMode.id === 'type_is') {
             options = this.ismiObjectTypes;
         } else if (queryMode.id === 'relation_is') {
@@ -53,6 +53,8 @@
             options = this.state.nextQueryAttributes;
         } else if (queryMode.id === 'att_contains_norm') {
             options = this.state.nextQueryAttributes;
+        } else if (queryMode.id === 'att_num_range') {
+            options = this.state.nextQueryAttributes;
         }
         console.debug("getQueryOptions returns: ", options);
         return options;
@@ -136,9 +138,25 @@
                 }
             }
             
+            /*
+             * step: attribute number range
+             */
+            if (step.mode.id === 'att_num_range') {
+                if (!queryWhere) {
+                    queryWhere = 'WHERE ';
+                } else {
+                    queryWhere += ' AND ';
+                }
+                queryWhere += `toint(n${nIdx}.${step.attribute}) >= toint({att_nlo${stepIdx}})`
+                    + ` AND toint(n${nIdx}.${step.attribute}) <= toint({att_nhi${stepIdx}})`;
+                queryParams[`att_nlo${stepIdx}`] = step.numLo;
+                queryParams[`att_nhi${stepIdx}`] = step.numHi;
+            }
+            
         });
         resultQuery = queryMatch + '\n' + queryWhere + '\n' + queryReturn;
-        attributesQuery = queryMatch + ' ' + queryWhere + ` WITH DISTINCT keys(n${nIdx}) AS atts UNWIND atts AS att RETURN DISTINCT att ORDER BY att`;
+        attributesQuery = queryMatch + ' ' + queryWhere + ` WITH DISTINCT keys(n${nIdx}) AS atts`
+            + ` UNWIND atts AS att RETURN DISTINCT att ORDER BY att`;
         relationsQuery = queryMatch + '-[r]-() ' + queryWhere + ' RETURN DISTINCT type(r)';
         this.state.resultCypherQuery = resultQuery;
         this.state.cypherQueryParams = queryParams;