Source: site.view [edit]
Function name: translateToFrench
Arguments: term
Description: A command to translate a term to French
Page type: webl
Render function:   tlidRender
Module: global

Page source:

var P;
var context;

context = NLUtil_InitContext();

//|| go to http://www.wordreference.com
context = NLUtil_GetUrl(context, "http://www.wordreference.com", nil, nil);
P = NLUtil_GetContext(context, `P`);

//|| find all forms that contain "Word:"
P = NLUtil_GetContext(context,`P`);
context = NLUtil_SetContext(context,`form`, Elem(P, `form`)  contain Pat(P, `(?i)` + `Word:`));

//|| fill in tranword with the term
context = NLUtil_SetField(context, "tranword", term);

//|| field dict is enfr
context = NLUtil_SetField(context, "dict", `enfr`);

//|| submit the form
context = NLUtil_submitForm(context);
P = NLUtil_GetContext(context, `P`);

//|| find all rows that come after "Principal Translations"
P = NLUtil_GetContext(context,`P`);
context = NLUtil_SetContext(context,`tr`, Elem(P, `tr`)  after Pat(P, `(?i)` + `Principal Translations`));


//|| select rows that come before "Additional Translations"
context = NLUtil_SetContext(context,`tr`, NLUtil_GetContext(context, `tr`)  before Pat(P, `(?i)` + `Additional Translations`));

//|| select all except for the last one
context = NLUtil_SetContext(context,NLUtil_LastType(context), Select(NLUtil_LastSet(context),0,Size(NLUtil_LastSet(context)) - 1));

if Size(OPTIONALARGS) == 0 then
   NLUtil_LastSet(context);
else
   context;
end;