My name is Ito and I work for ATL. We have now released RedPen version 1.7. In this version, properties can now be passed to the functions implemented in JavaScript (Validators). The properties are used for controlling the behavior of these functions. This version also includes a change that allows you to specify a configuration file for the RedPen server. We have also spent a lot of time making a large number of fixes and enhancements to RedPen’s functionality. Below I shall provide information about each topic.
Pass Properties to JavaScript Extensions
From version 1.7 onward, you can pass on properties to the functions implemented in JavaScript. Passing properties allows you to control the behavior of these functions. The properties are declared in the configuration block of the JavaScript functions. In the examples below, the property max_char_num has been set to 5.
1 2 3 |
<validator name="JavaScript"> <property name="max_char_num" value="5" /> </validator> |
The properties set in the JavaScript block can be read from JavaScript extensions. The JavaScript extension below reads the value of the max_char_num property using the getInt method.
1 2 3 4 5 6 7 8 9 10 |
function validateSentence(sentence) { var content = sentence.getContent().split(" "); var limit= getInt("max_char_num"); for(var i = 0; i<content.length;i++){ if(content[i].length >= limit){ addError("word [" + content[i] +"] is too long. length: " + content[i].length, sentence); } } } |
There are different methods available for reading properties of each datatype. The table below shows a list of the supported get methods.
Method name | Type |
---|---|
getInt | Int |
getFloat | Float |
getString | String |
getBoolean | Boolean |
getSet | Set |
Future Development: JavaScript Extensions
If you compare JavaScript extensions with extensions written in Java, you will notice that you can do less with JavaScript. For example, with the current JavaScript extensions, you cannot send property settings to just one function. In the future, we plan to make changes so that the functions implemented in JavaScript are treated as single functions just like in Java. Also, although RedPen’s core functionality is currently implemented in Java, in the future, we are planning to start replacing some of that implemented functionality using JavaScript.
Specify a Configuration File for the RedPen Server
When starting the RedPen server, you can now specify the default configuration file that it should use. To specify a configuration file, you need to edit the server startup script redpen-server (redpen-server.bat on Windows). The script has a commented-out line that refers to the REDPEN_CONF_FILE. Edit this line to specify the path to the configuration file. Please note that if the configuration file or the resources (JavaScript extensions and dictionary) are not under REDPEN_HOME (RedPen’s installation directory), the server will be unable to read in the file. After amending the RedPen server’s startup script (redpen-server), start the server. The content of the specified configuration file will then be used as the default configuration.
Functionality Improvements
In v1.7, we have also spent a lot of time making a large number of fixes and enhancements to RedPen’s functionality. Many of the fixes made are based on comments that we have received from RedPen users. In addition, we have also added support for the two new functions below.
Detection of Successive Sentences (SuccessiveSentence)
When you write text using an editor, copied sentences can sometimes be pasted twice by mistake. This is why we have implemented a SuccessiveSentence function. SuccessiveSentence outputs an error if the same sentence is detected twice in succession. For example, if the input text included the paragraph below, this function would return an error.
1 |
いつも感じるのです。ポケモン Go はおもしろい。ポケモン Go はおもしろい。気がつくとレベル 20 になっていました。 |
The paragraph contains the same sentence “Pokemon Go is fun” twice in succession.
Detection of Multiple Use of the Conjunctive Particle “Ga” (DoubledConjunctiveParticleGa)
DoubledConjunctiveParticleGa returns an error if the conjunctive particle “ga” is used twice or more within the same sentence. This functionality has been ported for RedPen from the implementation of the textlint plugin textlint-rule-no-doubled-conjunctive-particle-ga, written by Mr. Takahashi from Tatsu-zine Publishing.
For example, DoubledConjunctiveParticleGa would return an error for the following sentence.
1 |
今日は早朝から出発したが、定刻通りではなかったが、無事会場に到着した。 |
Summary
This document outlines the functionality of RedPen v1.7. As mentioned above, going forward, we plan to continue developments to support the creation of new JavaScript functionality.