Module: OpenAnnotationHarvest

Included in:
Annotations2triannon::AnnotationList, Annotations2triannon::Manifest
Defined in:
lib/annotations2triannon/open_annotation_harvest.rb

Overview

Module designed to be a mixin for manifest and annotation list.

Instance Method Summary collapse

Instance Method Details

#collect_open_annotations(rdf) ⇒ Array<RDF::Graph>

Returns for graphs of type RDF::Vocab::OA.Annotation.

Parameters:

  • rdf (RDF::Graph)

    a graph to search for RDF::Vocab::OA.Annotation

Returns:

  • (Array<RDF::Graph>)

    for graphs of type RDF::Vocab::OA.Annotation



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/annotations2triannon/open_annotation_harvest.rb', line 9

def collect_open_annotations(rdf)
  oa_graphs = []
  q = [nil, RDF.type, RDF::Vocab::OA.Annotation]
  rdf.query(q).each_subject do |subject|
    g = RDF::Graph.new
    rdf.query([subject, nil, nil]) do |s,p,o|
      g << [s,p,o]
      g << rdf_expand_blank_nodes(o) if o.node?
    end
    oa_graphs << g
  end
  oa_graphs
end

#rdf_expand_blank_nodes(object) ⇒ RDF::Graph

Returns graph of recursive resolution for a blank node.

Parameters:

  • object (RDF::Node)

    An RDF blank node

Returns:

  • (RDF::Graph)

    graph of recursive resolution for a blank node



25
26
27
28
29
30
31
32
33
34
# File 'lib/annotations2triannon/open_annotation_harvest.rb', line 25

def rdf_expand_blank_nodes(object)
  g = RDF::Graph.new
  if object.node?
    rdf.query([object, nil, nil]) do |s,p,o|
      g << [s,p,o]
      g << rdf_expand_blank_nodes(o) if o.node?
    end
  end
  g
end