Create a Cognate Query Expression Node


Namespace: NetricsServerInterface
Assembly: NetricsServerInterface (in NetricsServerInterface.dll)

Syntax

Visual Basic (Declaration)
Public Shared Function Cognate( _ 
   ByVal qstrs As String(),  _ 
   ByVal fldnames As String(),  _ 
   ByVal fldweights As Double(),  _ 
   ByVal noncogwgt As Double _ 
) As NetricsQuery
C#
public static NetricsQuery Cognate(
   string[] qstrs,
   string[] fldnames,
   double[] fldweights,
   double noncogwgt
)
C++
public:
 static NetricsQuery Cognate(
   array<String>^ qstrs,
   array<String>^ fldnames,
   array<double>^ fldweights,
   double noncogwgt
)
J#
public static NetricsQuery Cognate(
   string[] qstrs,
   string[] fldnames,
   double[] fldweights,
   double noncogwgt
)
JScript
public static  function Cognate(
   qstrs : String[],
   fldnames : String[],
   fldweights : double[],
   noncogwgt : double
) : NetricsQuery

Parameters

qstrs
the list of query strings
fldnames
list of fields to query
fldweights
list of weights for field
noncogwgt
weight for diagonal fields in the query

Remarks

A cognate query is a more complicated version of a Simple query. It uses the same string comparison algorithm but performs the match with multiple query strings. For instance, a first and last name can be searched against the first and last name fields of the database. This aids in finding transposed fields (where a first name occurs in the last name field or vice versa). The length of the qstrs array must always equal the length of the fldnames array. The fldweights array should also be that length if is used. The noncogwgt is a penalty applied to diagonal (non-cognate) field matches. Scores for non-cognate matches are reduced by this factor. For example, if noncogwgt is set to 0.8, the score of a first name exact match in the last name field would be reduced to 0.8.

Example

This sample shows how to perform a search of an ibi™ Patterns - Search table using a Cognate query.

 Copy Code
            using System;
            using NetricsServerInterface;
            class MyClass
            {
                private static NetricsServerInterface.NetricsServerInterface si = null;
                public static void Main()
                {
                    try
                    {
                        String host = "localhost";
                        int port = 5051;
                        si = new NetricsServerInterface.NetricsServerInterface(host, port);
                        // Query array will contain the query strings or tokens to be matched against
                        String [] queryStringArray = {"brown", "dennis"};
                        // Table is the ibi™ Patterns - Search table to be search/matched against query
                        String table = "names";
                        // FieldNames contain the fields within the table to be searhed/matched against.
                        // If fieldNames is set to null then all fields will be searched/matched against
                        String[] fieldNames = { "last", "first" };
                        // FieldWeights is an array that must be the same length as fields and contain the
                        // weights (0.0 - 1.0) of each field that contribute to the overall score of the result
                        double[] fieldWeights = { 1.0, .5 };
                        // Create NetricsSearchOpts object using the defaults
                        NetricsSearchOpts opts = new NetricsSearchOpts();
                        // Create the NetricsSearchCfg pointing to the table to be searched/matched against
                        NetricsSearchCfg tblCfg = new NetricsSearchCfg(table);
                        // Add a Cognate query to the NetricsSearchCfg using the query strings, fieldNames,
                        // fieldWeights and a cognateweight which is used to lower the score of miss fielded
                        // records.  In this case "last"="brown" and "first"="dennis" is an exact match
                        // with a similarity score of 1, while "last"="dennis" and "first"="brown" will be a 
                        // match with a similarity score of .8
                        // Use a cognate weight of .8
                        double cognateweight = .8;
                        tblCfg.setNetricsQuery(NetricsQuery.Cognate(queryStringArray, fieldNames, fieldWeights, cognateweight));
                        // Perform the search/match using the NetricsSearchCfg and NetricsSearchOpts
                        NetricsSearchResponse resp = si.search(tblCfg, opts);
                        String s = "";
                        // Get the results of the search/match
                        NetricsSearchResult[] res = resp.getSearchResults();
                        // Create viables for result processing
                        String[] xfieldNames;
                        String[] xfields;
                        // Iterate through the result records
                        for (int i = 0; i < res.Length; i++)
                        {
                            // Get the fieldNames in the result record
                            xfieldNames = res[i].getFieldNames();
                            // Get the data for each fieldName in result record
                            xfields = res[i].getFields();
                            // Get the score for this result record
                            double score = res[i].getMatchScore();
                            // Build the printline for the result record
                            s = s + "Rank=" + i + ", Score=" + score.ToString();
                            for (int x = 0; x < xfields.Length; x++)
                            {
                                s = s + ", " + xfieldNames[x] + "=" + xfields[x];
                            }
                            s = s + "\n";
                        }
                        Console.WriteLine(s);
                    }
                    catch (NetricsException e)
                    {
                        Console.Write(e.getErrorDescription() + "\n");
                    }
                }
            } 
            

See Also