Class: FactDb::Models::FactSource
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- FactDb::Models::FactSource
- Defined in:
- lib/fact_db/models/fact_source.rb
Overview
Join model linking facts to source documents
Represents the provenance relationship between a fact and the source document(s) it was extracted from, including the relationship type and an optional excerpt.
Constant Summary collapse
- KINDS =
Returns valid source relationship kinds.
%w[primary supporting corroborating].freeze
Instance Method Summary collapse
-
#corroborating ⇒ ActiveRecord::Relation
Returns corroborating source links.
-
#excerpt_preview(length: 100) ⇒ String?
Returns a preview of the excerpt, truncated if needed.
-
#high_confidence ⇒ ActiveRecord::Relation
Returns source links with confidence >= 0.9.
-
#primary ⇒ ActiveRecord::Relation
Returns primary source links.
-
#primary? ⇒ Boolean
Checks if this is the primary source for the fact.
-
#supporting ⇒ ActiveRecord::Relation
Returns supporting source links.
Instance Method Details
#corroborating ⇒ ActiveRecord::Relation
Returns corroborating source links
43 |
# File 'lib/fact_db/models/fact_source.rb', line 43 scope :corroborating, -> { where(kind: "corroborating") } |
#excerpt_preview(length: 100) ⇒ String?
Returns a preview of the excerpt, truncated if needed
61 62 63 64 65 66 |
# File 'lib/fact_db/models/fact_source.rb', line 61 def excerpt_preview(length: 100) return nil if excerpt.nil? return excerpt if excerpt.length <= length "#{excerpt[0, length]}..." end |
#high_confidence ⇒ ActiveRecord::Relation
Returns source links with confidence >= 0.9
48 |
# File 'lib/fact_db/models/fact_source.rb', line 48 scope :high_confidence, -> { where("confidence >= ?", 0.9) } |
#primary ⇒ ActiveRecord::Relation
Returns primary source links
33 |
# File 'lib/fact_db/models/fact_source.rb', line 33 scope :primary, -> { where(kind: "primary") } |
#primary? ⇒ Boolean
Checks if this is the primary source for the fact
53 54 55 |
# File 'lib/fact_db/models/fact_source.rb', line 53 def primary? kind == "primary" end |
#supporting ⇒ ActiveRecord::Relation
Returns supporting source links
38 |
# File 'lib/fact_db/models/fact_source.rb', line 38 scope :supporting, -> { where(kind: "supporting") } |