Module: RdfContext

Defined in:
lib/rdf_context/duration.rb,
lib/rdf_context.rb,
lib/rdf_context/bnode.rb,
lib/rdf_context/graph.rb,
lib/rdf_context/parser.rb,
lib/rdf_context/triple.rb,
lib/rdf_context/uriref.rb,
lib/rdf_context/literal.rb,
lib/rdf_context/n3parser.rb,
lib/rdf_context/resource.rb,
lib/rdf_context/namespace.rb,
lib/rdf_context/exceptions.rb,
lib/rdf_context/rdfaparser.rb,
lib/rdf_context/term_utils.rb,
lib/rdf_context/quoted_graph.rb,
lib/rdf_context/rdfxmlparser.rb,
lib/rdf_context/aggregate_graph.rb,
lib/rdf_context/store/list_store.rb,
lib/rdf_context/conjunctive_graph.rb,
lib/rdf_context/store/memory_store.rb,
lib/rdf_context/store/sqlite3_store.rb,
lib/rdf_context/store/abstract_store.rb,
lib/rdf_context/serializer/nt_serializer.rb,
lib/rdf_context/store/abstract_sql_store.rb,
lib/rdf_context/serializer/xml_serializer.rb,
lib/rdf_context/store/active_record_store.rb,
lib/rdf_context/serializer/turtle_serializer.rb,
lib/rdf_context/serializer/abstract_serializer.rb,
lib/rdf_context/serializer/recursive_serializer.rb

Overview

An XSD duration

Defined Under Namespace

Modules: TermUtils Classes: AbstractSQLStore, AbstractSerializer, AbstractStore, ActiveRecordStore, AggregateGraph, BNode, BNodeException, ConjunctiveGraph, Duration, Graph, GraphException, InvalidNode, InvalidPredicate, ListStore, Literal, MemoryStore, N3Parser, NTSerializer, Namespace, Parser, ParserException, QuotedGraph, RdfException, RdfXmlParser, RdfaParser, ReadOnlyGraphException, RecursiveSerializer, Resource, SQLite3Store, SparqlException, StoreException, Triple, TurtleSerializer, TypeError, URIRef, XmlSerializer

Constant Summary collapse

VERSION =

Version in parent directory

File.read(File.join(File.dirname(__FILE__), "..", "VERSION")).chop
%w(
  alternate appendix bookmark cite chapter contents copyright first glossary
  help icon index last license meta next p3pv1 prev role section stylesheet subsection
  start top up
)
NC_REGEXP =
Regexp.new(
%{^
  (?!\\\\u0301)             # ́ is a non-spacing acute accent.
                            # It is legal within an XML Name, but not as the first character.
  (  [a-zA-Z_]
   | \\\\u[0-9a-fA-F]
  )
  (  [0-9a-zA-Z_\.-]
   | \\\\u([0-9a-fA-F]{4})
  )*
$},
Regexp::EXTENDED)
LITERAL_PLAIN =
/^"((?:\\"|[^"])*)"/.freeze
LITERAL_WITH_LANGUAGE =
/^"((?:\\"|[^"])*)"@([a-z]+[\-A-Za-z0-9]*)/.freeze
LITERAL_WITH_DATATYPE =
/^"((?:\\"|[^"])*)"\^\^<([^>]+)>/.freeze
RDF_TYPE =
URIRef.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
XML_LITERAL =
Literal::Encoding.xmlliteral
DC_NS =
Namespace.new("http://purl.org/dc/terms/", "dc")
OWL_NS =
Namespace.new("http://www.w3.org/2002/07/owl#", "owl")
LOG_NS =
Namespace.new("http://www.w3.org/2000/10/swap/log#", "log")
PTR_NS =
Namespace.new("http://www.w3.org/2009/pointers#", "ptr")
RDF_NS =
Namespace.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf")
RDFA_NS =
Namespace.new("http://www.w3.org/ns/rdfa#", "rdfa")
RDFS_NS =
Namespace.new("http://www.w3.org/2000/01/rdf-schema#", "rdfs")
XHV_NS =
Namespace.new("http://www.w3.org/1999/xhtml/vocab#", "xhv")
XML_NS =
Namespace.new("http://www.w3.org/XML/1998/namespace", "xml")
XSD_NS =
Namespace.new("http://www.w3.org/2001/XMLSchema#", "xsd")
XSI_NS =
Namespace.new("http://www.w3.org/2001/XMLSchema-instance", "xsi")
WELLKNOWN_NAMESPACES =
[DC_NS, OWL_NS, LOG_NS, RDF_NS, RDFA_NS, RDFS_NS, XHV_NS, XML_NS, XSD_NS, XSI_NS]
XH_MAPPING =
{"" => Namespace.new("http://www.w3.org/1999/xhtml/vocab\#", nil)}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.debug=(value) ⇒ Object



118
# File 'lib/rdf_context.rb', line 118

def self.debug=(value); @debug = value; end

.debug?Boolean

Control debug output.

Returns:

  • (Boolean)


117
# File 'lib/rdf_context.rb', line 117

def self.debug?; @debug; end

Instance Method Details

#bnode_permutations(bn_source, bn_other) ⇒ Object (protected)

Permutations of two BNode lists

Take source keys and run permutations mapping to other keys, if the permutation maps to the same counts for each



573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
# File 'lib/rdf_context/graph.rb', line 573

def bnode_permutations(bn_source, bn_other)
  puts "compare #{bn_source.inspect}\n   with #{bn_other.inspect}" if ::RdfContext::debug?

  source_keys = bn_source.keys
  other_keys = bn_other.keys
  values = bn_source.values.uniq

  # Break key lists into groups based on sharing equivalent usage counts
  case values.length
  when 0
    {}
  when 1
    # All keys have equivalent counts, yield permutations
    if source_keys.length == 1
      puts "yield #{{source_keys.first => other_keys.first}.inspect}" if ::RdfContext::debug?
      yield({source_keys.first => other_keys.first})
    else
      (0..(source_keys.length-1)).to_a.permute do |indicies|
        puts "indicies #{indicies.inspect}" if ::RdfContext::debug?
        ok = other_keys.dup
        map = indicies.inject({}) { |hash, i| hash[source_keys[i]] = ok.shift; hash}
        puts "yield #{map.inspect}" if ::RdfContext::debug?
        yield(map)
      end
    end
  else
    # Break bnodes into 2 arrays sharing a common usage count and permute each separately
    max = values.max
    bn_source_min = bn_source.clone
    bn_other_min = bn_other.clone
    bn_source_max = {}
    bn_other_max = {}
    bn_source.each_pair do |bn, v|
      bn_source_max[bn] = bn_source_min.delete(bn) if v == max
    end
    bn_other.each_pair do |bn, v|
      bn_other_max[bn] = bn_other_min.delete(bn) if v == max
    end

    puts "yield permutations of multiple with max #{bn_source_max.inspect}\n  and #{bn_other_max.inspect}" if ::RdfContext::debug?
    # Yield for each permutation of max joined with permutations of min
    bnode_permutations(bn_source_max, bn_other_max) do |bn_perm_max|
      bnode_permutations(bn_source_min, bn_other_min) do |bn_perm_min|
        yield bn_perm_max.merge(bn_perm_min)
      end
    end
  end
end