Error when trying to convert sentence to Pig Latin in App Inventor 2 - app-inventor

I'm trying to create a basic sentence - pig latin translator for my CSP class.
Both me and my teacher have gone over this and agree it looks as though it should work, but we could both be missing something simple.
It perhaps could be an issue with AI itself but I won't jump to that as a first conclusion.
There are multiple errors, each to do with either a select, remove, or replace list item, such as that
The operation select list item cannot accept the arguments: , [(The quick brown fox jumped over the lazy dog)], [The]
Thanks for any help!

The operation select list item cannot accept the arguments: , [(The
quick brown fox jumped over the lazy dog)], [The]
the error message is trying to tell you, that a select list item block needs an index as second argument, but got the word "The" instead... this happens, because the local variable item is a single word of your sentence, but not an index.

Related

Google Sheets: using Query in ArraryFormula

I have a sheet to apply Query function to get the respective search data row by row. But I need to apply ArrayFormula to automate this search process. I want to know how should I do.
Expected Result
Check phrase Result 1 Result 2 Result 3 Result 4
Apple Apple Ice Apple Custard apple/Sugar apple/Sweetsop Rose apple/Water apple
berry Cape gooseberry/Inca berry/Physalis
man Mango Mangosteen
mom
fruit Dragon fruit Egg fruit Passion fruit Black sapote/Chocolate pudding fruit
j Jackfruit Jujube Jenipapo
nake Snake fruit/Salak
me Horned Melon Honeydew melon Medlar fruit Mouse melon
Currently
Check phrase Result 1 Result 2 Result 3 Result 4
Apple Apple Ice Apple
berry Apple Ice Apple
man Apple Ice Apple
mom Apple Ice Apple
fruit Apple Ice Apple
j Apple Ice Apple
nake Apple Ice Apple
me Apple Ice Apple
What I currently achieve is for single row using this:
=IF(LEN(F2:F)=0, IFERROR(1/0), IF(LEN(F2:F)>0, Query(TRANSPOSE(QUERY(Fruits!B:B, "select B where B contains '" & F2:F & "'")),"select * limit 12")))
How should I do. Please advise me. I attach my file link here.
[My Google Sheet file]
(https://docs.google.com/spreadsheets/d/1QDfruKtwJjmRQWqTlO3sBM-e9vp9QKwmla23ss0U1sY/edit#gid=1411907513)
use:
=ARRAY_CONSTRAIN(LAMBDA(a, b, BYROW(a, LAMBDA(x,
TRANSPOSE(IFNA(FILTER(b, SEARCH(IF(x="", "×", x), b)))))))
(F2:INDEX(F:F, MAX(ROW(F:F)*(F:F<>""))), Fruits!B2:B), 9^9, 12)
=LAMBDA(PHRASES,FRUITS,
BYROW(PHRASES,LAMBDA(FRUIT,
TRANSPOSE(FILTER(FRUITS,REGEXMATCH(FRUITS,FRUIT)))
))
)(QUERY({Current!F2:F},"WHERE Col1 IS NOT NULL"),QUERY({Fruits!B:B},"WHERE Col1 IS NOT NULL"))
Put this formula into G2, the result should be same as this image.
What we are doing here is...
use QUERY to get rid of blanks in range Current!F2:F, name the array as PHRASES with LAMBDA.
use QUERY to get rid of blanks in range Fruits!B:B, name the array as FRUITS with LAMBDA.
use BYROW to work on the single column array FRUITS value by value, with...
LAMBDA inside BYROW to name the value of each ROW as FRUIT,
use FILTER to filter the array FRUITS,
use REGEXMATCH to set the condition of the filter funciton in step.5, which returns TRUE for string matches,
TRANSPOSE the result of each filter to met your display format.
The filter can also be replaced by another QUERY function if you want, outputs should be identical in this case.
=LAMBDA(PHRASES,FRUITS,
BYROW(PHRASES,LAMBDA(FRUIT,
TRANSPOSE(QUERY(FRUITS,"WHERE Col1 CONTAINS '"&FRUIT&"'"))
))
)(QUERY({Current!F2:F},"WHERE Col1 IS NOT NULL"),QUERY({Fruits!B:B},"WHERE Col1 IS NOT NULL"))
According to you request in comments, this is the updated code:
to make it case insensitive, apply UPPER() to Col1 and FRUIT inside the transposed query,
to show blank instead of #N/A when there is no output on that row, apply IFNA() to the whole QUERY() inside the TRANSPOSE(),
to limit the length of the output array, warp up the TRANSPOSE() with ARRAY_CONSTRAIN().
=LAMBDA(NOTNULL,LAMBDA(PHRASES,FRUITS,
BYROW(PHRASES,LAMBDA(PHRASE,
ARRAY_CONSTRAIN(
TRANSPOSE(IFNA(
QUERY(FRUITS,"WHERE UPPER(Col1) CONTAINS '"&UPPER(PHRASE)&"'"),
"")),
1,12)
))
)(QUERY({Current!F2:F},NOTNULL),QUERY({Fruits!B:B},NOTNULL)))("WHERE Col1 IS NOT NULL")
The code will leave an empty row if there is no match found, which is required in your comment * Show blank if no valid return. (instead of #N/A),
What do you means When there is no phrase match, that row skipped?
It won't in my test environment.
But if you mean when you leave some part of the 'check phrase' column empty, it does break the calculation, because this case is never mentioned, that you may have blanks in the check phrase column, so I simply didn't handle it.
And if that is the case, you should always include such conditions into the sample data you provide at the very begining, otherwise this is another issue, and maybe better to open another question to ask about a solution after you trying to work it out on your own.
Anyway, this is a quick solution if you need to handle blanks in Check phrase column:
=LAMBDA(NOTNULL,LAMBDA(PHRASES,FRUITS,
BYROW(PHRASES,LAMBDA(PHRASE,
ARRAY_CONSTRAIN(TRANSPOSE(IFNA(IF(PHRASE="","",QUERY(FRUITS,"WHERE UPPER(Col1) CONTAINS '"&UPPER(PHRASE)&"'")),"")),1,12)
))
)({Current!F2:F},QUERY({Fruits!B:B},NOTNULL)))("WHERE Col1 IS NOT NULL")
The reason why the output result shifts upward when there are blanks in 'Check phrase' column, is because, as I said, I uses QUERY to get rid of extra blanks of the 2 source data, this helps speed things up a bit, but if there are blanks between array values, they will also be removed, which lead to the reference array being shortened.
To handle this issue, the easiest slove is, instead of removing the blanks, leave them there, and inside IFNA(), wherever encountering empty PHRASE, use a IF() to skip it by doing nothing, which result in leaving a blank row.

How to remove word in a visual selection in Vim

Suppose I have the following input as shown below. What I would like to do is to visually select lines 2 through 4 (shift + v) and then delete the word dog.
How can I do that? I know I can use something like :s/dog// on my selection, but I was wondering if there's a more straightforward way.
1 The quick brown dog
2 dog jumps
3 over the
4 lazy dog,
5 but it should be just a fox.
The final output should be (affected only by the visual selection on lines 2 through 4):
1 The quick brown dog
2 jumps
3 over the
4 lazy ,
5 but it should be just a fox.
That's impossible.
Why?
tl;dr
I think, you are envisioning something like a normal mode within visual mode (so that you can "move and delete like in Vim" while you are in visual mode). Such a thing doesn't exist.
Think about it: if you visual select some lines, then those lines, and nothing else, are the object of whatever action you do next (d, s, c, or whatever).
But you want to take an action not on those visually selected lines, but on words within them. But how can you tell Vim to take action on the words dog and not on other words? You can do that with movements, but as long as you are in visual mode, that's not possible, because any movement will just change the visual selection, and not allow you to somehow move within it.
This means that you need to abandon the visual selection so that you can move to those words and use them as the textual object for the action.
If you really want to start from the visual selection, then the only way to give the info that you want to take action on the words dog, is to type them out while you are in visual mode. And that's precisely what the :s approach does.
You can take advantage of the marks '< and '>: they store the start/end position of the visual selection and they keep their value after you exit the visual mode.
In command line mode, Ctrl-RCtrl-W inserts the word under the cursor.
By combining this, you can create a mapping like that:
noremap <c-d> :'<,'>s/<c-r><c-w>//<cr>
Then to use it:
first select the wanted zone with V;
hit Esc to exit visual mode;
move your cursor under the word you want to delete;
then trigger the mapping, in this example Ctrl-D.
I think there is no way in way to just replace a specific word in specific lines with visual selection. You can also use sed for that (look at #5).
Anyways:
Here are 4 way to delete the word dog in a file and one way to do it with sed:
1 (with visual mode):
Type v to enter visual character mode
Highlight dog
Press d for deleting
2 (with substitute and confirmation):
:%s/dog//gc
g stands for global
c stand for confirmation
You will be ask for every entry, what to do with.
3 (with substitute):
:2,4s/dog//
4 (with search mode):
/dog
Type: n for next match
Type: d for deleting the match
For further information: Search and Replace
5 (with sed):
sed 2,4\s/dog// filename
When you are in visual mode, pressing : automatically inserts the visual range in the command-line so whatever Ex command you use after that is going to work on the visually selected lines:
: becomes :'<,'>, in which '<,'> is a range beginning on the first line of the visual selection and ending on the last line of the visual selection.
After that, you can do s/dog<CR> (no need for the //) to substitute the first dog with nothing on every selected line. This is effectively equivalent to doing :2,4s/dog<CR>.
From a semantic point of view, :s/dog<CR> is as close as you can get with the built-in features to "remove dog in the current visual selection" so, barring making an hypothetical custom mapping that would only save a couple of keystrokes, you are unlikely to find a more "straightforward" way.

To build a flow using Power Automate to download linked csv report in gmail

I'm trying to create a flow using Power Automate (which I'm quite new to) that can get the link/URL in an email I receive daily, then download the .csv file that normally a click to the link would do, and then save the file to a given local folder.
An example of the email I get:
Screenshot of the email I get daily
I searched in Power Automate Community and found this insightful LINK post & answer almost solved it. However, after following the steps and built the flow, it kept failing at the Compose step.
Screenshot of the Flow & Error Message
The flow
Error message
Expression used:
substring(body('Html_to_text'),add(indexOf(body('Html_to_text'),'here'),5),sub(indexOf(body('Html_to_text'),'Name'),5))
Seems the expression couldn't really get the URL/Link? I'm not sure and searched but couldn't find any more posts that can help.
Please kindly share all insights on approaches or workarounds that you think may help me solve the problem and truly thanks!
PPPPPPPPisces
We need to breakdown the bits of the function here which needs 3 bits of info
substring(1 text to search, 2 starting position of the text you want, 3 length of text)
For example, if you were trying to return an unknown number from the text dog 4567 bird
Our function would have 3 parts.
body('Html_to_text'), this bit gets the text we are searching for
add(indexOf(body('Html_to_text'),'dog'),4), this bit finds the position in the text 4 characters after the start of the word dog (3 letters for dog + the space)
sub(sub(indexOf(body('Html_to_text'),'bird'),2)),add(indexOf(body('Html_to_text'),'dog'),4)), I've changed the structure of your code here because this part needs to return the length of the URL, not the ending position. So here, we take the position of the end of the URL (position of the word bird minus two spaces) and subtract it from the position of the start of the URL (position of the word dog + 4 spaces) to get the length.
In your HTML to text output, you need to check what the HTML looks like, and search for a word before the URL starts, and a word after the URL starts, and count the exact amount of spaces to reach the URL. You can then put those words and counts into your code.
More generally, when you have a complicated problem that you need to troubleshoot, you can break it down into steps. For example. Rather than putting that big mess of code into a single block, you can make each chunk of the code in its own compose, and then one final compose to bring them all together - that way when you run it you can see what information each bit is giving out, or where it is failing, and experiment from there to discover what is wrong.

Algorithm for translating MLB play-by-play records into descriptive text

I'm trying to collect a dataset that could be used for automatically generating baseball articles.
I have play-by-play records of MLB games from retrosheet.org that I would like to be written out to plain text, as those that could possibly appear as part of a recap news article.
Here are some examples of the play-by-play records:
play,2,0,semim001,32,.CBFFFBBX,9/F
play,2,0,phegj001,01,FX,S7/G
play,2,0,martn003,01,CX,3/G
play,2,1,youne003,00,,NP
The following is what I would like to achieve:
For the first example
play,2,0,semim001,32,.CBFFFBBX,9/F,
I want it to be written out as something like:
"semim001 (Marcus Semien) was on three balls and two strikes in the second inning as the away player. He hit the ball into play after one called strike, one ball, three fouls, and another two balls. The fly ball was caught by the right outfielder."
The plays are formatted in the following way:
The first field is the inning, an integer starting at 1.
The second field is either 0 (for visiting team) or 1 (for home team).
The third field is the Retrosheet player id of the player at the plate.
The fourth field is the count on the batter when this particular event (play) occurred. Most Retrosheet games do not have this information, and in such cases, "??" appears in this field.
The fifth field is of variable length and contains all pitches to this batter in this plate appearance and is described below. If pitches are unknown, this field is left empty, nothing is between the commas.
The sixth field describes the play or event that occurred.
Explanations for all the symbols in the fifth and sixth field can be found on this Retrosheet page.
With Python 3, I've been able to format all the info of invariable length into a formatted sentence, which is all but the last two fields. I'm having difficulty in thinking of an efficient way to unparse (correct me if this is the wrong term to use here) the fifth and sixth fields, the pitches and the events that occurred, due to their variable length and wide variety of things that can occur.
I think I could write out all the rules based on the info on the Retrosheet website, but I'm looking for suggestions for a smarter way to do this. I wrote natural language processing as tags, hoping this could be a trivial problem in that field. Any pointers will be greatly appreciated!

Trying to exclude a portion of an xPath

I have looked through several posts about this, but have failed to apply the principles used to get the result I desire, so I'm going to just post my specific problem.
I am building a Google Sheet that enables the user to pull up Bible verses.
I have it all working, however I am running into an issue with a hidden element being pulled into my text().
FUNCTION:
=IMPORTXML("http://www.biblestudytools.com/ESV/Numbers/5-3.html",
"//*[#class='scripture']//span[2]//text()")
RESULT: You shall put out both male and female, putting them outside the camp, that they may not defile their camp, 1in the midst of which I dwell."
You can see the "1" that is showing up before the word "in"
I have found the xPath that pulls only that "1"
//*[#class='scripture']//span[2]//sup//text()
I am trying to remove that "1" from the text.
HELP PLEASE!!! :)
You can add a predicate to the end to exclude text nodes that are inside sup elements:
=IMPORTXML("http://www.biblestudytools.com/ESV/Numbers/5-3.html",
"//*[#class='scripture']//span[2]//text()[not(ancestor::sup)]")
This will retrieve only the text nodes that are not inside a sup element, but it will still result in having the verse spread out across two cells, because there are two text nodes. You can rectify this by wrapping this expression in a JOIN():
=JOIN("", IMPORTXML("http://www.biblestudytools.com/ESV/Numbers/5-3.html",
"//*[#class='scripture']//span[2]//text()[not(ancestor::sup)]"))

Resources