Changeset - ffa3b81c6d95
[Not reviewed]
default
0 1 0
Drew Perttula - 8 years ago 2017-06-10 10:23:48
drewp@bigasterisk.com
some missing askedFor auditing
Ignore-this: 581b102bbdaef0dc715e61430d639e01
1 file changed with 3 insertions and 0 deletions:
0 comments (0 inline, 0 general)
light9/web/graph.coffee
Show inline comments
 
@@ -269,60 +269,63 @@ class window.SyncedGraph
 
  labelOrTail: (uri) ->
 
    try
 
      @graph.stringValue(uri, @graph.Uri('rdfs:label'))
 
    catch
 
      words = uri.split('/')
 
      words[words.length-1]
 

	
 
  objects: (s, p) ->
 
    @_autoDeps.askedFor(s, p, null, null)
 
    quads = @graph.findByIRI(s, p)
 
    return (q.object for q in quads)
 

	
 
  subjects: (p, o) ->
 
    @_autoDeps.askedFor(null, p, o, null)
 
    quads = @graph.findByIRI(null, p, o)
 
    return (q.subject for q in quads)
 

	
 
  items: (list) ->
 
    out = []
 
    current = list
 
    while true
 
      if current == RDF + 'nil'
 
        break
 
        
 
      @_autoDeps.askedFor(current, null, null, null) # a little loose
 

	
 
      firsts = @graph.findByIRI(current, RDF + 'first', null)
 
      rests = @graph.findByIRI(current, RDF + 'rest', null)
 
      if firsts.length != 1
 
        throw new Error("list node #{current} has #{firsts.length} rdf:first edges")
 
      out.push(firsts[0].object)
 

	
 
      if rests.length != 1
 
        throw new Error("list node #{current} has #{rests.length} rdf:rest edges")
 
      current = rests[0].object
 
    
 
    return out
 

	
 
  contains: (s, p, o) ->
 
    @_autoDeps.askedFor(s, p, o, null)
 
    return @graph.findByIRI(s, p, o).length > 0
 

	
 
  nextNumberedResources: (base, howMany) ->
 
    results = []
 
    # we could cache [base,lastSerial]
 
    for serial in [0..1000]
 
      uri = @Uri("#{base}#{serial}")
 
      if not @contains(uri, null, null)
 
        results.push(uri)
 
        if results.length >= howMany
 
          return results
 
    throw new Error("can't make sequential uri with base #{base}")
 

	
 
  nextNumberedResource: (base) ->
 
    @nextNumberedResources(base, 1)[0]       
 

	
 
  contextsWithPattern: (s, p, o) ->
 
    @_autoDeps.askedFor(s, p, o, null)
 
    ctxs = []
 
    for q in @graph.find(s, p, o)
 
      ctxs.push(q.graph)
 
    return _.unique(ctxs)
 

	
0 comments (0 inline, 0 general)