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::BLANK_NODE_LABEL, RDF::NTriples::Reader::COMMENT, RDF::NTriples::Reader::DATATYPE_URI, RDF::NTriples::Reader::ECHAR, RDF::NTriples::Reader::END_OF_STATEMENT, RDF::NTriples::Reader::ESCAPE_CHARS, RDF::NTriples::Reader::ESCAPE_CHARS_ESCAPED, RDF::NTriples::Reader::ESCAPE_CHARS_ESCAPED_REGEXP, RDF::NTriples::Reader::IRIREF, RDF::NTriples::Reader::IRI_RANGE, RDF::NTriples::Reader::LANGTAG, RDF::NTriples::Reader::LANG_DIR, 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::PN_CHARS, RDF::NTriples::Reader::PN_CHARS_BASE, RDF::NTriples::Reader::PN_CHARS_U, RDF::NTriples::Reader::PREDICATE, RDF::NTriples::Reader::QT_END, RDF::NTriples::Reader::QT_START, RDF::NTriples::Reader::STRING_LITERAL_QUOTE, RDF::NTriples::Reader::SUBJECT, RDF::NTriples::Reader::TT_END, RDF::NTriples::Reader::TT_START, RDF::NTriples::Reader::UCHAR, RDF::NTriples::Reader::UCHAR4, RDF::NTriples::Reader::UCHAR8, RDF::NTriples::Reader::URIREF, RDF::NTriples::Reader::U_CHARS1, RDF::NTriples::Reader::U_CHARS2

Constants included from Util::Logger

Util::Logger::IOWrapper

Instance Attribute Summary

Attributes inherited from Reader

#options

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_eos, #read_literal, #read_node, #read_quotedTriple, #read_tripleTerm, #read_uriref, #read_value, unescape, unserialize

Methods included from Util::Logger

#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger

Methods inherited from Reader

#base_uri, #canonicalize?, #close, each, #each_pg_statement, #each_statement, #each_triple, #encoding, #fail_object, #fail_predicate, #fail_subject, for, format, #initialize, #intern?, #lineno, open, options, #prefix, #prefixes, #prefixes=, #read_statement, #rewind, #to_sym, to_sym, #valid?, #validate?

Methods included from Util::Aliasing::LateBound

#alias_method

Methods included from Enumerable

#canonicalize, #canonicalize!, #dump, #each_graph, #each_object, #each_predicate, #each_quad, #each_statement, #each_subject, #each_term, #each_triple, #enum_graph, #enum_object, #enum_predicate, #enum_quad, #enum_statement, #enum_subject, #enum_term, #enum_triple, #graph?, #graph_names, #invalid?, #method_missing, #object?, #objects, #predicate?, #predicates, #project_graph, #quad?, #quads, #respond_to_missing?, #statement?, #statements, #subject?, #subjects, #supports?, #term?, #terms, #to_a, #to_h, #to_set, #triple?, #triples, #valid?, #validate!

Methods included from Countable

#count, #empty?

Methods included from Readable

#readable?

Constructor Details

This class inherits a constructor from RDF::Reader

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RDF::Enumerable

Instance Method Details

#read_tripleArray

Read a Quad, where the graph_name 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
86
87
88
89
# 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
        # FIXME: quoted triples are now deprecated
        subject   = read_uriref || read_node || read_quotedTriple || fail_subject
        predicate = read_uriref(intern: true) || fail_predicate
        object    = read_uriref || read_node || read_literal || read_tripleTerm || read_quotedTriple || fail_object
        graph_name    = read_uriref || read_node
        if validate? && !read_eos
          log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
        end
        return [subject, predicate, object, {graph_name: graph_name}]
      end
    rescue RDF::ReaderError => e
      @line = line  # this allows #read_value to work
      raise e
    end
  end
end