Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Extract Color Given Word or Sentence

I am in the middle of trying to cleanup several hundred thousand lines of data that is managed by users inputting data into a field. There has been no re-cleaning of the data after input masks were recently set.

Now I am trying to hypothesize given a word(Color) or sentence(may or may not have a Color in it) passed into a function and return its best Color guess.

Is there a library that currently does this that I am not aware of?

Example

Input: INT SATIN BASE

Output: SATIN

Input: Light Red

Output: Red

Input: Latching Box - White

Output: White

like image 232
evolancer Avatar asked Oct 19 '25 07:10

evolancer


1 Answers

You can use python colour package to check where input keyword is color or not. To install, use pip install colour

>>> from colour import Color
>>> s = 'Light Red'
>>> _color = [i for i in s.split(' ') if check_color(i)]
['Red']    

Here is the custom function:

def check_color(color):
    try:
        Color(color)
        return True
    except ValueError:
        return False
like image 134
akash karothiya Avatar answered Oct 20 '25 19:10

akash karothiya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!