Skip to content

Commit

Permalink
refactor: settings.CorpData
Browse files Browse the repository at this point in the history
  • Loading branch information
engisalor committed Dec 4, 2023
1 parent b98d0e2 commit 66314ee
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ def __init__(self):
class CorpData:
"""Dataclass with corpus data."""

def __init__(self):
def get_label(self, row: dict) -> str | None:
return self.dt.get(row["corpus"]).get("label").get(row["attr"], row["attr"])

def is_in_list(self, row: dict, key: str) -> bool:
return row["attr"] in self.dt.get(row["corpus"]).get(key, [])

def run(self):
# load corpora file
self.dt = read_yaml(env.CORPORA_YML)
self.colors = {v["name"]: v["color"] for k, v in self.dt.items()}
Expand Down Expand Up @@ -106,28 +112,21 @@ def __init__(self):
wordlist_calls = []
self.structures = pd.DataFrame()
self.sizes = pd.DataFrame()

def get_label(row: dict) -> str | None:
return self.dt.get(row["corpus"]).get("label").get(row["attr"], row["attr"])

def is_in_list(row: dict, key: str) -> bool:
return row["attr"] in self.dt.get(row["corpus"]).get(key, [])

for x in range(len(corp_ids)):
_structures = j.data.corpinfo[x].structures_from_json()
_structures["corpus"] = corp_ids[x]
_structures["attr"] = (
_structures["structure"] + "." + _structures["attribute"]
)
_structures["comparable"] = _structures.apply(
is_in_list, key="comparable", axis=1
self.is_in_list, key="comparable", axis=1
)
_structures["label"] = _structures.apply(get_label, axis=1)
_structures["label"] = _structures.apply(self.get_label, axis=1)
_structures["exclude"] = _structures.apply(
is_in_list, key="exclude", axis=1
self.is_in_list, key="exclude", axis=1
)
_structures["choropleth"] = _structures.apply(
is_in_list, key="choropleth", axis=1
self.is_in_list, key="choropleth", axis=1
)
self.structures = pd.concat([self.structures, _structures])
_sizes = j.data.corpinfo[x].sizes_from_json()
Expand All @@ -147,6 +146,9 @@ def is_in_list(row: dict, key: str) -> bool:
_ttypes["corpus"] = call.params["corpname"]
self.ttypes = pd.concat([self.ttypes, _ttypes])

def __init__(self):
self.run()


env = ENV()
corp_data = CorpData()
Expand Down

0 comments on commit 66314ee

Please sign in to comment.