カスタム比較の例
カスタム比較を、照合ライブラリに追加できます。プロセッサ(ウィジェット)と同じ方法で、widgets.xml
に追加されます。唯一の制限として、比較には、2つの入力と1つの出力が必要です。出力は、文字列(ブール比較用)または数値(結果バンドを使用する比較用)のいずれかである必要があります。ブール比較は、Trueの場合"T"を、Falseの場合"F"を返します。
各カスタム比較は、識別子タイプ(既存のタイプ(文字列、数値または日付))またはカスタム・タイプ(「カスタム識別子タイプの例」を参照)に関連付けられる必要があります。
比較ガジェットと識別子タイプの関連付け
比較ガジェットを使用するには、特定の識別子タイプと関連付ける必要があります。新しい比較を既存のシステム識別子と関連付ける場合、その名前は次のようになります。
文字列の場合dnm:string
数値の場合dnm:number
日付の場合dnm:date
次のxmlの例は、matchlibrary.xml
に追加された比較の関連付けを表しています。
<identifierComparison> <ident>dnm:string</ident> <gadget>dnm:exactstringmatch</gadget> </identifierComparison>
これにより、識別子"dnm:string
"が比較"dnm:exactstringmatch
"と関連付けられます。
比較用のデフォルト結果バンドの設定
次のxmlは、文字列編集距離の比較用にmatchlibrary.xml
に追加された比較デフォルト結果バンドを表しています。
<comparisonReturn> <widgetId>dnm:stringeditdistance</widgetId> <resultBand name="exact" label="Exact Match">0</resultBand> <resultBand name="onetypo" label="One Typo">1</resultBand> <resultBand name="twotypos" label="Two Typos">2</resultBand> <resultBand name="threetypos" label="Three Typos">3</resultBand> </comparisonReturn>
完全な例
次の例のファイルは、JARファイルにパッケージ化でき、照合ライブラリへのカスタム「文字置換の一致」比較の追加に使用できます。「文字置換の一致」比較は、文字置換が発生した文字列を照合します。たとえば、値'Michael'と'Micheal'を比較する際、1回の置換がカウントされ、「最大許容置換」オプションが1以上に設定されている場合、2つの値が照合されます。
例2-1 matchlibrary.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- Custom Match Library Extension Copyright 2008 Oracle Ltd. All rights reserved. --> <matchLibrary> <identifierComparison> <ident>dnm:string</ident> <gadget>dn:characterTranspositionMatch</gadget> </identifierComparison> </matchLibrary>
例2-2 widgets.xml
<?xml version="1.0" encoding="UTF-8"?> <widgets> <comment>Oracle Match example script widgets</comment> <copyright>Copyright 2008 Oracle Ltd. All rights reserved.</copyright> <widget id="dn:characterTranspositionMatch" class="com.datanomic.director.match.library.util.JavaScriptGadget"> <guidata> <label>%characterTranspositionMatch.gadget</label> <group>compare</group> <icon>script</icon> </guidata> <!-- inputs --> <inputs> <input id="1" type="string" maxattributes="1"> <guidata><label>label1</label></guidata> </input> <input id="2" type="string" maxattributes="1"> <guidata><label>label1</label></guidata> </input> </inputs> <!-- outputs --> <outputs cardinality="1:1"> <output id="1" type="string" name="result"> <guidata><label>resultlabel</label></guidata> </output> </outputs> <properties> <property name="matchNoDataPairs" type="boolean" required="true"> <guidata> <label>%characterTranspositionMatch.property.matchNoDataPairs.label</label> </guidata> <default>false</default> </property> <property name="ignoreCase" type="boolean" required="true"> <guidata> <label>%characterTranspositionMatch.property.ignoreCase.label</label> </guidata> <default>true</default> </property> <property name="startsWith" type="boolean" required="true"> <guidata> <label>%characterTranspositionMatch.property.startsWith.label</label> </guidata> <default>false</default> </property> <property name="maxAllowedTranspositions" type="number" required="true"> <guidata> <label>%characterTranspositionMatch.property.maxAllowedTranspositions.label</label> </guidata> <default>1</default> </property> </properties> <parameters> <parameter name="script"> <![CDATA[ function S(s) { return (s == null) ? "" : s; } function doit() { // no data pairs if (S(input1) == "" | S(input2) == "") { if (matchNoDataPairs) output1 = "T"; else output1 = "F"; return; } if (!startsWith) { if (input1.length != input2.length) { output1 = "F"; return; } } var transpositions = 0; var longword = input1.length > input2.length ? input1 : input2; var shortword = input1.length > input2.length ? input2 : input1; if (ignoreCase) { // convert to uppercase longword = longword.toUpperCase(); shortword = shortword.toUpperCase(); } for (var i = 0; i < shortword.length; i++) { if (shortword[i] != longword[i]) { // are we at the end of the string? if (i == shortword.length - 1) { output1 = "F"; return; } // not a transposition match? if (shortword[i] != longword[i + 1]) { output1 = "F"; return; } // compare the next character if (shortword[i + 1] != longword[i]) { output1 = "F"; return; } transpositions++; // too many transpositions? if (transpositions > maxAllowedTranspositions) { output1 = "F"; return; } // skip over the characters i++; } } output1 = "T"; } ]]> </parameter> <parameter name="function">doit</parameter> </parameters> </widget> </widgets>
例2-3 matchlibrary.properties
[This file was not required in this case as the comparison does not support result bands, and does not require new identifiers.]
例2-4 widgets.properties
characterTranspositionMatch.gadget = Character Transposition Match characterTranspositionMatch.property.matchNoDataPairs.label = Match No Data pairs? characterTranspositionMatch.property.ignoreCase.label = Ignore case? characterTranspositionMatch.property.startsWith.label = Starts with? characterTranspositionMatch.property.maxAllowedTranspositions.label = Maximum allowed transpositions
例2-5 version.properties
name=Character Transposition Match version=v8.1.3.(175) title=Character Transposition Match type=GADGET