-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommunity.py
69 lines (55 loc) · 2.23 KB
/
community.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A package containing the 'Community' model."""
from dataclasses import dataclass
from typing import Any
from graphrag.model.named import Named
@dataclass
class Community(Named):
"""A protocol for a community in the system."""
level: str = ""
"""Community level."""
entity_ids: list[str] | None = None
"""List of entity IDs related to the community (optional)."""
relationship_ids: list[str] | None = None
"""List of relationship IDs related to the community (optional)."""
covariate_ids: dict[str, list[str]] | None = None
"""Dictionary of different types of covariates related to the community (optional), e.g. claims"""
sub_community_ids: list[str] | None = None
"""List of community IDs of the child nodes of this community (optional)."""
attributes: dict[str, Any] | None = None
"""A dictionary of additional attributes associated with the community (optional). To be included in the search prompt."""
size: int | None = None
"""The size of the community (Amount of text units)."""
period: str | None = None
""
@classmethod
def from_dict(
cls,
d: dict[str, Any],
id_key: str = "id",
title_key: str = "title",
short_id_key: str = "human_readable_id",
level_key: str = "level",
entities_key: str = "entity_ids",
relationships_key: str = "relationship_ids",
covariates_key: str = "covariate_ids",
sub_communities_key: str = "sub_community_ids",
attributes_key: str = "attributes",
size_key: str = "size",
period_key: str = "period",
) -> "Community":
"""Create a new community from the dict data."""
return Community(
id=d[id_key],
title=d[title_key],
short_id=d.get(short_id_key),
level=d[level_key],
entity_ids=d.get(entities_key),
relationship_ids=d.get(relationships_key),
covariate_ids=d.get(covariates_key),
sub_community_ids=d.get(sub_communities_key),
attributes=d.get(attributes_key),
size=d.get(size_key),
period=d.get(period_key),
)