09-18-2015 05:46 AM
09-18-2015 06:20 AM
Well, its a bit tricky in code, an example below. Also you run the risk of a few various, extra spaces, dots in words (for example etc., or e.g.). I would prefer to proces the text at source rather than at receipt.
string="Officials said they had no choice after more than 13,000 people entered the country since Hungary fenced off its border with Serbia earlier this week. Many have been taken by bus to reception centres but some say they plan to walk to neighbouring Slovenia? Huge numbers of people heading north from the Mediterranean have created a political crisis in the European Union? Croatian officials said roads leading to the border crossings had also been shut! The crossing on the main road linking Belgrade and Zagreb - at Bajakovo - appeared to be the only one left open";
string="Officials said they had no choice after more than 13,000 people entered the country since Hungary fenced off its border with Serbia earlier this week.";
string="Many have been taken by bus to reception centres but some say they plan to walk to neighbouring Slovenia?";
length sentance $2000;
do i=1 to length(string);
if substr(string,i,1) in ('.','?','!') or i=length(string) then do;
09-18-2015 07:58 AM
09-18-2015 08:31 AM
I would think you could use the SCAN function, where delimiters are period, exclamation and question mark, to extract each sentence one by one. Of course, as noted, this fails if there is a period within a sentence, like "Mr. Jones came home."
09-18-2015 09:00 AM
Indeed, you raise a good point on scan(), it can reduce the code somewhat:
do while(scan(string,i,".?!") ne "");
09-21-2015 04:47 AM - edited 09-21-2015 04:51 AM
09-21-2015 04:56 AM
Yes, that is exactly the same as I posted. Firstly the code is unreadable, need to put things on different lines, use indetation. There are two main differences, firstly, he has assumed that there will be no more than 6 strings per sentance. This may or may not work. Secondly, he uses an array of blocks of text up to a maximum of 6. This may be fine, but I tend to prefer a normalised strcuture (data goes down rather than across) as the code is simplified.