Class: Dbd::ContextFact

Inherits:
Fact
  • Object
show all
Defined in:
lib/dbd/context_fact.rb

Overview

ContextFact

ContextFact is derived from Fact and behaves very similar.

The ContextFacts with same subject form a Context and this is used as the target for the context_subject of a Fact.

The context_subject of a ContextFact itself is empty, so the usage of context_subject is not recursive on this level (this allows efficient single pass loading in an underlying database).

In the serialisation of a fact stream, the presence or absence of a context_subject marks the difference between a Fact and a ContextFact.

The predicates of the ContextFacts in a Context would typically come from a defined context ontology (including provenance). Experimental examples of ontologies are built in the dbd_onto project.

Instance Method Summary collapse

Methods inherited from Fact

attributes, #context_subject=, #equivalent?, #errors, factory, #short, #string_values, #subject=, #time_stamp=, #values

Constructor Details

#initialize(options) ⇒ ContextFact

Builds a new ContextFact.

Parameters:

  • options (Hash{Symbol => Object})

Options Hash (options):

  • :subject (Fact::Subject) — default: new_subject

    Optional: the subject for the ContextFact

  • :predicate (String)

    Required: the subject for the ContextFact

  • :object (String)

    Required: the object for the ContextFact



30
31
32
33
# File 'lib/dbd/context_fact.rb', line 30

def initialize(options)
  validate_context_subject(options)
  super
end

Instance Method Details

#context_fact?Boolean

Confirms this is a ContextFact

Needed for validations that depend on different behavior for a context_fact (mainly, no context_subject).

Returns:

  • (Boolean)


50
51
52
# File 'lib/dbd/context_fact.rb', line 50

def context_fact?
  true
end

#context_subject_error(context_subject) ⇒ Object

Validates the presence or absence of context_subject.

Here, in the derived ContextFact, it must not be present. Return [nil, String] nil if valid, an error message if not

Parameters:

  • context_subject (#nil?)


41
42
43
# File 'lib/dbd/context_fact.rb', line 41

def context_subject_error(context_subject)
  "ContextFact subject should not be present in ContextFact" if context_subject
end