mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
naive entity matching
This commit is contained in:
parent
02e68d73ae
commit
c20ad8efee
@ -4,7 +4,37 @@ class DocumentEntity < ApplicationRecord
|
||||
|
||||
after_create :match_notebook_page
|
||||
|
||||
def match_notebook_page
|
||||
# TODO: Attempt to link to a Notebook.ai page of the same name
|
||||
# TODO should this be some chain of method aliases maybe? or cached on object?
|
||||
def document_owner
|
||||
document_analysis.document.user
|
||||
end
|
||||
|
||||
def match_notebook_page!
|
||||
matched_entity = document_owner.send(entity_relation).detect do |entity|
|
||||
entity_match?(entity)
|
||||
end
|
||||
|
||||
# If we found a Notebook.ai entity to match to, hurrah!
|
||||
if matched_entity.present?
|
||||
update(
|
||||
entity_type: matched_entity.class.name,
|
||||
entity_id: matched_entity.id
|
||||
)
|
||||
end
|
||||
|
||||
# Return true/false for whether we found a match
|
||||
matched_entity.present?
|
||||
end
|
||||
|
||||
def entity_relation
|
||||
# 'Character' => 'characters'
|
||||
self.entity_type.downcase.pluralize
|
||||
end
|
||||
|
||||
def entity_match?(entity)
|
||||
return unless entity.respond_to?(:name)
|
||||
|
||||
# TODO: levenshtein distance threshold comparison?
|
||||
entity.name == self.text
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user