メイン コンテンツをスキップする 補完的コンテンツへスキップ

カスタムマッチングアルゴリズムの作成

tRecordMatchingコンポーネントを使用すると、必要な結果を得るためにユーザー定義のマッチングアルゴリズムを使用できます。

カスタムマッチングアルゴリズムは手動で書き込み、.jarファイル (Javaアーカイブ)に保管されます。 Talend では.jarファイルのサンプルを提供しており、これをベースにご自身のファイルを簡単に作成できます。

手順

  1. Eclipseでは、svnからtest.mydistanceプロジェクトをご覧ください。
  2. このプロジェクトでは、MyDistance.Java: https://github.com/Talend/tdq-studio-se/tree/master/sample/test.mydistance/src/main/java/org/talend/mydistanceという名前のJavaクラスに移動します。
  3. 以下のコードを含むこのファイルを開きます:
    package org.talend.mydistance;
    
    import org.talend.dataquality.record.linkage.attribute.AbstractAttributeMatcher;
    import org.talend.dataquality.record.linkage.constant.AttributeMatcherType;
    
    /**
     * @author scorreia
     * 
     * Example of Matching distance.
     */
    public class MyDistance extends AbstractAttributeMatcher {
    
        /*
         * (non-Javadoc)
         * 
         * @see org.talend.dataquality.record.linkage.attribute.IAttributeMatcher#getMatchType()
         */
        @Override
        public AttributeMatcherType getMatchType() {
            // a custom implementation should return this type AttributeMatcherType.custom
            return AttributeMatcherType.CUSTOM;
        }
    
        /*
         * (non-Javadoc)
         * 
         * @see org.talend.dataquality.record.linkage.attribute.IAttributeMatcher#getMatchingWeight(java.lang.String,
         * java.lang.String)
         */
        @Override
        public double getWeight(String arg0, String arg1) {
            // Here goes the custom implementation of the matching distance between the two given strings.
            // the algorithm should return a value between 0 and 1.
    
            // in this example, we consider that 2 strings match if their first 4 characters are identical
            // the arguments are not null (the check for nullity is done by the caller)
            int MAX_CHAR = 4;
            final int max = Math.min(MAX_CHAR, Math.min(arg0.length(), arg1.length()));
            int nbIdenticalChar = 0;
            for (; nbIdenticalChar < max; nbIdenticalChar++) {
                if (arg0.charAt(nbIdenticalChar) != arg1.charAt(nbIdenticalChar)) {
                    break;
                }
            }
            if (arg0.length() < MAX_CHAR && arg1.length() < MAX_CHAR) {
                MAX_CHAR = Math.max(arg0.length(), arg1.length());
            }
            return (nbIdenticalChar) / ((double) MAX_CHAR);
    }
  4. このファイルに、デフォルト名を置き換えるために作成するカスタムアルゴリズムのクラス名を入力します。
    デフォルト名はMyDistanceで、次の行にあります: public class MyDistance implements IAttributeMatcher
  5. ファイル内のデフォルトのアルゴリズムが存在する場所で、デフォルトのアルゴリズムを置き換えるために作成するアルゴリズムを入力します。
    デフォルトのアルゴリズムは以下のとおりです:
            int MAX_CHAR = 4;
            final int max = Math.min(MAX_CHAR, Math.min(arg0.length(), arg1.length()));
            int nbIdenticalChar = 0;
            for (; nbIdenticalChar < max; nbIdenticalChar++) {
                if (arg0.charAt(nbIdenticalChar) != arg1.charAt(nbIdenticalChar)) {
                    break;
                }
            }
            if (arg0.length() < MAX_CHAR && arg1.length() < MAX_CHAR) {
                MAX_CHAR = Math.max(arg0.length(), arg1.length());
            }
            return (nbIdenticalChar) / ((double) MAX_CHAR);
    
  6. 変更を保存します。
  7. Eclipseを使用して、この新しい.jarファイルをエクスポートします。

タスクの結果

これにより、このユーザー定義アルゴリズムはtRecordMatchingコンポーネントで使用できる状態になります。

このページは役に立ちましたか?

このページまたはコンテンツに、タイポ、ステップの省略、技術的エラーなどの問題が見つかった場合は、お知らせください。改善に役立たせていただきます。