Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate nodes for gliner graph transformer #26

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ def __init__(
import gliner_spacy # type: ignore # noqa: F401
except ImportError:
raise ImportError(
"Could not import relik python package. "
"Could not import gliner-spacy python package. "
"Please install it with `pip install gliner-spacy`."
)
try:
import spacy # type: ignore
except ImportError:
raise ImportError(
"Could not import relik python package. "
"Could not import spacy python package. "
"Please install it with `pip install spacy`."
)
try:
import glirel # type: ignore # noqa: F401
except ImportError:
raise ImportError(
"Could not import relik python package. "
"Could not import gliner python package. "
"Please install it with `pip install gliner`."
)

Expand Down Expand Up @@ -101,15 +101,17 @@ def process_document(self, document: Document) -> GraphDocument:
[(document.page_content, self.allowed_relationships)], as_tuples=True
)
)
# Convert nodes
nodes = []
for node in docs[0][0].ents:
nodes.append(
Node(
id=node.text,
type=node.label_,
)
# Deduplicate nodes
deduplicated_nodes = {(node.text, node.label_) for node in docs[0][0].ents}

# Step 2: Convert back to Node objects
nodes = [
Node(
id=node_text,
type=node_label,
)
for node_text, node_label in deduplicated_nodes
]
# Convert relationships
relationships = []
relations = docs[0][0]._.relations
Expand Down
Loading