Jump to content
daanvdn

recursion problem (a.o.)

Recommended Posts

daanvdn

Hi,

 

I'm completely new to wrting recursive CFs. I've been trying to write a CF to convert line a to line b

 

a) Vf-Edat-SBJ-Egen-AttribNom-Aneg-AttribPron-Amod-Anrede

 

b) Vf-E-SBJ-E-Attrib-A-Attrib-A-Anrede

 

The dash "-" separates sentences constituents.

"Vf", "SBJ" and "Anrede" should remain the same.

A constituent containing the pattern Attrib* should become "Attrib" (e.g.AttribNom, AttribPron)

Constituents like "Edat" or "Egen" should become "E" (next to dat and gen, there are a dozen other suffixes)

Constituents like "Aneg" or "Amod" should become "A" (next to neg and mod there are 30 other suffixes).

 

I've come up with the following CF but it always results in a question mark (so a.o. there must be something wrong with the recursion):

Let ([
t 	=	Substitute ( text ; "-";" "); //remove all dashes from the text
kons  	=	LeftWords ( t ; 1);
                                                     //determine what a constituent should converted into 
konsalg	=	Case                         
                      (
		PatternCount (  kons; "Attrib")  ≠ 0;"Attrib";
		PatternCount (  kons; "App")  ≠ 0;"App";
		kons = "Anrede";"Anrede";
		Left ( kons ; 1) = "E";"E";
		 Left ( kons ; 1) = "A";"A";
		kons
		)

];

If 
(
WordCount ( t) > 1;	
Substitute ( text; kons; konsalg) & KonsKonv (Substitute ( text; kons; konsalg))

)
)	

 

Does anybody have any suggestion what I'm doing wrong?

Thanks

 

Daan

Share this post


Link to post
Share on other sites
MartinOva

Hello Daan!

 

First thing in recursion is to take care of recursion. ie you must call the recursive function itself by a calculated value in the definition of the recursive function (RED) . And the second thing is to take care that the recursion ends (BLUE) when there is nothing to recurr.

 

Third problem was that you substituted kons already in konsalg calc. There are no need to to the substitution another time (GREEN)

 

My solution to your problem is as follows:

 

=============================

Let ([

t = Substitute ( text ; "-";" "); //remove all dashes from the text

kons = LeftWords ( t ; 1);

//determine what a constituent should converted into

konsalg = Case

(

PatternCount ( kons; "Attrib") ≠ 0;"Attrib";

PatternCount ( kons; "App") ≠ 0;"App";

kons = "Anrede";"Anrede";

Left ( kons ; 1) = "E";"E";

Left ( kons ; 1) = "A";"A";

kons

) ;

 

wc = WordCount ( t) ;

remain = RightWords (t ; wc-1) //pass the remains of the text to recursion

 

];

 

If

(

wc > 1;

konsalg & "-" & KonsKonv (remain) ; konsalg

 

)

)

====================================

 

Hope that helps

 

Martti

Share this post


Link to post
Share on other sites
daanvdn

Hi MartinOva,

 

Thank you very much for your reply, it works, great!

I've been looking for some info on recursive functions on the web (fm-manuals don't seem to waste much time on this subject), but so far I haven't found any detailed descriptions. Should you have any suggestions ....

 

Thanks again!!!

 

 

Cheers,

 

Daan Ghent Belgium

Share this post


Link to post
Share on other sites
Josh Ormond
Hi MartinOva,

 

Thank you very much for your reply, it works, great!

I've been looking for some info on recursive functions on the web (fm-manuals don't seem to waste much time on this subject), but so far I haven't found any detailed descriptions. Should you have any suggestions ....

 

Thanks again!!!

 

 

Cheers,

 

Daan Ghent Belgium

There is one entry on here for Recursive Functions that includes a White Paper and demo file.

Share this post


Link to post
Share on other sites
This thread is quite old. Please start a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




×
×
  • Create New...

Important Information

Terms of Use