drepr.writers.base#

Classes

class StreamClassWriter[source]#

Bases: object

has_written_record(subject: str) bool[source]#

Test if a record of a given subject has been written

Parameters:

subject (str) –

Return type:

bool

begin_record(class_uri: str, subject: str, is_blank: bool, is_buffered: bool) bool[source]#

Tell the writer that we are going to write a record, and we already have all information of the record to write. The function return true if this is a new record, otherwise false.

# Arguments

  • class_uri - the URI of the class that the record belongs to

  • subject - real id of the record, which is determined by the value of drepr:uri property

    of the record or generated randomly (if it’s a blank node)

  • is_blank - whether this subject is a blank node or not

Parameters:
  • class_uri (str) –

  • subject (str) –

  • is_blank (bool) –

  • is_buffered (bool) –

Return type:

bool

end_record()[source]#

Tell the writer that we finish writing all information of the record. This method cannot be called before begin_record method.

Note: this method should not be called if the function begin_record return false

begin_partial_buffering_record(subject: str, is_blank: bool) bool[source]#

Tell the writer that we are going to write a record, and we don’t have some information about the links between the records and other records as the other records haven’t been generated yet. The function return true if this is a new record, otherwise false.

# Arguments

  • subject - real id of the record, which is determined by the value of drepr:uri property

    of the record

  • is_blank - whether this subject is a blank node or not

Parameters:
  • subject (str) –

  • is_blank (bool) –

Return type:

bool

write_data_property(subject: str, predicate_id: str, value: Any)[source]#

Write value of a data property of the current record.

# Arguments

  • subject - real id of the current record

  • predicate_id - id of the data property that we are writing to (edge_id of the edge in the

    semantic model)

  • value - value of the property

Parameters:
  • subject (str) –

  • predicate_id (str) –

  • value (Any) –

write_object_property(predicate_id: str, object: str, is_subject_blank: bool, is_object_blank: bool, is_new_subj: bool)[source]#

Write value of a object property of the current record.

# Arguments

  • predicate_id - id of the object property that we are writing to (edge_id of the edge in the

    semantic model)

  • object - id of the target record

  • is_subject_blank - whether the subject id is blank

  • is_object_blank - whether the object id is blank

  • is_new_subj - whether the current record is a new record or an existing record (obtained

    from the begin_record or begin_partial_buffering_record function

Parameters:
  • predicate_id (str) –

  • object (str) –

  • is_subject_blank (bool) –

  • is_object_blank (bool) –

  • is_new_subj (bool) –

buffer_object_property(target_cls: str, predicate_id: str, object: str, is_object_blank: bool)[source]#

Write value of a object property of the current record into buffer because we haven’t generated the target object, it may be missed later.

# Arguments

  • target_cls: id of the class of the target record that the current record is linked to,

    which is the node_id of the class node in the semantic model

  • predicate_id - id of the object property that we are writing to (edge_id of the edge in the

    semantic model)

  • object - id of the target record

  • is_object_blank - whether the object is blank node or not

Parameters:
  • target_cls (str) –

  • predicate_id (str) –

  • object (str) –

  • is_object_blank (bool) –