Graph Operations
Interlink
The interlink function merges multiple knowledge graphs into a single, interlinked graph.
Synchronous
interlink
def interlink(
kbs: List[KnowledgeGraph],
interlinking_key_uris: List[str] = [
"http://www.w3.org/2000/01/rdf-schema#label"
],
immutable_properties: Optional[List[str]] = None,
merge_properties_on_conflict: bool = False,
) -> KnowledgeGraph:Merges a list of knowledge graphs.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
kbs | List[KnowledgeGraph] | A list of KnowledgeGraph objects to merge. | - |
interlinking_key_uris | List[str] | A list of URI keys (e.g., rdfs:label) to use for entity linking. | ["http://www.w3.org/2000/01/rdf-schema#label"] |
immutable_properties | Optional[List[str]] | A list of properties that should not be changed during a merge conflict. | None |
merge_properties_on_conflict | bool | If True, merges properties on conflict instead of raising an error. | False |
Returns
| Type | Description |
|---|---|
KnowledgeGraph | A single, merged KnowledgeGraph object. |
Example
import perseus_client
from perseus_client.models import KnowledgeGraph
# Assume 'graphs' is a list of KnowledgeGraph objects from build_graph
graphs = [...]
try:
merged_graph = perseus_client.interlink(graphs)
print("Graphs interlinked successfully.")
except Exception as e:
print(f"An error occurred: {e}")Asynchronous
interlink_async
async def interlink_async(
kbs: List[KnowledgeGraph],
interlinking_key_uris: List[str] = [
"http://www.w3.org/2000/01/rdf-schema#label"
],
immutable_properties: Optional[List[str]] = None,
merge_properties_on_conflict: bool = False,
) -> KnowledgeGraph:Asynchronously merges a list of knowledge graphs.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
kbs | List[KnowledgeGraph] | A list of KnowledgeGraph objects to merge. | - |
interlinking_key_uris | List[str] | A list of URI keys (e.g., rdfs:label) to use for entity linking. | ["http://www.w3.org/2000/01/rdf-schema#label"] |
immutable_properties | Optional[List[str]] | A list of properties that should not be changed during a merge conflict. | None |
merge_properties_on_conflict | bool | If True, merges properties on conflict instead of raising an error. | False |
Returns
| Type | Description |
|---|---|
KnowledgeGraph | A single, merged KnowledgeGraph object. |
Example
import asyncio
import perseus_client
from perseus_client.models import KnowledgeGraph
# Assume 'graphs' is a list of KnowledgeGraph objects from build_graph
graphs = [...]
async def main():
try:
merged_graph = await perseus_client.interlink_async(graphs)
print("Graphs interlinked successfully.")
except Exception as e:
print(f"An error occurred: {e}")
finally:
await perseus_client.close_async()
if __name__ == "__main__":
asyncio.run(main())