This commit is contained in:
bashrc committed 2021-07-13 09:43:07 +01:00
1 parent 33ecd05abb
commit 8485371197
2 files changed
+6 -3

No files matched your search

+4 -1
View File
@@ -165,6 +165,9 @@ def guessHashtagCategory(tagName: str, hashtagCategories: {}) -> str:
"""Tries to guess a category for the given hashtag.
This works by trying to find the longest similar hashtag
"""
if len(tagName) < 4:
return ''
categoryMatched = ''
tagMatchedLen = 0
@@ -185,5 +188,5 @@ def guessHashtagCategory(tagName: str, hashtagCategories: {}) -> str:
if len(hashtag) > tagMatchedLen:
categoryMatched = categoryStr
if not categoryMatched:
return
return ''
return categoryMatched
+2 -2
View File
@@ -2843,12 +2843,12 @@ def _testGuessHashtagCategory() -> None:
print('testGuessHashtagCategory')
hashtagCategories = {
"foo": ["swan", "goose"],
"bar": ["cat", "mouse"]
"bar": ["cats", "mouse"]
}
guess = guessHashtagCategory("unspecifiedgoose", hashtagCategories)
assert guess == "foo"
guess = guessHashtagCategory("catpic", hashtagCategories)
guess = guessHashtagCategory("mastocats", hashtagCategories)
assert guess == "bar"