App inventor 2 MockingApp - app-inventor

I am trying to create an app in MIT App Inventor that allows me to type a sentence or a word into the text box and when I click the submit button, the result will show a mocked version of that.
For example, if I type in "hello there sir," it will take each separate letter and randomize it to have capital lettering or lowercase lettering. So it could have a result like "hElLo tHErE sIr."
I assume the blocks would be made so that it would take each separate letter have a probability of 50% and capitalize the letter 50% of the time. But I do not know how to do that.
This is what i have so far, but the label turned up blank:

I am attaching the blocks as image. The function splits the original text into individual letters, and randomly upcases or downcases them.
Blocks

Related

Full stop added by speech recognition at the end of the spoken sentence doesn't match action

I have developed a Virtual Assistant and am using the WebChat to test it with the Cognitive Speech Services.
I have an issue: some responses from the bot include suggested actions like, for example,
"Choose a color"
"RED" "BLUE" "GREEN"
By typing in or clicking the chosen color everything is ok.
If I use the speech with the microphone a "full stop" is added at the end of the sentence, i.e. "BLUE."
This way LUIS doesn't recognize the answer and re-asks the question.
What is the best way to make it recognize correctly? Is there a way to disable the final full stop from being added by the speech engine? Or is there a better solution? (like normalizing punctuation in LUIS to make it ignore that or something else?)
You will want to scrub the activity of any punctuation after it has been received by your bot but before it is sent to and processed by LUIS. You can use the following regex to remove the unwanted characters (choose the characters you want to scrub...I included a lot) and to replace remaining stacked white spaces, like so:
let text = turnContext.context.activity.text;
let scrubbedText = text.replace(/[.,/#!$%\^&*;:{}=-_`~()]/g,"");
const finalString = scrubbedText.replace(/\s{2,}/g," ");
Then, update the activity.text with the scrubbed text and send it to LUIS.

Java textbox accepting specif number

I am planning to make a maths game there will be one question like 1+ 1 as an image in Javafx. The textbox provided will give the user to input the number how do for example for 1+1 just allow the user to put in 2 and for everything else it will not accept then number in the text box. and display a message try again or something similar.
Basicly how do I restrict the text box for a specific number

Building a GUI in Netbeans, which should I use?

I am building a GUI in Netbeans - it is for a simple little application - a converter program. Basically, user types whatever it is they want to convert into a text field, selects the conversion from a number of radio buttons (say lbs to kg) and then clicks "Convert".
The thing is, I want the "Convert" button and the radio buttons to behave like this:
Radio buttons and "Convert" button are disabled when program loads.
Radio buttons and "Convert" button will become enabled if user types a number (and only a number) into the text field.
If used deletes what they have typed, everything will be disabled again until they type in another number.
I have managed to set the Radio buttons and "Convert" button up so they are disabled, by unchecking the "enabled" box in the properties for each component. I have also been able to use a simple if statement and the keyTyped event to enable/disable as follows:
private void txtUsrInputKeyTyped(java.awt.event.KeyEvent evt)
{
if (!txtUsrInput.getText().equals(""))
{
btnCalculate.setEnabled(true);
}
else
{
btnCalculate.setEnabled(false);
}
}
I want to extend my code so that if the user accidentally types a letter or symbol into the text field (don't ask me why they'd do that, when they know they must only type a number) then the program will either ignore what they typed, or display an error. The exception to this is, of course, typing a period (.) because they might want to indicate a decimal number.
Any thoughts on how I might do this? Hope what I wrote makes sense!
Your GUI
If you do not already know swing, then learn it. Knowing how all of the components work is always a huge advantage for any developer, and if anything goes wrong, you know exactly how to fix it (or at least have a much better chance). Take a look at this stuff, for some help on getting started.
Checking for a decimal
This looks like a job for regular expressions. What you can do is specify a number [0-9], and a period, \.. Then ensure that either a number or a decimal is typed a certain amount of times. The important thing to note here though, is that the user can only type one decimal, which winds up being:
([0-9]+(\.[0-9]+))
This will allow values like 9, 0.9, 1.9302. It will not allow values like .901. If you wish to allow that, simple swap the first + for a *.:
([0-9]*(\.[0-9]+))
Using it
Because a text box contains a string, you can compare it with your regex. Simply:
if(textBox1.getText().matches("([0-9]+(\.[0-9]+))")) {
// Run some code in here.
}
Well, if GUI is simple, DO NOT use GUI Builder, but code from scratch. Following harder path, you will learn about layouts, actionlisteners and so on ...

(Mac OS X, Cocoa) How to make drag-and-droppable placeholder elements in an input text field?

I'm writing a Cocoa app where I would like the user to be able to put together a template string using placeholders. (For example, an (artist) placeholder would be filled in by the artist of the song currently playing in iTunes, etc.) I've seen apps that do something like this where each possible placeholder term is displayed in a blue "lozenge," and the user can drag and drop these "lozenges" into an input text field to construct a string, optionally entering some custom text of their own (e.g. separating (artist) and (title) "lozenges" with a hyphen).
Does anyone know if there is any sample code anywhere that will help me implement something like this?
I'm talking about something like this: (this comes from the "Hazel" app where, in a Hazel rule, you can rename a file based on a template pattern you specify)
NSTokenField is focused in the above pic (has the blue ring around it). Each "token" (your lozenges) is an auto-recognized string for the token field. As rdelmar comments above, read up on NSTokenField and you'll be most of the way there.
The "source" of tokens is likely a rounded-edged NSBox containing lined-up borderless, no-background NSTokenFields with one token each. That'll give you easy drag-and-drop as well as easy alignment.
if you need to customize the l&f of the individual tokens, you need to implement your own stuff: NSTextView with NSTextAttachment which have NSTextAttachmentCells... Its painful and a lot of code but actually not that hard
The NSTokenAttachment cell only has lots of private l&f options :(

Does Shoes have a number input?

I'm trying my luck with Shoes and wanted to create a number input. I know there's list_box but that's a simple dropdown select which would require an array of known numbers. However I don't know how many numbers the array will hold. It could be anything between 1 and 1000 or more. The user will have to decide that. And its methods (on The Shoes Manual website) don't seem to help me with my wish either.
To clarify what I mean with 'number input': In HTML5 we have <input type=number> and OS X has the Date Picker (or the Stepper + Text Field wich does, by my understanding, basically the same thing but consists of 2 objects).
Is there any way that I can create a number input like this with Shoes?
You are looking for the EditLine element. It can accept any text, and you can hook up your own checking algorithm to its change event (which can handle non-digits).

Resources