merge-requests/30/head
Bob Mottram 2021-07-13 09:43:07 +01:00
parent 33ecd05abb
commit 8485371197
2 changed files with 6 additions and 3 deletions

View File

@ -165,6 +165,9 @@ def guessHashtagCategory(tagName: str, hashtagCategories: {}) -> str:
"""Tries to guess a category for the given hashtag. """Tries to guess a category for the given hashtag.
This works by trying to find the longest similar hashtag This works by trying to find the longest similar hashtag
""" """
if len(tagName) < 4:
return ''
categoryMatched = '' categoryMatched = ''
tagMatchedLen = 0 tagMatchedLen = 0
@ -185,5 +188,5 @@ def guessHashtagCategory(tagName: str, hashtagCategories: {}) -> str:
if len(hashtag) > tagMatchedLen: if len(hashtag) > tagMatchedLen:
categoryMatched = categoryStr categoryMatched = categoryStr
if not categoryMatched: if not categoryMatched:
return return ''
return categoryMatched return categoryMatched

View File

@ -2843,12 +2843,12 @@ def _testGuessHashtagCategory() -> None:
print('testGuessHashtagCategory') print('testGuessHashtagCategory')
hashtagCategories = { hashtagCategories = {
"foo": ["swan", "goose"], "foo": ["swan", "goose"],
"bar": ["cat", "mouse"] "bar": ["cats", "mouse"]
} }
guess = guessHashtagCategory("unspecifiedgoose", hashtagCategories) guess = guessHashtagCategory("unspecifiedgoose", hashtagCategories)
assert guess == "foo" assert guess == "foo"
guess = guessHashtagCategory("catpic", hashtagCategories) guess = guessHashtagCategory("mastocats", hashtagCategories)
assert guess == "bar" assert guess == "bar"