Class: FactDb::Models::EntityMention

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/fact_db/models/entity_mention.rb

Overview

Join model linking entities to facts with role information

Represents how an entity is mentioned in a specific fact, including the exact text used and the semantic role (subject, object, etc.).

Examples:

Create a mention

mention = EntityMention.create!(
  fact: fact, entity: person,
  mention_text: "John", mention_role: "subject"
)

Constant Summary collapse

ROLES =

Returns valid mention roles.

Returns:

  • (Array<String>)

    valid mention roles

%w[subject object location temporal instrument beneficiary].freeze

Instance Method Summary collapse

Instance Method Details

#by_role(role) ⇒ ActiveRecord::Relation

Returns mentions with a specific role

Parameters:

  • role (String)

    the mention role

Returns:

  • (ActiveRecord::Relation)


34
# File 'lib/fact_db/models/entity_mention.rb', line 34

scope :by_role, ->(role) { where(mention_role: role) }

#high_confidenceActiveRecord::Relation

Returns mentions with confidence >= 0.9

Returns:

  • (ActiveRecord::Relation)


49
# File 'lib/fact_db/models/entity_mention.rb', line 49

scope :high_confidence, -> { where("confidence >= ?", 0.9) }

#object?Boolean

Checks if this mention has the object role

Returns:

  • (Boolean)

    true if mention_role is “object”



61
62
63
# File 'lib/fact_db/models/entity_mention.rb', line 61

def object?
  mention_role == "object"
end

#objectsActiveRecord::Relation

Returns mentions with object role

Returns:

  • (ActiveRecord::Relation)


44
# File 'lib/fact_db/models/entity_mention.rb', line 44

scope :objects, -> { by_role("object") }

#subject?Boolean

Checks if this mention has the subject role

Returns:

  • (Boolean)

    true if mention_role is “subject”



54
55
56
# File 'lib/fact_db/models/entity_mention.rb', line 54

def subject?
  mention_role == "subject"
end

#subjectsActiveRecord::Relation

Returns mentions with subject role

Returns:

  • (ActiveRecord::Relation)


39
# File 'lib/fact_db/models/entity_mention.rb', line 39

scope :subjects, -> { by_role("subject") }