Fix weight casting during graph extraction (#1016)

* Fix weight casting during graph extraction

* Format

* Format
This commit is contained in:
Alonso Guevara 2024-08-23 20:51:59 -06:00 committed by GitHub
parent e15df44f0d
commit 55e74a0c2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

View File

@ -0,0 +1,4 @@
{
"type": "patch",
"description": "Fix weight casting during graph extraction"
}

View File

@ -4,7 +4,6 @@
"""A module containing 'GraphExtractionResult' and 'GraphExtractor' models."""
import logging
import numbers
import re
import traceback
from collections.abc import Mapping
@ -248,11 +247,11 @@ class GraphExtractor:
target = clean_str(record_attributes[2].upper())
edge_description = clean_str(record_attributes[3])
edge_source_id = clean_str(str(source_doc_id))
weight = (
float(record_attributes[-1])
if isinstance(record_attributes[-1], numbers.Number)
else 1.0
)
try:
weight = float(record_attributes[-1])
except ValueError:
weight = 1.0
if source not in graph.nodes():
graph.add_node(
source,