Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Want to add custom words #84

Open
aditya113141 opened this issue Jun 15, 2022 · 1 comment
Open

Want to add custom words #84

aditya113141 opened this issue Jun 15, 2022 · 1 comment

Comments

@aditya113141
Copy link

I need to add words - 'Software' and 'Foundation' to the list of words to be cleaned. How to modify the library ?

@FBnil
Copy link
Contributor

FBnil commented Aug 16, 2022

There's a bug in the code that does not allow you to prepare your terms (because the function does not allow parameters), so here's a way to do it, without the need to modify the library:

from cleanco import basename
from cleanco.clean import custom_basename,normalize_terms,terms_by_type,terms_by_country
import functools
import operator


my_terms_by_type = {
   'Foundation': ['fnd']
}

def prepare_my_terms(terms_by_type, terms_by_country):
    ts = functools.reduce(operator.iconcat, terms_by_type.values(), [])
    cs = functools.reduce(operator.iconcat, terms_by_country.values(), [])
    terms = set(ts + cs)
    nterms = normalize_terms(terms)
    ntermparts = (t.split() for t in nterms)
    sntermparts = sorted(ntermparts, key=lambda x: (-len(x), x))
    return [(len(tp), tp) for tp in sntermparts]

business_name1 = "Some Big Pharma, LLC"
business_name2 = "Spaguetti, fnd"

print(basename(business_name1))
print(basename(business_name2))

my_terms=prepare_my_terms( { **terms_by_type, **my_terms_by_type }, terms_by_country)

print(custom_basename(business_name1, my_terms))
print(custom_basename(business_name2, my_terms))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants