Search code examples
listvariablesmit-scratchnlp-question-answering

Scratch project: To check if any word in a list is contained in an answer


I have the following Scratch project which has a "kind list" of words like: "good", "kind", "love", "come" etc.

A user should be able to enter any sentence containing any of these words, and the happy face would show.

enter image description here

Currently if the user types "kind" the happy face shows and if it types anything else like "you are kind", the sad face shows.

How do I change this, in scratch, such that if the user types in:

"you are kind" or "how kind you are" or "come here" (any sentence containing any word in the "kindlist") the face is happy,else not.

I can only find a block that allows me to select the LIST and then the ANSWER and no other alternatives. What I want is the Python equivalent of > in list

answer=input("Say something") If any word in the input answer (sentence) in in the list. Then do - - -

For teaching purposes, I am trying to simplify what is on https://machinelearningforkids.co.uk/#!/newproject (creating of the training set). Can this be done directly in scratch or not? Or is this why the site allows you generate blocks on their site first and import them.

Surely Scratch should have the capability to enter data into lists and then test them directly.

I've also tried using a loop (which doesn't quite work correctly either) but was hoping there was a far simpler way.

enter image description here


Solution

  • I guess Scratch deliberately offers a minimal set of functions, on the one hand not to overwhelm beginners, on the other hand to encourage students to piece together simple blocks into more complex systems. Yes, a simple (sentence) contains (word) is all you get out-of-the-box; you do need a loop to match a multi-word sentence against a multi-word whitelist.

    Seems to me like you would be better off with some development environment that will at least give you some mature text parsing capabilities. I'm not saying it's impossible to teach student about machine learning using Scratch, but I doubt it's the best tool for the job. It feels like somebody wants to give music lessons, but students first have to go through the process of building a piano.

    As for your code, it looks like a good start. Some suggestions:

    • Replace the 'forever' loop with a loop bounded by the length of list 'kindthings'.
    • Include a leading and a trailing space in the 'contains' check, to make sure only whole words match. Wouldn't want 'unhappy' in a sentence to match 'happy' in the whitelist.