changeset 29:1a1877812757

include normalized attributes in neo4j with prefix "_n_"
author casties
date Thu, 10 Dec 2015 12:11:25 -0500
parents a9bfd49355f8
children 870b0b3b272f
files importFromOpenMind/importer/ismi2model.py importFromOpenMind/importer/model2model.py importFromOpenMind/importer/model2neo4j.py
diffstat 3 files changed, 19 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/importFromOpenMind/importer/ismi2model.py	Wed Nov 18 15:22:05 2015 +0100
+++ b/importFromOpenMind/importer/ismi2model.py	Thu Dec 10 12:11:25 2015 -0500
@@ -96,6 +96,9 @@
 
             # keep attribute
             attrs[key] = val
+            if 'nov' in att:
+                # add normalized value
+                attrs['_n_'+key] = att['nov']
             
         elif ct == 'num':
             # number attribute
@@ -143,7 +146,7 @@
     oc = ent['oc']
     if oc != etype:
         print("ERROR: entity type doesn't match!")
-        return null
+        return None
             
     # rename if type attr exists
     if 'type' in attrs:
@@ -160,8 +163,10 @@
     if ov is not None:
         # save ov as label
         attrs['label'] = ov
+        if 'nov' in ent:
+            # add normalized value
+            attrs['_n_label'] = ent.get('nov')
                         
-    # create node with attributes
     nx_graph.add_node(ismi_id, **attrs)
     node = nx_graph.node[ismi_id]
     
--- a/importFromOpenMind/importer/model2model.py	Wed Nov 18 15:22:05 2015 +0100
+++ b/importFromOpenMind/importer/model2model.py	Thu Dec 10 12:11:25 2015 -0500
@@ -27,7 +27,7 @@
 
 # add URLs to nodes using an attribute in a pattern
 #add_link_attributes = {'ismi_id': 'https://ismi-dev.mpiwg-berlin.mpg.de/drupal-ismi/entity/%s'}
-add_link_attributes = {'ismi_id': 'https://ismi-dev.mpiwg-berlin.mpg.de/om4-ismi/public/publicWitness.jsp?eid=%s'}
+add_link_attributes = {'ismi_id': 'https://ismi-dev.mpiwg-berlin.mpg.de/om4-ismi/public/entityDetails.xhtml?eid=%s'}
 
 
 def fixName(name, is_src_rel=False, is_tar_rel=False, att_from_rel=False):
@@ -140,6 +140,9 @@
                 att_name = genAttName(src_attrs, att_name)
                 # add target node's attribute
                 src_attrs[att_name] = tar_attrs.get(transfer_att)
+                # also add normalized attribute
+                if '_n_'+transfer_att in tar_attrs:
+                    src_attrs['_n_'+att_name] = tar_attrs.get('_n_'+transfer_att)
             
         # contract target relations
         src_type = src_attrs['type']
@@ -161,6 +164,9 @@
                 att_name = genAttName(tar_attrs, att_name)
                 # add target node's attribute
                 tar_attrs[att_name] = src_attrs.get(transfer_att)
+                # also add normalized attribute
+                if '_n_'+transfer_att in src_attrs:
+                    tar_attrs['_n_'+att_name] = src_attrs.get('_n_'+transfer_att)
 
         cnt += 1
         if cnt % 100 == 0:
--- a/importFromOpenMind/importer/model2neo4j.py	Wed Nov 18 15:22:05 2015 +0100
+++ b/importFromOpenMind/importer/model2neo4j.py	Thu Dec 10 12:11:25 2015 -0500
@@ -1,5 +1,5 @@
 import networkx as nx
-from neo4jrestclient.client import GraphDatabase, Node
+from neo4jrestclient.client import GraphDatabase
 import sys
 
 ## configure behaviour
@@ -52,12 +52,12 @@
     cnt = 0
     for node_id in nx.nodes_iter(nx_graph):
         attrs = nx_graph.node[node_id]
-        type = attrs['type']
+        ntype = attrs['type']
         ismi_id = attrs['ismi_id']
         # create node with attributes
         n4j_node = n4j_graph.nodes.create(**attrs)
         # add labels
-        n4j_node.labels.add([project_label, type])
+        n4j_node.labels.add([project_label, ntype])
         # save reference
         n4j_nodes[ismi_id] = n4j_node
 
@@ -75,7 +75,7 @@
         (nx_src, nx_tar) = nx_edge
         # get attributes of edge
         attrs = nx_graph.edge[nx_src][nx_tar][0]
-        type = attrs['type']
+        ntype = attrs['type']
         # get ismi_id of source and target nodes
         src_id = nx_graph.node[nx_src]['ismi_id']
         tar_id = nx_graph.node[nx_tar]['ismi_id']
@@ -91,7 +91,7 @@
             break
         
         # create Neo4J relation
-        n4j_rel = n4j_graph.relationships.create(src, type, tar)
+        n4j_rel = n4j_graph.relationships.create(src, ntype, tar)
         # add attributes
         n4j_rel.properties = attrs