changeset 40:896ae7eefb33

fix relation type queries.
author casties
date Mon, 15 Feb 2016 11:10:08 +0100
parents 7578b21cdf2e
children 5353b2dffb0f
files app/ismi-relation-types.ts app/query-app.component.ts app/query-select.component.ts app/query.service.ts app/relation-type.ts
diffstat 5 files changed, 30 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/app/ismi-relation-types.ts	Sun Feb 14 19:40:07 2016 +0100
+++ b/app/ismi-relation-types.ts	Mon Feb 15 11:10:08 2016 +0100
@@ -28,13 +28,22 @@
 addRelationType('was_studied_by', 'persons studying this text', 'text studied by');
 //addRelationType('', '', '');
 
-export function getRelationType(name: string, isOutgoing?: boolean): RelationType {
+export function getRelationType(relType: string, isOutgoing: boolean): RelationType {
+    let name = relType;
     if (isOutgoing === false) {
         // add prefix to name
         name = invNamePrefix + name;
     } 
     let rt = RELATION_TYPES[name];
     if (rt == null) {
+        rt = new RelationType(relType, isOutgoing);
+    }
+    return rt;
+}
+
+export function getRelationByName(name: string): RelationType {
+    let rt = RELATION_TYPES[name];
+    if (rt == null) {
         if (name.indexOf(invNamePrefix) == 0) {
             // inverse relation
             name = name.substr(invNamePrefix.length);
--- a/app/query-app.component.ts	Sun Feb 14 19:40:07 2016 +0100
+++ b/app/query-app.component.ts	Mon Feb 15 11:10:08 2016 +0100
@@ -59,7 +59,7 @@
     
     onQueryChanged(event: any) {
         console.debug("app.onquerychanged! event=", event);
-        this._queryService.updateQuery();
+        this._queryService.runQuery();
         this.queryState = this._queryService.getState();
     }
 }
--- a/app/query-select.component.ts	Sun Feb 14 19:40:07 2016 +0100
+++ b/app/query-select.component.ts	Mon Feb 15 11:10:08 2016 +0100
@@ -6,7 +6,7 @@
 
 import {QueryService} from './query.service';
 import {NormalizationService} from './normalization.service';
-import {getRelationType} from './ismi-relation-types';
+import {getRelationByName} from './ismi-relation-types';
 
 
 @Component({
@@ -139,7 +139,7 @@
              */
             let opt = this.selectedOption;
             if (opt) {
-                let rel = getRelationType(opt);
+                let rel = getRelationByName(opt);
                 step = new QueryStep(this.selectedMode, {'relationType': rel});
             }
         } else if (this.selectedMode.id == 'id_is') {
--- a/app/query.service.ts	Sun Feb 14 19:40:07 2016 +0100
+++ b/app/query.service.ts	Mon Feb 15 11:10:08 2016 +0100
@@ -151,10 +151,10 @@
                 nIdx += 1;
                 let rel = params.relationType;
                 if (rel.isOutgoing()) {
-                    queryMatch += `-[:\`${rel.getName()}\`]->(n${nIdx})`;
+                    queryMatch += `-[:\`${rel.getRelType()}\`]->(n${nIdx})`;
                 } else {
                     // inverse relation
-                    queryMatch += `<-[:\`${rel.getName()}\`]-(n${nIdx})`;
+                    queryMatch += `<-[:\`${rel.getRelType()}\`]-(n${nIdx})`;
                 }
                 queryReturn =  `RETURN DISTINCT n${nIdx}`;
                 returnType = 'node';
@@ -222,7 +222,7 @@
      * 
      * Updates the results and nextQuery attributes and relations.
      */
-    updateQuery() {
+    runQuery() {
         this.createCypherQuery();
         this.state.resultInfo = 'loading...';
         /*
--- a/app/relation-type.ts	Sun Feb 14 19:40:07 2016 +0100
+++ b/app/relation-type.ts	Mon Feb 15 11:10:08 2016 +0100
@@ -6,20 +6,26 @@
 
 export class RelationType {
     public name: string;
+    public relType: string;
     public label: string;
     public outgoing: boolean;
     
-    constructor (name: string, isOutgoing: boolean, label?:string) {
-        this.name = name;
+    constructor (relType: string, isOutgoing: boolean, label?:string) {
         this.outgoing = isOutgoing;
+        this.relType = relType;
+        if (isOutgoing) {
+            this.name = relType;
+        } else {
+            this.name = invNamePrefix + relType;
+        }
         if (label != null) {
             this.label = label;
         } else {
             // create label using name
             if (isOutgoing) {
-                this.label = rawLabelPrefix + name + rawLabelPostfix;
+                this.label = rawLabelPrefix + relType + rawLabelPostfix;
             } else {
-                this.label = rawLabelPrefix + invLabelPrefix + name + rawLabelPostfix;
+                this.label = rawLabelPrefix + invLabelPrefix + relType + rawLabelPostfix;
             }
         }
     }
@@ -32,6 +38,10 @@
         return this.name;
     }
     
+    getRelType() {
+        return this.relType;
+    }
+    
     isOutgoing() {
         return this.outgoing;
     }