Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

this is some text saved to the page


Document properties

<#assign dumy = doc.setTitle("this is the new title")>
<#assign dumy = doc.setDescription("this is the new description")>
<#assign dumy = doc.setFeedItemUrl("https://not-a-real-domain.com")>

Document custom properties

There are now 10 custom document properties that will hold strings of up to about 20,000 characters.  They are named – very imaginatively – custom1, custom2, …, custom10.  These properties are preserved through all workflows.  To access one of these values in a script do:

custom1 = ${doc.custom1}

To assign a value to one of these variables do:

<#assign dumy = doc.setCustom1("uno")>

Note a small detail:  The values you set on custom variables currently “take effect” at the end of script execution. so if you assign a value to one of these properties in a script and then access its value, you won’t get the updated value.  This is a (minor) bug scheduled for the next update.

jSoup

This oddly named package provides easy yet powerful ways to both query and edit HTML documents.  The entire package is exposed so go here for the full documentation.  Here is a simple example of it’s use.

<#assign dom = doc.soup>
<#assign p1 = dom.select("p").first()>
<#assign dumy = p1.attr("style","font-weight:bold")>
<#assign dumy = p1.append("<p>an inserted paragraph</p>")>
<#assign special = dom.select("p#specialp").html("this is the special text we inserted")>
${dom.html()}

The code above gets the jSoup structure into ‘dom’.  We then find the first paragraph, add some styling to it, and then add a new paragraph immediately following.  Finally, we find we replace the contents of the paragraph with id=specialp with the text shown.  The dom variable now contains the original document with content changed and added.  We probably want to keep those changes for use in later workflows, so the final line takes the dom and converts it back to html as the output of this script.

Persona properties

All workflows operate within some Persona.  The properties of that Persona are now available to scripts.  These are currently of somewhat limited use, but in future releases additional properties will be included and supported in the same way as shown in the sample script below.  Note that no updating of these properties is supported – they are read-only.

tone=${persona.tone}<br/>
style=${persona.style}<br/>
viewpoint=${persona.viewpoint}<br/>
mission=${persona.mission}<br/>

Random

Scripts have not previously had a sound random value function.  We now have one.  The randomInt call will provide a value between 0 and the specified limit.  The randomBoolean call returns true/false values.

<#assign n1 = LIB.randomInt(10)>
<#assign b1 = LIB.randomBoolean()>
random num = ${n1}
<#if b1 >
random bool = true
<#else>
random bool = false
</#if>

Similarity

Turkers that copy/paste to create an abstract are a problem!  Likewise those that produce a ‘quote’ that is not really a quote.  This function allows us to detect these bad actors.  The textSimilarity function uses Levenshtein distance to compare two strings.  Their degree of similarity is returned as an integer percentage between 0 and 100 where 100 is an exact match.

Here is a simple example use, but see the Abstract and Author Quote steps in the Reference Persona workflows for real applications.

<#assign dom = doc.soup>
<#assign source = dom.text()>
<#assign abstract = "blah blah blah">
<#assign sim = LIB.textSimilarity(source, abstract)>
similarity=${sim}



  • No labels