Jelajahi Sumber

HPCC-12810 Include dmetaphone in the OSS version of HPCC Systems

Added to standard library.

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 10 tahun lalu
induk
melakukan
45b214e993

+ 41 - 0
ecllibrary/std/Metaphone.ecl

@@ -0,0 +1,41 @@
+/*##############################################################################
+## HPCC SYSTEMS software Copyright (C) 2015 HPCC Systems.  All rights reserved.
+############################################################################## */
+
+
+EXPORT Metaphone := MODULE
+
+
+IMPORT lib_metaphone;
+
+/**
+ * Returns the primary metaphone value
+ *
+ * @param src           The string whose metphone is to be calculated.
+ * @see                 http://en.wikipedia.org/wiki/Metaphone#Double_Metaphone
+ */
+
+EXPORT String primary(STRING src) :=
+  lib_metaphone.MetaphoneLib.DMetaphone1(src);
+
+/**
+ * Returns the secondary metaphone value
+ *
+ * @param src           The string whose metphone is to be calculated.
+ * @see                 http://en.wikipedia.org/wiki/Metaphone#Double_Metaphone
+ */
+
+EXPORT String secondary(STRING src) :=
+  lib_metaphone.MetaphoneLib.DMetaphone2(src);
+
+/**
+ * Returns the double metaphone value (primary and secondary concatenated
+ *
+ * @param src           The string whose metphone is to be calculated.
+ * @see                 http://en.wikipedia.org/wiki/Metaphone#Double_Metaphone
+ */
+
+EXPORT String double(STRING src) :=
+  lib_metaphone.MetaphoneLib.DMetaphoneBoth(src);
+
+END;

+ 15 - 0
ecllibrary/teststd/Metaphone/TestMetaphone.ecl

@@ -0,0 +1,15 @@
+/*##############################################################################
+## HPCC SYSTEMS software Copyright (C) 2015 HPCC Systems.  All rights reserved.
+############################################################################## */
+IMPORT Std.Metaphone;
+
+EXPORT TestMetaphone := MODULE
+
+  EXPORT TestConst := MODULE
+    EXPORT Test01 := ASSERT(Metaphone.primary('Algernon') = 'ALKRNN');
+    EXPORT Test02 := ASSERT(Metaphone.secondary('Algernon') = 'ALJRNN');
+    EXPORT Test03 := ASSERT(Metaphone.double('Algernon') = 'ALKRNNALJRNN');
+  END;
+
+  EXPORT Main := [EVALUATE(TestConst)];
+END;

+ 0 - 2
plugins/dmetaphone/dmetaphone.cpp

@@ -5,8 +5,6 @@
 #include "dmetaphone.hpp"
 #include "dmetaphone.hpp"
 #include "metaphone.h"
 #include "metaphone.h"
 
 
-static char buildVersion[] = "$HeadURL: https://svn.br.seisint.com/ecl/trunk/ln/plugins/dmetaphone/dmetaphone.cpp $ $Id: dmetaphone.cpp 60037 2010-10-07 13:00:46Z ghalliday $";
-
 #define DMETAPHONE_VERSION "DMETAPHONE 1.1.05"
 #define DMETAPHONE_VERSION "DMETAPHONE 1.1.05"
 
 
 static const char * compatibleVersions[] = {
 static const char * compatibleVersions[] = {

+ 2 - 0
plugins/dmetaphone/metaphone.cpp

@@ -12,6 +12,8 @@
 //
 //
 //  13-Dec-00   mtw Modified to return a number (e.g. 77th returns 77)
 //  13-Dec-00   mtw Modified to return a number (e.g. 77th returns 77)
 //
 //
+// Placed in the public domain by Lawrence Philips
+//
 ////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////
 #include "metaphone.h"
 #include "metaphone.h"
 #include <ctype.h>
 #include <ctype.h>

+ 4 - 4
testing/regress/ecl/metaphone.ecl

@@ -15,7 +15,7 @@
     limitations under the License.
     limitations under the License.
 ############################################################################## */
 ############################################################################## */
 
 
-import lib_metaphone;
+import Std.Metaphone, lib_metaphone;
 
 
 input := DATASET([
 input := DATASET([
   {'Algernon'},
   {'Algernon'},
@@ -36,9 +36,9 @@ END;
 
 
 outrec t(string name) := TRANSFORM
 outrec t(string name) := TRANSFORM
    SELF.name := name;
    SELF.name := name;
-   SELF.d1 := lib_metaphone.MetaphoneLib.DMetaphone1(name);
-   SELF.d2 := lib_metaphone.MetaphoneLib.DMetaphone2(name);
-   SELF.db := lib_metaphone.MetaphoneLib.DMetaphoneBoth(name);
+   SELF.d1 := Metaphone.primary(name);
+   SELF.d2 := Metaphone.secondary(name);
+   SELF.db := Metaphone.double(name);
    SELF.d1_20 := lib_metaphone.MetaphoneLib.DMetaphone1_20(name);
    SELF.d1_20 := lib_metaphone.MetaphoneLib.DMetaphone1_20(name);
    SELF.d2_20 := lib_metaphone.MetaphoneLib.DMetaphone2_20(name);
    SELF.d2_20 := lib_metaphone.MetaphoneLib.DMetaphone2_20(name);
    SELF.db_40  := lib_metaphone.MetaphoneLib.DMetaphoneBoth_40(name);
    SELF.db_40  := lib_metaphone.MetaphoneLib.DMetaphoneBoth_40(name);