カスタム比較をマッチ・ライブラリに追加できます。これらは、プロセッサ(ウィジェット)と同じ方法で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の比較では、単一の転置がカウントされるため、「Maximum allows transpositions」オプションが1以上に設定されている場合、2つの値はマッチします。
<?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>
<?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>
[比較では結果バンドはサポートされず、新しい識別子は不要であるため、このファイルはこのケースでは必要ありませんでした。]
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
name=Character Transposition Match
version=v8.1.3.(175)
title=Character Transposition Match
type=GADGET
Oracle (R) Enterprise Data Qualityオンライン・ヘルプ バージョン8.1
Copyright (C) 2006,2011 Oracle and/or its affiliates.All rights reserved.