Thanks Charley!
I got the speeded up script working great, thanks for that.
I half understand it, slowly getting there
I decided the code needed reworking so it looks for partial matches for all the genres i have provided (41 of them), and then the new code to map scarey to Horror etc (rather than have 41 for loops)
Here is the new code:
Code:
def evaluate(self, formatter, kwargs, mi, locals, val):
list1 = val
l2 = ['adult', 'adventure', 'anthologies', 'biography', 'childrens', 'classics', 'drugs', 'fantasy', 'food', 'football', 'health', 'history', 'historical', 'horror', 'humour', 'inspirational', 'modern', 'music', 'mystery', 'non-fiction', 'poetry', 'political', 'philosophy', 'psychological', 'reference', 'religion', 'romance', 'science', 'science fiction', 'self help', 'short stories', 'sociology', 'spirituality', 'suspense', 'thriller', 'travel', 'vampires', 'war', 'western', 'writing', 'young adult']
l1 = [l.strip() for l in list1.split(',') if l.strip()]
l1lcase = [icu_lower(l) for l in l1]
res = set()
for idx,item in enumerate(l1lcase):
if item in l2:
res.add(l1[idx])
for item in l1lcase:
for item2 in l2:
if item2 in item:
res.add(item2)
break
for item in l1lcase:
if 'scary' in item or 'spooky' in item:
res.add('Horror')
break
return ', '.join(res)
But this bit of that code adds tags in lowercase:
Code:
for item in l1lcase:
for item2 in l2:
if item2 in item:
res.add(item2)
break
I tried using
res.add(titlecase(item2))
but that thows an error
Maybe i need to keep the list2 in titlecase and lowercase it as i go, ill try to figure it out but if you can put me on the right path i would really appreciate it.
Thanks!