Spacy regex over entities - expression

How can you use in Spacy v2 the usual regex functionality but over named entities and POS?
It seems that the full syntax of the Matcher's patterns is not available.
Only scattered examples like the following are available
[{'LOWER': 'facebook'}, {'LEMMA': 'be'}, {'POS': 'ADV', 'OP': '*'}, {'POS': 'ADJ'}]
What I need is to allow for an arbitrary number of repetions of a group.
In the example below assume color as an entity and I only know Red is a color.
"Red, green and black" , "Red, white, green and black"
I need to recognize green, black, white as color entities as well since I know red is a color entity and whatever follows it by comma is also a color.
Atm i do it like this but it works only for a certain number of commas, not for an arbitrary number:
pattern = [{'ent_type': 'Color'}, {'IS_PUNCT': True}, {'POS': 'NOUN'}, {'IS_PUNCT': True}, {'POS': 'NOUN'}, {'POS': 'CCONJ'},{'POS': 'NOUN'}]
matcher.add('commas', add_event_skill, pattern)
In a more advanced version of my question, red would be allowed to be in any position of the sentencne, not only the first.

Related

NUmber formatting to display green and red in Google sheets

I have a custom number formatting where I need to change the numbers from black for postive and red for negative
I have the format as: [$₹][>9999999]##\,##\,##\,##0.00;[$₹][>99999]##\,##\,##0.00;[$₹]##,##0.00;
The formatting is used to displaying lakh and crore number systems. I only need to display the colors.
Like this?
[$₹][green]##,##0.00;[$₹][red]##,##0.00;[$₹]##,##0.00;
Not sure about >999... conditions, you do not mention those.

Sass color transform calculation

I have two shades of the color blue (#1E95EF -> #1988DD), and need to figure out the color transformation that has happened in order to replicate it across other colors in my palette (red, green etc).
I've used combinations of darken()/lighten() & saturate()/desaturate() to eyeball the transformation, and have gotten it pretty close:
desaturate(darken(#1E95EF, 4.5%), 8%); === #1A88DC
But I need to get it exactly right, so that the small errors that I make with the percentage decimal points are not replicated across all of the colors. How can I figure out exactly what transformation has occurred?
Here is what I've tried:
sassmeister gist
In this snippet, the relevant classes to my example are .ga-primary and .ga-primary-hover
You can measure the differences between colors in different ways, depending on the color model/space you're using. Hex colors use RGB, but the HSL model will be more useful here. It records a color as 3 values: Hue, Saturation and Lightness.
We can use SASS's HSL functions to work out how each value of the color differs, and then selectively apply that difference to other colors:
$start-color: #1E95EF
$end-color: #1988DD
//We won't need the hue-difference in practice
$hue-difference: hue($start-color) - hue($end-color)
//These express the difference as a percentage
$saturation-difference: saturation($start-color) - saturation($end-color)
$lightness-difference: lightness($start-color) - lightness($end-color)
#function color-adjust($base-color)
//Apply the lightness and saturation changes but keep the original Hue
#return hsl(hue($base-color), saturation($base-color) + $saturation-difference, lightness($base-color) + $lightness-difference)
//To find the adjusted color, just pass whatever base color you like to the color-adjust function:
background: color-adjust(red)
Here's a demo with a few colors: http://codepen.io/anon/pen/bqOaZZ
Obviously that code can be compacted a lot - I'm thinking that what you really want is to define your variants as a set of Saturation/Lightness changes, and then apply them to your whole palette (rather than trying to 'reverse-engineer' it from one example pair). If you want help with something to do that, let me know!

colored text with highlighted data via colored gem

I am trying to achieve multi colored text with the colored gem in ruby.
Basically I want to set a base color for the text, but highlight specific details in another color while still keeping all the other text in the base color.
For example if I do something like:
puts "Found #{book_title.yellow} and it has #{chapters.to_s.yellow} chapters".green
I would of expected that the entire phrase would be green except for the book title and number of chapters which should be yellow.
Instead the results are that "Found" is green, book title is yellow, "and it has" is white (no color), chapters is yellow, and "chapters" is white (no color).
It simply appears that appending .green to the surrounding string doesn't re-add the color codes after a color change when using #{} to insert data.
I want to build this functionality into a info function like so:
def info(message)
time_stamp = "[#{Time.new.strftime("%H:%M:%S")}]"
puts "#{time_stamp} Info: #{message}".green
end
So that when I call it like so:
info "Found #{book_title.yellow} and it has #{chapters.to_s.yellow} chapters"
It will print the entire statement in green with highlighted text in yellow as described above.
Is this possible without breaking the string into substrings and concatting them, or specifying a hard coded list of arguments to the info function (the number of highlighted texts is dynamic). Is there a VA_LIST type like in C's printf I could use?
I wouldn't mind calling the function as:
info "Found %s and it has %d chapters", book_title.yellow, chapters.to_s.yellow
or something similar. But I would still need to figure out a way to set the color codes for each segment of text and concat them together.
Hopefully this makes sense.

Text processing... Shell Scripting

I'm having issues wrapping my brain around how to accomplish this.
Basically, as I go through a text document I have I get a comma separated line where there are two attributes then an image name. The next couple lines lack the two attributes but contain different image names. To the software I'm working with, these additional image named lines without the two attributes are related to the first line WITH the attributes. I would like to take the two attributes and assign them to the next lines that lack them... The number of images per "group" varies. It looks like this:
red, large, kitty1235.jpg
,, kitty1294.jpg
,, kitty3452.jpg
orange, small, cuteface123.jpg
,,adorable544.jpg
...and what I am trying to do is:
red, large, kitty1235.jpg
red, large, kitty1294.jpg
red, large, kitty3452.jpg
orange, small, cuteface123.jpg
orange, small, adorable544.jpg
I know there has to be a way, I'm guessing I'm going to have to use an array but I'm a newb at that. Any help would be GRAND.
Thanks!
Here is the awk solution, which could be easily adjusted to virtually any language. It takes line by line, remembers the values of the first and second fields, and uses them if the fields are empty:
> awk -F, 'BEGIN {f1="";f2="";OFS=", "} {if ($1=="") $1=f1; if ($2=="") $2=f2; f1=$1;f2=$2; print}' x.txt
red, large, kitty1235.jpg
red, large, kitty1294.jpg
red, large, kitty3452.jpg
orange, small, cuteface123.jpg
orange, small, adorable544.jpg

How can i get light green ansi code and get bigger font for ruby?

printf "\033[1;32;40mGreen text on black background.\033[0m\n"
That is the green, but how can i get light green or other variation of color?
http://pueblo.sourceforge.net/doc/manual/ansi_color_codes.html , are only those color available for gnome-terminal as escape code?
Also how can i get bigger font with ruby?
using the "1" as the first parameter, as you are doing already, that's as "light" a green as you're going to get. this guy's webpage might be helpful: http://www.linuxfocus.org/English/May2004/article335.shtml
testing on urxvt:
[added later] there is a DEC extension for double-sized characters: Printing double-size characters with Ncurses but urxvt doesn't support it, I don't know about Gnome terminal.
With an offset of 90 you can create bright/high contrast colors.
See here for a reference. Wikipedia mentions the bright color range, but doesn't really explain how to use them (if I haven't missed it).
If you combine it with the bold style you can create 4 variations of a color.
Example:
It's a matter of the terminal support. The ansi codes that you list are interpreted by the terminal emulator and those codes are the only available colours (it comes from the days before windows and when 16 colours caused a stir).
If you need more you could consider using a graphical interface to your ruby app such as tk.
You can use an RGB escape code:
printf "\033[38;2;r;g;bmText\033[0m"
or, for background colour:
printf "\033[48;2;r;g;bmText\033[0m"
Just replace r, g, and b with the desired RGB value.

Resources