@@ -7,30 +7,29 @@ let nodes = [];
77let edges = [ ] ;
88let maxLevel = 1 ;
99let maxNodes = 1000 ;
10- let limitPerNode = 100 ;
1110let traversed = { } ;
1211let alreadyAddedtoNode = { } ;
1312let entityOptions = {
1413 'getRelationships' : true ,
15- 'getContent' : false
14+ 'getContent' : true
1615}
1716
1817let breakException = { } ;
1918let currentUser = user . getCurrentUser ( ) ;
2019
2120function isEntityInCurrentWorkspace ( entityUri ) {
2221 if (
23- currentUser != null &&
24- currentUser . hasOwnProperty ( "currentWorkspace" ) &&
25- currentUser . currentWorkspace . hasOwnProperty ( "content" ) &&
26- currentUser . currentWorkspace . content != null &&
27- currentUser . currentWorkspace . content . hasOwnProperty ( "entities" ) &&
22+ currentUser != null &&
23+ currentUser . hasOwnProperty ( "currentWorkspace" ) &&
24+ currentUser . currentWorkspace . hasOwnProperty ( "content" ) &&
25+ currentUser . currentWorkspace . content != null &&
26+ currentUser . currentWorkspace . content . hasOwnProperty ( "entities" ) &&
2827 currentUser . currentWorkspace . content . entities . hasOwnProperty ( entityUri )
2928 ) {
3029 return true ;
3130 }
3231 else {
33- return false ;
32+ return false ;
3433 }
3534} ;
3635
@@ -39,9 +38,10 @@ function buildNodesAndEdges(level, entityUri, visibleIds, options = {}) {
3938 const entityObject = entity . getData ( entityUri , entityOptions ) ;
4039 let nextLevel = level + 1 ;
4140 let id = entityUri ;
42- let label = entityObject . preferredName ;
43- let group = entityObject . type ;
44- if ( ! alreadyAddedtoNode . hasOwnProperty ( id ) ) {
41+ const e = entityObject . entity || { } ;
42+ let label = e . preferredName ;
43+ let group = e . type ;
44+ if ( ! alreadyAddedtoNode . hasOwnProperty ( id ) ) {
4545 let node = {
4646 id : id ,
4747 label : label ,
@@ -67,86 +67,16 @@ function buildNodesAndEdges(level, entityUri, visibleIds, options = {}) {
6767 // Only include edges for links to nodes already visible on the graph.
6868 const relationshipId = relationship . uri ;
6969 if ( doesListContain ( visibleIds , relationshipId . toString ( ) ) ) {
70- // let relationshipLabel = relationship.preferredName;
71- // let relationshipGroup = relationship.entityType;
7270 let edge = {
7371 from : id ,
7472 to : relationshipId
7573 } ;
76-
77- edges . push ( edge ) ;
78- }
79-
80- if ( ( nextLevel <= maxLevel || relationship . autoExpand ) && ! traversed . hasOwnProperty ( relationshipId ) && nodes . length < maxNodes ) {
81- buildNodesAndEdges ( nextLevel , relationship . uri , visibleIds , { autoExpand : relationship . autoExpand } ) ;
82- }
83- } ) ;
84- }
85- } ;
8674
87- function buildNodesAndEdgesv1 ( level , entityUri , options = { } ) {
88- if ( ( level <= maxLevel || options . autoExpand ) && ! traversed . hasOwnProperty ( entityUri ) ) {
89- const entityObject = entity . getData ( entityUri , entityOptions ) ;
90- let nextLevel = level + 1 ;
91- let id = entityUri ;
92- let label = entityObject . preferredName ;
93- let group = entityObject . type ;
94- if ( ! alreadyAddedtoNode . hasOwnProperty ( id ) ) {
95- let node = {
96- id : id ,
97- label : label ,
98- group : group + 'Recommendation' ,
99- level : ( level - 1 ) ,
100- isInCurrentWorkspace : isEntityInCurrentWorkspace ( entityUri ) ,
101- isRecommendation : true
102- } ;
103-
104- if ( nodes . length < maxNodes || ( level - 1 ) == 0 ) {
105- nodes . push ( node ) ;
106- }
107- else {
108- throw breakException ;
109- }
110-
111- alreadyAddedtoNode [ id ] = true ;
112- }
113-
114- traversed [ id ] = true ;
115-
116- entityObject . relationships . slice ( 0 , limitPerNode ) . forEach ( function ( relationship ) {
117- let relationshipId = relationship . uri ;
118- let relationshipLabel = relationship . preferredName ;
119- let relationshipGroup = relationship . entityType ;
120-
121- if ( ! alreadyAddedtoNode . hasOwnProperty ( relationshipId ) && nodes . length < maxNodes ) {
122- let node = {
123- id : relationshipId ,
124- label : relationshipLabel ,
125- group : relationshipGroup + 'Recommendation' ,
126- level : level ,
127- isInCurrentWorkspace : isEntityInCurrentWorkspace ( entityUri ) ,
128- isRecommendation : true
129- } ;
130-
131- if ( nodes . length < maxNodes ) {
132- nodes . push ( node ) ;
133- }
134- else {
135- throw breakException ;
136- }
137-
138- alreadyAddedtoNode [ relationshipId ] = true ;
139-
140- let edge = {
141- from : id ,
142- to : relationshipId
143- } ;
144-
14575 edges . push ( edge ) ;
14676 }
14777
14878 if ( ( nextLevel <= maxLevel || relationship . autoExpand ) && ! traversed . hasOwnProperty ( relationshipId ) && nodes . length < maxNodes ) {
149- buildNodesAndEdgesv1 ( nextLevel , relationship . uri , { autoExpand : relationship . autoExpand } ) ;
79+ buildNodesAndEdges ( nextLevel , relationship . uri , visibleIds , { autoExpand : relationship . autoExpand } ) ;
15080 }
15181 } ) ;
15282 }
@@ -169,8 +99,6 @@ function get(context, params) {
16999 // Search on Pubs with text: obesity exercise
170100 if ( params . hasOwnProperty ( "id" ) ) {
171101 let visibleIds = [ ] ;
172- let workspaceId = null ;
173- let algorithmName = null ;
174102
175103 // uri can come in encoded many times
176104 const sourceIds = params . id . toString ( ) . split ( "," ) . map ( key => decodeURIComponent ( decodeURIComponent ( decodeURIComponent ( decodeURIComponent ( key ) ) ) ) ) ;
@@ -197,16 +125,16 @@ function get(context, params) {
197125 if ( params . hasOwnProperty ( "algorithmName" ) ) {
198126 algorithmName = params . algorithmName ;
199127 }
200-
128+
201129 uris . forEach ( function ( uri ) {
202130 try {
203- buildNodesAndEdges ( 1 , uri ) ;
131+ buildNodesAndEdges ( 1 , uri , [ ] ) ;
204132 }
205133 catch ( e ) {
206134 if ( e !== breakException ) throw e ;
207135 }
208136 } ) ;
209-
137+
210138 // Remove the visible and source ids that overlap with the recommended nodes.
211139 const finalNodes = nodes . filter ( node => {
212140 const idStr = fn . string ( node . id ) ;
@@ -230,8 +158,6 @@ function post(context, params, input) {
230158 // Search on Pubs with text: obesity exercise
231159 if ( input . root && input . root . ids ) {
232160 let visibleIds = [ ] ;
233- let workspaceId = null ;
234- let algorithmName = null ;
235161
236162 const sourceIds = Sequence . from ( input . root . ids ) . toArray ( ) ;
237163 var recommended = recom . bestNewConnection ( sourceIds ) ;
@@ -259,7 +185,7 @@ function post(context, params, input) {
259185 }
260186
261187 const allIds = sourceIds . concat ( uris ) ;
262-
188+
263189 uris . forEach ( function ( uri ) {
264190 try {
265191 buildNodesAndEdges ( 1 , uri , allIds ) ;
0 commit comments