turtlestitch/libraries/word-sentence.xml

1 wiersz
17 KiB
XML

<blocks app="Snap! 4.0, http://snap.berkeley.edu" version="1"><block-definition s="all but first letter of %&apos;string&apos;" type="reporter" category="operators"><comment x="0" y="0" w="199" collapsed="false">Takes a text string as input, and reports a new text string containing all but the first character of the input.</comment><header></header><code></code><inputs><input type="%txt"></input></inputs><script><block s="doDeclareVariables"><list><l>result</l><l>i</l></list></block><block s="doWarp"><script><block s="doIf"><block s="reportEquals"><block s="reportStringSize"><block var="string"/></block><l>0</l></block><script><block s="doReport"><block s="reportListItem"><l>1</l><block s="reportSum"><l>0</l><l>0</l></block></block></block></script></block><block s="doSetVar"><l>result</l><l></l></block><block s="doSetVar"><l>i</l><l>2</l></block><block s="doUntil"><block s="reportGreaterThan"><block var="i"/><block s="reportStringSize"><block var="string"/></block></block><script><block s="doSetVar"><l>result</l><block s="reportJoinWords"><list><block var="result"/><block s="reportLetter"><block var="i"/><block var="string"/></block></list></block></block><block s="doChangeVar"><l>i</l><l>1</l></block></script></block><block s="doReport"><block var="result"/></block></script></block></script></block-definition><block-definition s="all but first word of %&apos;sentence&apos;" type="reporter" category="operators"><comment x="0" y="0" w="223.000001" collapsed="false">Takes a text string as input, divides it into words treating one or more spaces as a word separator (only spaces count; punctuation is part of the word) and reports a text string containing all but the first word, with one space between words and no spaces at the beginning or end. (Note: consider using SENTENCE-&gt;LIST and processing the resulting list instead of doing recursion on sentences in text string form. List operations are faster.)</comment><header></header><code></code><inputs><input type="%txt"></input></inputs><script><block s="doDeclareVariables"><list><l>index</l><l>bf</l></list></block><block s="doWarp"><script><block s="doSetVar"><l>bf</l><l></l></block><block s="doSetVar"><l>index</l><l>1</l></block><block s="doIf"><block s="reportEquals"><block s="reportStringSize"><block var="sentence"/></block><l>0</l></block><script><block s="doReport"><block s="reportListItem"><l>1</l><block s="reportJoinWords"><list><l>empty </l><l>sentence</l></list></block></block></block></script></block><block s="doUntil"><block s="reportOr"><block s="reportEquals"><block var="index"/><block s="reportStringSize"><block var="sentence"/></block></block><block s="reportNot"><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block></block></block><script><block s="doChangeVar"><l>index</l><l>1</l></block></script></block><block s="doIf"><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block><script><block s="doReport"><block s="reportListItem"><l>1</l><block s="reportJoinWords"><list><l>empty </l><l>sentence</l></list></block></block></block></script></block><block s="doUntil"><block s="reportOr"><block s="reportEquals"><block var="index"/><block s="reportStringSize"><block var="sentence"/></block></block><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block></block><script><block s="doChangeVar"><l>index</l><l>1</l></block></script></block><block s="doIf"><block s="reportEquals"><block var="index"/><block s="reportStringSize"><block var="sentence"/></block></block><script><block s="doReport"><l></l></block></script></block><block s="doUntil"><block s="reportOr"><block s="reportEquals"><block var="index"/><block s="reportStringSize"><block var="sentence"/></block></block><block s="reportNot"><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block></block></block><script><block s="doChangeVar"><l>index</l><l>1</l></block></script></block><block s="doIf"><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block><script><block s="doReport"><l></l></block></script></block><block s="doUntil"><block s="reportGreaterThan"><block var="index"/><block s="reportStringSize"><block var="sentence"/></block></block><script><block s="doSetVar"><l>bf</l><block s="reportJoinWords"><list><block var="bf"/><block s="reportLetter"><block var="index"/><block var="sentence"/></block></list></block></block><block s="doChangeVar"><l>index</l><l>1</l></block></script></block><block s="doReport"><block var="bf"/></block></script></block></script></block-definition><block-definition s="all but last letter of %&apos;string&apos;" type="reporter" category="operators"><comment x="0" y="0" w="218" collapsed="false">Takes a text string as input, and reports a new text string containing all but the last letter of the input.</comment><header></header><code></code><inputs><input type="%txt"></input></inputs><script><block s="doDeclareVariables"><list><l>result</l><l>i</l></list></block><block s="doWarp"><script><block s="doIf"><block s="reportEquals"><block s="reportStringSize"><block var="string"/></block><l>0</l></block><script><block s="doReport"><block s="reportListItem"><l>1</l><block s="reportSum"><l>0</l><l>0</l></block></block></block></script></block><block s="doSetVar"><l>result</l><l></l></block><block s="doSetVar"><l>i</l><l>1</l></block><block s="doUntil"><block s="reportEquals"><block var="i"/><block s="reportStringSize"><block var="string"/></block></block><script><block s="doSetVar"><l>result</l><block s="reportJoinWords"><list><block var="result"/><block s="reportLetter"><block var="i"/><block var="string"/></block></list></block></block><block s="doChangeVar"><l>i</l><l>1</l></block></script></block><block s="doReport"><block var="result"/></block></script></block></script></block-definition><block-definition s="all but last word of %&apos;sentence&apos;" type="reporter" category="operators"><comment x="0" y="0" w="212" collapsed="false">Takes a text string as input, divides it into words treating one or more spaces as a word separator (only spaces count; punctuation is part of the word) and reports a text string containing all but the last word, with one space between words and no spaces at the beginning or end. (Note: consider using SENTENCE-&gt;LIST and processing the resulting list instead of doing recursion on sentences in text string form. List operations are faster.)</comment><header></header><code></code><inputs><input type="%txt"></input></inputs><script><block s="doDeclareVariables"><list><l>index</l><l>bl</l></list></block><block s="doWarp"><script><block s="doSetVar"><l>bl</l><l></l></block><block s="doSetVar"><l>index</l><block s="reportStringSize"><block var="sentence"/></block></block><block s="doIf"><block s="reportEquals"><block s="reportStringSize"><block var="sentence"/></block><l>0</l></block><script><block s="doReport"><block s="reportListItem"><l>1</l><block s="reportJoinWords"><list><l>empty </l><l>sentence</l></list></block></block></block></script></block><block s="doUntil"><block s="reportOr"><block s="reportEquals"><block var="index"/><l>1</l></block><block s="reportNot"><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block></block></block><script><block s="doChangeVar"><l>index</l><l>-1</l></block></script></block><block s="doIf"><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block><script><block s="doReport"><block s="reportListItem"><l>1</l><block s="reportJoinWords"><list><l>empty </l><l>sentence</l></list></block></block></block></script></block><block s="doUntil"><block s="reportOr"><block s="reportEquals"><block var="index"/><l>1</l></block><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block></block><script><block s="doChangeVar"><l>index</l><l>-1</l></block></script></block><block s="doIf"><block s="reportEquals"><block var="index"/><l>1</l></block><script><block s="doReport"><l></l></block></script></block><block s="doUntil"><block s="reportOr"><block s="reportEquals"><block var="index"/><l>1</l></block><block s="reportNot"><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block></block></block><script><block s="doChangeVar"><l>index</l><l>-1</l></block></script></block><block s="doIf"><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block><script><block s="doReport"><l></l></block></script></block><block s="doUntil"><block s="reportLessThan"><block var="index"/><l>1</l></block><script><block s="doSetVar"><l>bl</l><block s="reportJoinWords"><list><block s="reportLetter"><block var="index"/><block var="sentence"/></block><block var="bl"/></list></block></block><block s="doChangeVar"><l>index</l><l>-1</l></block></script></block><block s="doReport"><block var="bl"/></block></script></block></script></block-definition><block-definition s="first word of %&apos;sentence&apos;" type="reporter" category="operators"><comment x="0" y="0" w="236" collapsed="false">Takes a text string as input, divides it into words treating one or more spaces as a word separator (only spaces count; punctuation is part of the word) and reports a text string containing only the first word, with no spaces before or after it.</comment><header></header><code></code><inputs><input type="%txt"></input></inputs><script><block s="doDeclareVariables"><list><l>index</l><l>first</l></list></block><block s="doWarp"><script><block s="doSetVar"><l>first</l><l></l></block><block s="doSetVar"><l>index</l><l>1</l></block><block s="doIf"><block s="reportEquals"><block s="reportStringSize"><block var="sentence"/></block><l>0</l></block><script><block s="doReport"><block s="reportListItem"><l>1</l><block s="reportJoinWords"><list><l>empty </l><l>sentence</l></list></block></block></block></script></block><block s="doUntil"><block s="reportOr"><block s="reportEquals"><block var="index"/><block s="reportStringSize"><block var="sentence"/></block></block><block s="reportNot"><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block></block></block><script><block s="doChangeVar"><l>index</l><l>1</l></block></script></block><block s="doIf"><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block><script><block s="doReport"><block s="reportListItem"><l>1</l><block s="reportJoinWords"><list><l>empty </l><l>sentence</l></list></block></block></block></script></block><block s="doUntil"><block s="reportOr"><block s="reportEquals"><block var="index"/><block s="reportStringSize"><block var="sentence"/></block></block><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block></block><script><block s="doSetVar"><l>first</l><block s="reportJoinWords"><list><block var="first"/><block s="reportLetter"><block var="index"/><block var="sentence"/></block></list></block></block><block s="doChangeVar"><l>index</l><l>1</l></block></script></block><block s="doIf"><block s="reportNot"><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block></block><script><block s="doSetVar"><l>first</l><block s="reportJoinWords"><list><block var="first"/><block s="reportLetter"><block var="index"/><block var="sentence"/></block></list></block></block></script></block><block s="doReport"><block var="first"/></block></script></block></script></block-definition><block-definition s="last letter of %&apos;word&apos;" type="reporter" category="operators"><comment x="0" y="0" w="260" collapsed="false">Takes a text string as input, and reports the last character in the string.</comment><header></header><code></code><inputs><input type="%txt"></input></inputs><script><block s="doReport"><block s="reportLetter"><block s="reportStringSize"><block var="word"/></block><block var="word"/></block></block></script></block-definition><block-definition s="last word of %&apos;sentence&apos;" type="reporter" category="operators"><comment x="0" y="0" w="262" collapsed="false">Takes a text string as input, divides it into words treating one or more spaces as a word separator (only spaces count; punctuation is part of the word) and reports a text string containing only the last word of the input, with no spaces before or after it.</comment><header></header><code></code><inputs><input type="%txt"></input></inputs><script><block s="doDeclareVariables"><list><l>index</l><l>last</l></list></block><block s="doWarp"><script><block s="doSetVar"><l>last</l><l></l></block><block s="doSetVar"><l>index</l><block s="reportStringSize"><block var="sentence"/></block></block><block s="doIf"><block s="reportEquals"><block s="reportStringSize"><block var="sentence"/></block><l>0</l></block><script><block s="doReport"><block s="reportListItem"><l>1</l><block s="reportJoinWords"><list><l>empty </l><l>sentence</l></list></block></block></block></script></block><block s="doUntil"><block s="reportOr"><block s="reportEquals"><block var="index"/><l>1</l></block><block s="reportNot"><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block></block></block><script><block s="doChangeVar"><l>index</l><l>-1</l></block></script></block><block s="doIf"><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block><script><block s="doReport"><block s="reportListItem"><l>1</l><block s="reportJoinWords"><list><l>empty </l><l>sentence</l></list></block></block></block></script></block><block s="doUntil"><block s="reportOr"><block s="reportEquals"><block var="index"/><l>1</l></block><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block></block><script><block s="doSetVar"><l>last</l><block s="reportJoinWords"><list><block s="reportLetter"><block var="index"/><block var="sentence"/></block><block var="last"/></list></block></block><block s="doChangeVar"><l>index</l><l>-1</l></block></script></block><block s="doIf"><block s="reportNot"><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block></block><script><block s="doSetVar"><l>last</l><block s="reportJoinWords"><list><block s="reportLetter"><block var="index"/><block var="sentence"/></block><block var="last"/></list></block></block></script></block><block s="doReport"><block var="last"/></block></script></block></script></block-definition><block-definition s="empty word? %&apos;word&apos;" type="predicate" category="operators"><comment x="0" y="0" w="208" collapsed="false">Takes a text string as input, and reports TRUE if the string has no characters in it of any kind, otherwise false.</comment><header></header><code></code><inputs><input type="%txt"></input></inputs><script><block s="doReport"><block s="reportEquals"><block s="reportStringSize"><block var="word"/></block><l>0</l></block></block></script></block-definition><block-definition s="empty sentence? %&apos;sentence&apos;" type="predicate" category="operators"><comment x="0" y="0" w="221" collapsed="false">Takes a text string as input, and reports TRUE if the input contains no characters other than spaces (therefore, no words when the string is considered as a sentence), otherwise FALSE.</comment><header></header><code></code><inputs><input type="%txt"></input></inputs><script><block s="doDeclareVariables"><list><l>index</l></list></block><block s="doSetVar"><l>index</l><l>1</l></block><block s="doIf"><block s="reportEquals"><block s="reportStringSize"><block var="sentence"/></block><l>0</l></block><script><block s="doReport"><block s="reportTrue"></block></block></script></block><block s="doUntil"><block s="reportOr"><block s="reportEquals"><block var="index"/><block s="reportStringSize"><block var="sentence"/></block></block><block s="reportNot"><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block></block></block><script><block s="doChangeVar"><l>index</l><l>1</l></block></script></block><block s="doReport"><block s="reportEquals"><block s="reportLetter"><block var="index"/><block var="sentence"/></block><l> </l></block></block></script></block-definition><block-definition s="word-&gt;list %&apos;text&apos;" type="reporter" category="operators"><comment w="160" collapsed="false">Takes a text string as input, and reports a list in which each item is a single character from the string.</comment><header></header><code></code><inputs><input type="%s"></input></inputs><script><block s="doDeclareVariables"><list><l>result</l><l>index</l></list></block><block s="doSetVar"><l>result</l><block s="reportNewList"><list></list></block></block><block s="doSetVar"><l>index</l><l>1</l></block><block s="doUntil"><block s="reportGreaterThan"><block var="index"/><block s="reportStringSize"><block var="text"/></block></block><script><block s="doAddToList"><block s="reportLetter"><block var="index"/><block var="text"/></block><block var="result"/></block><block s="doChangeVar"><l>index</l><l>1</l></block></script></block><block s="doReport"><block var="result"/></block></script></block-definition></blocks>