how to space two sentences if you are multiplying same sentence - spacing

I want to multiply a name like a = "name" but space them between
like a*3 = 'namenamename'
I want it in this way = 'name name name', but i don't want to add space to the end of a

Related

Skimage's cut_normalized return a single label

I'm trying to learn how to segment an image using Normalization Cut. My problem is that I would use superpixel and then NCUT, but the cut_normalized method gives me a single value, and so if I plot it, I have a single color, as follows:
This is my code:
def normcut_segmentations(img):
labels, superpixels = get_super_pixels(img)
g = graph.rag_mean_color(img, labels, mode='similarity')
ncuts_labels = graph.cut_normalized(labels, g)
print("Segmentation label: ", np.unique(labels))
print("NCUTs Label:",np.unique(ncuts_labels))
ncuts_result = color.label2rgb(ncuts_labels, img, kind='avg')
return ncuts_labels,ncuts_result
To read the image (that is a bitmap), I use skimage.io.imread(img_filename).
What would be the problem?
Thanks!

Multiply select value from QUERY

I have created a named range called coins and have the following query:
=QUERY(coins,"SELECT C WHERE A = '"&B17&"' ")
which returns the correct values. If I want to multiply this number by e.g. 2 and write the following:
=QUERY(coins,"SELECT C*2 WHERE A = '"&B17&"' ")
my cell is replaced with product(2()) and the correct value is placed at the underneath cell.
I have tried also:
=QUERY(coins,"SELECT product(C,2) WHERE A = '"&B17&"' ")
but had no correct result.
How do I get the value of the multiplication on that specific cell and not the one underneath?
try like this:
=QUERY(coins, "SELECT C*2 WHERE A = '"&B17&"' label C*2''")

How to calculate the spaces between texts according to rectangle width?

I would like to ask you, how to calculate the text position, more like the spaces between texts.
Ive got an array with texts text1, text2, text3, text4... And I can call a function to get the length of the text in pixels and I also know the length of the rectangle and I would like to calculate the spaces between each text to entirely fill the rectangle and only keep 10px from both sides.
Function to get the text length is dxGetTextWidth and rectangle width is specified in a variable called rWidth.
How can I calculate it?
A Text Justification Algorithm can do what your looking for.
https://www.rose-hulman.edu/class/csse/csse221/200910/Projects/Markov/justification.html
Here is an example based on your question:
local output_width = 0
local line_width = box.rWidth() - 20 --10px from each side
local line = {}
for text in ipairs(texts) do
text_width = text.dxGetTextWidth()
if (output_width + text_width <= line_width) then
output_width = output_width + text_width
line[#line + 1] = text
else
remaining_space = line_width - output_width
space_width = remaining_space / #line --space evenly spread over words in the line
for text in ipairs(line) do
--now add the space between each word
end
end
end

How to reveal string one letter at a time?

I'm learning from a book, and this is the assignment question i'm working on:
Create an app that asks for the users name and then displays the name down the side of the screen, one letter at a time.
Clarify what i'm trying trying to do: Have users name fade in one at a time vertically. Example: Adam "A" would appear after 1 second , "d" would appear after 3 seconds under the displayed A, "a" would appear after 5 seconds under the displayed d, "m" would appear after 7 seconds under the displayed a. The visuals would have a sort of domino effect.When they appear they would stay displayed on screen.
So far i'm able to get the user's name and display it side ways. Have it fade it in within 2 seconds. I'm stuck on how to get the letters to fade in one letter at a time.
function submit ()
print( "connect" )
userName = userNameField.text
display_userName = display.newText( userName, display.contentWidth-20, display.contentHeight/2 )
display_userName.rotation = 90
display_userName.alpha = 0
userNameField: removeSelf( )
greeting:removeSelf( )
submitButton:removeSelf( )
transition.fadeIn( display_userName, {time = 2000} )
Please let me know if you need to see more of my code.
You can do it in a simple way as below:
local myString = "Adam" -- Create your string
local positionCount = 0 -- initialize a variable to determine letter position
local function displayData()
positionCount = positionCount + 1
if(positionCount<=string.len(myString))then
-- if positionCount is less than or equal to letters in 'myString'
local letter = string.sub(myString, positionCount, positionCount) -- get the current letter
local letterLabel = display.newText(letter,20,20*positionCount,nil,20) -- place the letter
letterLabel.alpha = 0;
-- display the label and update the function after the completion of transition
transition.to(letterLabel,{time=1000,alpha=1,onComplete=displayData})
end
end
displayData()
Keep Coding.................... :)
Here is the code snippet for storing every character in a table.
Initialise a variable:
check =0;
Here splitWord is an table to store each character of string. and variable "yourStringForOneLetter" is your string variable for splitting. "string.sub" will split string into words using for loop.
if(check==wordSize) then
check=1
end
local wordSize = string.len(yourStringForOneLetter)
splitWord = {}
for i=check, check do
splitWord[i] = string.sub(yourStringForOneLetter, i, i)
check= check +1;
end

iOS: Algorithm to center a word in a sentence inside of a UILabel

I need to center a particular word in a sentence by truncating the beginning and endings of a long sentence inside of a UILabel, For example
NSString mySentence = #"This is my very long sentence to give you an example of what I am trying to do.. And its still going..";
NSString myWord = #"example";
<Algorithm goes here>
Should display:
"...sentence to give you an example of what I am trying to..."
If the word is closer to one end or the other, just do your best to center and display an appropriate amount of the text, example:
NSString myWord = #"my";
"This is my very long sentence to give you an example of what..."
Any ideas?
Thanks.
I believe you can do a scan for your search to be placed. Let's say you have the index in a variable named centerWordIndex. You could then split the string based on whitechars, and add words to the beginning and the end of your word until you are out of words at each side, or until the size of you string matches the size of the label.
what do you think :) ?
The data you need to start is:
the width of your label (call it labelWidth)
the width of the word you want to center (call it wordWidth)
Then the size on each side you have to work with is (labelWidth - wordWidth) / 2. Don't worry about using this value, it's just the target.
You can use the ability to calculate the size of a NSString using
CGSize newSize = [myString sizeWithFont: myFont];
CGFloat newWidth = newSize.width;
The goal of the algorithm should be to continue to add words on each side of the centered word and recalculating the total width each step. If you've gone past labelWidth, you can't add that word or anymore from that direction. So, in pseudocode, one approach is:
calculate labelWidth and wordWidth
set currentWidth to wordWidth
set currentLeftPosition to position of first letter of word
set currentRightPosition to position of last letter of word
set currentString to word
set currentImbalance to 0
algorithm start:
scan for position of 2 spaces to left of currentLeftPosition or start of string
set leftTrialPosition to position found
set leftTrialString as between leftTrialPosition and currentRightPosition inclusive
calculate trialLeftWidth of leftTrialString
scan for position of 2 spaces to right of currentRightPosition or end of string
set rightTrialPosition to position found
set rightTrialString as between currentLeftPosition and rightTrialPositon inclusive
calculate trialRightWidth of rightTrialString
if (trialLeftWidth - currentImbalance <= trialRightWidth
&& trialLeftWidth <= labelWidth
&& trialLeftWidth != currentWidth)
set currentImbalance -= calculate width of string from leftTrialPosition to currentLeftPosition
set currentLeftPosition = leftTrialPosition
set currentWidth = trialLeftWidth
set currentString = leftTrialString
else if (same checks for right)
same steps using right data
else if (both left and right are larger than label or both sides no longer grow bigger)
algorithm is done - return here
recurse to algorithm start
Using this basic strategy, you track the left imbalance (negative) or right imbalance (positive) throughout the algorithm and preferentially add the left or right word accordingly until you have the biggest string of complete words that can fit on the label or you have used the full string. The key iOS specific part here is the NSString method that calculates the width.

Resources