Page 3 of 3

Re: Can a function return two values?

Posted: Wed Jun 30, 2021 7:54 pm
by mwieder

Re: Can a function return two values?

Posted: Thu Jul 01, 2021 8:42 pm
by jiml
Chopping sentences by a word into 'subsentences'.

TheText to be parsed:
I am a Scottish man who lives in Bulgaria who eats cabbages. I see dead people who are freakin' everywhere! Who codes in Java? Do not ask for whom the bell tolls. It tolls for thee.

Code: Select all

put splitSentences(TheText, " who ") into theSplitTextArray
Note spaces around 'who'.

Code: Select all

function splitSentences pText, splitWord
   repeat with s = 1 to the number of sentences of ptext
      get sentence s of ptext
      split it by splitWord
      put it into splitText[s]
   end repeat
    return splitText
end splitSentences

Re: Can a function return two values?

Posted: Thu Jul 01, 2021 8:49 pm
by richmond62
BUT . . .

does the splitWord include the splitWord in the derived 'subsentences?

BECAUSE if one uses itemDelimiter the itemDelimiter gets lost.

Re: Can a function return two values?

Posted: Thu Jul 01, 2021 9:26 pm
by dunbarx
BECAUSE if one uses itemDelimiter the itemDelimiter gets lost.
True. That makes wordOffset more straightforward. It simply identifies a word in the text string, and that value can be either the end or the beginning of each half.

Craig

Re: Can a function return two values?

Posted: Thu Jul 01, 2021 9:54 pm
by SparkOut
It's also true that if you already know the split word, it's pretty simple to

Code: Select all

return splitWord && splitText
(although you'd need to be a bit more sophisticated with a returned array, but hardly taxing)

Re: Can a function return two values?

Posted: Fri Jul 02, 2021 1:12 am
by mwieder
Building a bit on Jim's suggestion, here's a more robust function.
I cheated a bit an included relative pronouns in the subordinating conjunctions list.

Code: Select all

constant kSubordinatingConjunctions = "after,although,as,as if, as long as,as much as,as soon as,as though,because,before,even if,even though,how,if,in as much as,in case,in order that,in order to,in so far as,insofar as,just as,lest,no matter,now that,once,provided,provided that,rather than,since,so that,than,that,though,till,unless,until,when,whenever,where,whereas,wherever,whether,which,whichever,while,who,whoever,whoever,whomever,whosever,why"
function splitSentences pText
   local tSplitText, tText
   
   set the itemdelimiter to comma
   replace "(" with space in pText
   replace ")" with space in pText
   repeat with s = 1 to the number of sentences of pText
      put sentence s of ptext into tText
      repeat for each item tSplitWord in kSubordinatingConjunctions
         if space&tSplitWord&space is in tText then
            replace space&tSplitWord&space with cr&tSplitWord&space in tText
         end if
      end repeat
      split tText by cr
      put tText into tSplitText[s]
   end repeat
   breakpoint
   return tSplitText
end splitSentences
Still will have some problems with constructs like "no matter who..." and "no matter what..."
and will split "as long as" twice (a second time for the "as") but it's another step along the way.

Re: Can a function return two values?

Posted: Fri Jul 02, 2021 4:16 am
by mwieder
A revision does a better job of things.
Still will trip over some simple things like "there it is as you like it" and can't differentiate between subordinating conjunctions and adverbial clauses, but I'm not sure how much that can be automated away.

Code: Select all

constant kSubordinatingConjunctions = "why,whosever,whomever,whoever,whoever,who,while,whichever,which,whether,wherever,whereas,where,whenever,when,until,unless,till,though,that,than,so that,since,rather than,provided that,provided,once,now that,no matter,lest,just as,insofar as,in so far as,in order to,in order that,in case,in as much as,if,how,even though,even if,before,because,as though,as soon as,as much as,as long as,as if,as,although,after"
function splitSentences pText
   local tSplitText, tText
   
   set the itemdelimiter to comma
   replace "(" with space in pText
   replace ")" with space in pText
   replace comma with space in pText
   repeat with s = 1 to the number of sentences of pText
      put sentence s of ptext into tText
      repeat for each item tSplitWord in kSubordinatingConjunctions
         if space&tSplitWord&space is in tText then
            replace space&tSplitWord&space with cr&tSplitWord&numtochar(3) in tText
         end if
      end repeat
      replace numtochar(3) with space in tText
      split tText by cr
      put tText into tSplitText[s]
   end repeat
   return tSplitText
end splitSentences

Re: Can a function return two values?

Posted: Fri Jul 02, 2021 9:19 am
by richmond62
can't differentiate between subordinating conjunctions and adverbial clauses
-
stew.jpg
-
https://youtu.be/sLeG7gxIJx4

SURELY the point of the exercise is to SPLIT a sequence of words in half somewhere and NOT get into
grammatical nit-picking. 8)

Re: Can a function return two values?

Posted: Fri Jul 02, 2021 6:43 pm
by jiml
MarkW wrote:
A revision does a better job of things.
Nice!