(ctx context.Context, gs *GraphStream, limit int)
| 246 | } |
| 247 | |
| 248 | func (s *GraphStreamHandler) serveNodesWithProps(ctx context.Context, gs *GraphStream, limit int) { |
| 249 | propsPath := path.NewPath(s.QS).Has(iriInlinePred, quad.Bool(true)) |
| 250 | |
| 251 | // list of predicates marked as inline properties for gephi |
| 252 | inline := make(map[quad.Value]struct{}) |
| 253 | err := propsPath.Iterate(ctx).EachValue(s.QS, func(v quad.Value) { |
| 254 | inline[v] = struct{}{} |
| 255 | }) |
| 256 | if err != nil { |
| 257 | clog.Errorf("cannot iterate over properties: %v", err) |
| 258 | return |
| 259 | } |
| 260 | // inline some well-known predicates |
| 261 | for _, iri := range defaultInline { |
| 262 | inline[iri] = struct{}{} |
| 263 | inline[iri.Full()] = struct{}{} |
| 264 | } |
| 265 | |
| 266 | ignore := make(map[quad.Value]struct{}) |
| 267 | |
| 268 | nodes := iterator.NewNot(propsPath.BuildIterator(), s.QS.NodesAllIterator()) |
| 269 | defer nodes.Close() |
| 270 | |
| 271 | ictx, cancel := context.WithCancel(ctx) |
| 272 | defer cancel() |
| 273 | |
| 274 | itc := graph.Iterate(ictx, nodes).On(s.QS).Limit(limit) |
| 275 | |
| 276 | qi := 0 |
| 277 | _ = itc.EachValuePair(s.QS, func(v graph.Ref, nv quad.Value) { |
| 278 | if _, skip := ignore[nv]; skip { |
| 279 | return |
| 280 | } |
| 281 | // list of inline properties |
| 282 | props := make(map[quad.Value]quad.Value) |
| 283 | |
| 284 | var ( |
| 285 | sid string |
| 286 | h, oh valHash |
| 287 | ) |
| 288 | quad.HashTo(nv, h[:]) |
| 289 | |
| 290 | predIt := s.QS.QuadIterator(quad.Subject, nodes.Result()) |
| 291 | defer predIt.Close() |
| 292 | for predIt.Next(ictx) { |
| 293 | // this check helps us ignore nodes with no links |
| 294 | if sid == "" { |
| 295 | sid = gs.addNode(nv, h, props) |
| 296 | } |
| 297 | q := s.QS.Quad(predIt.Result()) |
| 298 | if _, ok := inline[q.Predicate]; ok { |
| 299 | props[q.Predicate] = q.Object |
| 300 | ignore[q.Object] = struct{}{} |
| 301 | } else if shouldInline(q.Object) { |
| 302 | props[q.Predicate] = q.Object |
| 303 | } else { |
| 304 | quad.HashTo(q.Object, oh[:]) |
| 305 | o := gs.addNode(q.Object, oh, nil) |
no test coverage detected