Skip to content

Commit

Permalink
introduce unknown concept and handling
Browse files Browse the repository at this point in the history
  • Loading branch information
soad003 committed Jan 2, 2025
1 parent f3bb261 commit 3305508
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/tagpack/db/concepts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ concept:
Anything that describes an actor in the Darknet- or Cryptoasset Ecosystems.
narrower: [entity, behaviour]

unknown:
id: unknown
type: concept
prefLabel: Unknown
description: >
Special category representing a tag with unknown categorization
broader: concept

behaviour:
id: behaviour
type: concept
Expand Down
8 changes: 7 additions & 1 deletion src/tagstore/algorithms/tag_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ def add_tag_data(t, tags_count, total_words):
concepts_counter.add(x, weight=conf * _get_concept_weight(x))

ls["concepts"].add(x)
else:
# tags without categorization are added to unknown category in wordcloud
x = "unknown"
concepts_counter.add(x, weight=conf * _get_concept_weight(x))

ls["concepts"].add(x)

ls["cnt"] += 1
ls["lbl"] = t.label
Expand Down Expand Up @@ -181,7 +187,7 @@ def add_tag_data(t, tags_count, total_words):
].capitalize()

# get broad category
broad_concept = "user"
broad_concept = "entity"
if len(concepts_counter) > 0:
broad_concept = _map_concept_to_broad_concept(
concepts_counter.most_common(1, weighted=True)[0][0]
Expand Down
12 changes: 7 additions & 5 deletions src/tagstore/db/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ class TagPublic(BaseModel):
@computed_field
@property
def concepts(self) -> List[str]:
return (
[self.primary_concept] + self.additional_concepts
if (self.primary_concept)
else self.additional_concepts
)
return dict.fromkeys(
(
[self.primary_concept] + self.additional_concepts
if (self.primary_concept)
else self.additional_concepts
)
).keys()

@classmethod
def fromDB(cls, t: Tag, tp: TagPack, inherited_from=None) -> "TagPublic":
Expand Down

0 comments on commit 3305508

Please sign in to comment.