Class: RDF::NQuads::Reader

Inherits:
RDF::NTriples::Reader show all
Defined in:
lib/rdf/nquads.rb

Constant Summary

Constants inherited from RDF::NTriples::Reader

RDF::NTriples::Reader::COMMENT, RDF::NTriples::Reader::DATATYPE_URI, RDF::NTriples::Reader::ESCAPE_CHAR, RDF::NTriples::Reader::ESCAPE_CHAR4, RDF::NTriples::Reader::ESCAPE_CHAR8, RDF::NTriples::Reader::ESCAPE_CHARS, RDF::NTriples::Reader::ESCAPE_SURROGATE, RDF::NTriples::Reader::ESCAPE_SURROGATE1, RDF::NTriples::Reader::ESCAPE_SURROGATE2, RDF::NTriples::Reader::LANGUAGE_TAG, RDF::NTriples::Reader::LITERAL, RDF::NTriples::Reader::LITERAL_PLAIN, RDF::NTriples::Reader::LITERAL_WITH_DATATYPE, RDF::NTriples::Reader::LITERAL_WITH_LANGUAGE, RDF::NTriples::Reader::NODEID, RDF::NTriples::Reader::OBJECT, RDF::NTriples::Reader::PREDICATE, RDF::NTriples::Reader::SUBJECT, RDF::NTriples::Reader::URIREF

Instance Attribute Summary

Attributes inherited from Reader

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RDF::NTriples::Reader

parse_literal, parse_node, parse_object, parse_predicate, parse_subject, parse_uri, #read_comment, #read_literal, #read_node, #read_uriref, #read_value, unescape, unserialize

Methods inherited from Reader

#base_uri, #close, each, #each_statement, #each_triple, for, format, #initialize, open, #prefix, #prefixes, #prefixes=, #rewind, #to_sym, to_sym

Methods included from Util::Aliasing::LateBound

#alias_method

Methods included from Enumerable

#contexts, #dump, #each_context, #each_graph, #each_object, #each_predicate, #each_quad, #each_statement, #each_subject, #each_triple, #enum_context, #enum_graph, #enum_object, #enum_predicate, #enum_quad, #enum_statement, #enum_subject, #enum_triple, #has_context?, #has_object?, #has_predicate?, #has_quad?, #has_statement?, #has_subject?, #has_triple?, #objects, #predicates, #quads, #statements, #subjects, #supports?, #to_a, #to_hash, #to_set, #triples

Methods included from Countable

#count, #empty?, #enum_for

Methods included from Readable

#readable?

Constructor Details

This class inherits a constructor from RDF::Reader

Class Method Details

.parse_context(input) ⇒ RDF::Term

Parameters:

  • input (String)

Returns:

Since:

  • 0.4.0



57
58
59
# File 'lib/rdf/nquads.rb', line 57

def self.parse_context(input)
  parse_uri(input) || parse_node(input) || parse_literal(input)
end

Instance Method Details

#read_tripleArray

Read a Quad, where the context is optional

Returns:

  • (Array)

See Also:

Since:

  • 0.4.0



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rdf/nquads.rb', line 67

def read_triple
  loop do
    readline.strip! # EOFError thrown on end of input
    line = @line    # for backtracking input in case of parse error

    begin
      unless blank? || read_comment
        subject   = read_uriref || read_node || fail_subject
        predicate = read_uriref(:intern => true) || fail_predicate
        object    = read_uriref || read_node || read_literal || fail_object
        context    = read_uriref || read_node || read_literal
        return [subject, predicate, object, {:context => context}]
      end
    rescue RDF::ReaderError => e
      @line = line  # this allows #read_value to work
      raise e
    end
  end
end