Esempio n. 1
0
        public void mReadMap(RecordSetMD aRecordSetMD, JniPMMLItem aJniPMML, PrintWriter pw, Boolean bFillDictionaryNames)
        //throws com.WDataSci.WDS.WDSException
        {
            try {
                int i  = -1;
                int ii = -1;
                int j  = -1;
                int jj = -1;
                int k  = -1;
                int kk = -1;


                //Java Boolean bUsingPMML = (aJniPMML != null && aJniPMML.PMMLMatter.Doc != null);
                //C#
                Boolean bUsingPMML = false;

                String[] lFieldStringNames = null;
                int      nDataFieldNames   = 0;
                if (bUsingPMML)
                {
                    lFieldStringNames = aJniPMML.PMMLDataFieldStringNames();
                    nDataFieldNames   = lFieldStringNames.Length;
                }

                if (pw != null)
                {
                    pw.printf("In RecordSetMD constructor\n");
                }
                if (pw != null)
                {
                    pw.flush();
                }

                //point to file or memory
                DBB buffer = this.Header.Buffer;
                buffer.position(0, 0, 0);

                try {
                    //get compound dataset information

                    long nColumns = buffer.nRecords;
                    long nBlockMaxStringByteLength = this.Header.MaxStringByteLength;

                    int nBlockCoreColumnSize = (int)(buffer.nRecordFLenBytes);
                    int nBlockAllocatedSize  = (int)(buffer.nDBBRequiredBytes);

                    if (nBlockAllocatedSize > this.Header.Buffer.Length)
                    {
                        throw new com.WDataSci.WDS.WDSException("Error, HeaderBuffer capacity, " + this.Header.Buffer.Length
                                                                + ", is less then what should be BlockAllocatedSize, " + nBlockAllocatedSize
                                                                );
                    }

                    int nBlockCoreSize = (int)(buffer.nDBBLeadingBytes + buffer.nDBBFLenBytes);

                    if (pw != null)
                    {
                        pw.printf("In RecordSetMD constructor, nColumns=%d\n", nColumns);
                    }
                    if (pw != null)
                    {
                        pw.flush();
                    }

                    byte[] namebuffer = new byte[(int)(nBlockMaxStringByteLength)];


                    //iterate through columns (dataset members)

                    aRecordSetMD.Column = new FieldMD[(int)(nColumns)];

                    int bptr = 0;

                    for (ii = 0; ii < nColumns; ii++, bptr += (int)nBlockCoreColumnSize)
                    {
                        buffer.position(buffer.ptr, bptr, buffer.vlenptr);

                        aRecordSetMD.Column[ii] = new FieldMD();
                        FieldMD col = aRecordSetMD.Column[ii];

                        //the first two fields are always names and taken to be variable length
                        col.Name = buffer.GetLayerVLenString(1, nBlockMaxStringByteLength);

                        //Check for PMML DataFieldName map
                        //If not mapped externally, the next VLenString pointer will be 0 and will come back as empty
                        String tmpname = buffer.GetLayerVLenString(1, nBlockMaxStringByteLength);

                        //Search for PMML DataFieldName map, take input supplied map first, then the usual search

                        /* Java >>> *
                         * Boolean found = false;
                         * if ( bUsingPMML && tmpname.length() > 0 ) {
                         *  for (j = 0; !found && j < nDataFieldNames; j++) {
                         *      if ( tmpname.equals(lFieldStringNames[j]) ) {
                         *          col.MapToMapKey(lFieldStringNames[j]);
                         *          found = true;
                         *          break;
                         *      }
                         *  }
                         * }
                         * if ( bUsingPMML && !found ) {
                         *  for (j = 0; !found && j < nDataFieldNames; j++) {
                         *      if ( col.Name.equals(lFieldStringNames[j]) ) {
                         *          col.MapToMapKey(lFieldNames[j]);
                         *          found = true;
                         *          break;
                         *      }
                         *  }
                         * }
                         * /* <<< Java */
                        if (!bUsingPMML && bFillDictionaryNames)
                        {
                            col.MapToMapKey(col.Name);
                        }

                        //Java col.DTyp = FieldMDEnums.eDTyp.FromInt(buffer.GetLayerInt(1));
                        //C#
                        col.DTyp = FieldMDExt.eDTyp_FromInt((int)buffer.GetLayerInt(1));

                        //See notes above on Date and DateTime types
                        //Since the header block is being passed in, Date and DateTime types are provided.

                        col.ByteMemLength = (long)buffer.GetLayerLong(1);
                        col.ByteMaxLength = (long)buffer.GetLayerLong(1);
                        if (col.DTyp.bIn(FieldMDEnums.eDTyp.VLS, FieldMDEnums.eDTyp.Str))
                        {
                            col.StringMaxLength = (int)(col.ByteMaxLength / 2);
                        }

                        //no longer using the last byte for bIsMappedToPMMLFieldName, so there is filler space at the end
                    }
                }
                catch (Exception e) {
                    throw new com.WDataSci.WDS.WDSException("Error in RecordSetMD processing of Header DBB:", e);
                }

                if (pw != null)
                {
                    pw.printf("leaving RecordSetMD constructor\n");
                }
                if (pw != null)
                {
                    pw.flush();
                }
            }
            catch (Exception e) {
                throw new com.WDataSci.WDS.WDSException("Error in ProcessInputMapFor", e);
            }
        }
Esempio n. 2
0
        public void mReadMapFor(RecordSetMD aRecordSetMD, JniPMMLItem aJniPMML, PrintWriter pw, Boolean bFillDictionaryNames)
        //throws com.WDataSci.WDS.WDSException
        {
            try {
                int ii = -1;
                int j  = -1;
                int k  = -1;


                //are we using a JniPMML object (as when called from C# and does it have PMMLMatter
                Boolean bUsingJniPMML = (aJniPMML != null);
                //Java Boolean bCheckingAgainstPMML = (aJniPMML != null && aJniPMML.PMMLMatter.Doc != null);
                //C#
                Boolean bCheckingAgainstPMML = false;

                //Java org.dmg.pmml.DataField[] lDataFields = null;
                String[] lFieldStringNames = null;
                int      nDataFieldNames   = 0;

                if (bCheckingAgainstPMML)
                {
                    /* Java >>> *
                     * lDataFields = aJniPMML.PMMLDataFields();
                     * nDataFieldNames = lDataFields.length;
                     * lFieldStringNames = new String[nDataFieldNames];
                     * for (i = 0; i < nDataFieldNames; i++)
                     * lFieldStringNames[i] = lDataFields[i].getName().getValue();
                     * /* <<< Java */
                }


                String aPathAndName = null;
                aPathAndName = com.WDataSci.WDS.Util.PathAndName(this.Path, this.FileName);

                /* Java >>> *
                 * this.__CSVParser = new CSVParser(new FileReader(aPathAndName), CSVFormat.EXCEL);
                 * this.__CSVParserIterator = this.__CSVParser.iterator();
                 * CSVRecord inputLine = this.__CSVParserIterator.next();
                 * /* <<< Java */
                /* C# >>> */
                this.__StreamReader = new StreamReader(aPathAndName);
                this.__CSV          = new CsvParser(this.__StreamReader);
                String[] inputLine = this.__CSV.Read();
                /* <<< C# */

                //Java int xnlLength = inputLine.size();
                //C#
                int xnlLength = inputLine.Length;

                aRecordSetMD.Column = new FieldMD[xnlLength];

                //for when the length is packed into the XSD type for limiting strings
                int[] typl = new int[1];
                for (ii = 0; ii < xnlLength; ii++)
                {
                    aRecordSetMD.Column[ii] = new FieldMD();
                    FieldMD cm = aRecordSetMD.Column[ii];

                    //Java cm.Name = inputLine.get(ii);
                    //C#
                    cm.Name = inputLine[ii];

                    Boolean found = false;

                    if (bCheckingAgainstPMML)
                    {
                        //Search for PMML DataFieldName map
                        for (j = 0; !found && j < nDataFieldNames; j++)
                        {
                            if (cm.Name.equals(lFieldStringNames[j]))
                            {
                                found = true;
                                cm.MapToMapKey(lFieldStringNames[j]);
                                break;
                            }
                        }

                        /* Java >>> *
                         * // if found in PMML, check for PMML DataType
                         *  if ( found ) {
                         *      org.dmg.pmml.DataType ofdtyp = lDataFields[j].getDataType();
                         *      switch ( ofdtyp ) {
                         *          case FLOAT:
                         *          case DOUBLE:
                         *              cm.DTyp = FieldMDEnums.eDTyp.Dbl;
                         *              break;
                         *          case INTEGER:
                         *              if ( cm.Name.endsWith("ID") )
                         *                  cm.DTyp = FieldMDEnums.eDTyp.Lng;
                         *              else
                         *                  cm.DTyp = FieldMDEnums.eDTyp.Int;
                         *              break;
                         *          case STRING:
                         *              cm.DTyp = FieldMDEnums.eDTyp.VLS;
                         *              break;
                         *          case DATE:
                         *              cm.DTyp = FieldMDEnums.eDTyp.Dte;
                         *              break;
                         *          case DATE_TIME:
                         *          case TIME:
                         *              cm.DTyp = FieldMDEnums.eDTyp.DTm;
                         *              break;
                         *          case BOOLEAN:
                         *              cm.DTyp = FieldMDEnums.eDTyp.Bln;
                         *              break;
                         *          case DATE_DAYS_SINCE_0:
                         *          case DATE_DAYS_SINCE_1960:
                         *          case DATE_DAYS_SINCE_1970:
                         *          case DATE_DAYS_SINCE_1980:
                         *          case TIME_SECONDS:
                         *          case DATE_TIME_SECONDS_SINCE_0:
                         *          case DATE_TIME_SECONDS_SINCE_1960:
                         *          case DATE_TIME_SECONDS_SINCE_1970:
                         *          case DATE_TIME_SECONDS_SINCE_1980:
                         *          default:
                         *              cm.DTyp = FieldMDEnums.eDTyp.Int;
                         *              break;
                         *      }
                         *  }
                         * /* <<< Java */
                    }

                    if (!found)
                    {
                        if (bFillDictionaryNames)
                        {
                            cm.MapToMapKey(cm.Name);
                        }

                        String s = cm.Name;

                        String cls     = null;
                        String mod     = null;
                        String rep     = null;
                        String postmod = null;

                        //We are assuming a modified three part naming convention
                        //The core three part naming convention is assumed to be CamelCase and of the form
                        //   Class[Modifier]Representation
                        //The Representation defines the data type (we will assume all strings are VLen).
                        //
                        //We allow a _PostModifier (preceded by an underscore).  This implies that all
                        //fields with a root name are related and we are not embedding obfuscation.
                        //
                        //Examples based on consumer loan data are:
                        //   Long form                     Short form
                        //   PrincipalBalance              PrinBal
                        //   PaymentAmount                 PmtAmt
                        //   PaymentPrincipalAmount        PmtPrinAmt
                        //   PaymentPrincipalAmount_Lag1   PmtPrinAmt_Lag1
                        //
                        //See documentation on WDataSci naming conventions.

                        k = s.lastIndexOf("_");
                        if (k > 0)
                        {
                            postmod = s.substring(k + 1);
                            s       = s.substring(0, k - 1);
                        }
                        String sl = s.toLowerCase();

                        //recognize Date and DateTime first
                        if (s.endsWith("Date"))
                        {
                            cm.DTyp = FieldMDEnums.eDTyp.Dte;
                        }
                        else if (s.endsWith("Time"))
                        {
                            cm.DTyp = FieldMDEnums.eDTyp.DTm;
                        }
                        //longs
                        else if (cm.Name.endsWith("ID"))
                        {
                            cm.DTyp = FieldMDEnums.eDTyp.Lng;
                        }
                        else if (cm.Name.endsWith("Nbr") && (sl.startsWith("acc") || sl.startsWith("loan")))
                        {
                            cm.DTyp = FieldMDEnums.eDTyp.Lng;
                        }
                        else if (cm.Name.endsWith("Nbr"))
                        {
                            cm.DTyp = FieldMDEnums.eDTyp.Int;
                        }
                        else if (cm.Name.endsWith("Count"))
                        {
                            cm.DTyp = FieldMDEnums.eDTyp.Int;
                        }
                        else if (cm.Name.endsWith("Status"))
                        {
                            cm.DTyp = FieldMDEnums.eDTyp.VLS;
                        }
                        else if (cm.Name.length() > 3 &&
                                 bIn(cm.Name.substring(cm.Name.length() - 3)
                                     , "Bal", "Amt", "Pct"))
                        {
                            cm.DTyp = FieldMDEnums.eDTyp.Dbl;
                        }
                        else if (cm.Name.length() > 3 &&
                                 bIn(cm.Name.substring(cm.Name.length() - 3)
                                     , "Mos"))
                        {
                            cm.DTyp = FieldMDEnums.eDTyp.Int;
                        }
                        else if (cm.Name.length() > 4 &&
                                 bIn(cm.Name.substring(cm.Name.length() - 4)
                                     , "Rate"))
                        {
                            cm.DTyp = FieldMDEnums.eDTyp.Dbl;
                        }
                        else if (cm.Name.length() > 4 &&
                                 bIn(cm.Name.substring(cm.Name.length() - 4)
                                     , "Name", "Code", "Stat", "Flag"))
                        {
                            cm.DTyp = FieldMDEnums.eDTyp.VLS;
                        }
                        else
                        {
                            cm.DTyp = FieldMDEnums.eDTyp.VLS;
                        }
                    }

                    if (cm.DTyp.bIn(FieldMDEnums.eDTyp.VLS, FieldMDEnums.eDTyp.Str))
                    {
                        cm.StringMaxLength = FieldMD.Default.StringMaxLength;
                    }
                }
            }
            catch (Exception e) {
                throw new com.WDataSci.WDS.WDSException("Error mapping input columns:", e);
            }
        }
Esempio n. 3
0
        //Java public void mReadMapFor(Document aDoc, RecordSetMD aRecordSetMD, JniPMMLItem aJniPMMLItem, PrintWriter pw, Boolean bFillDictionaryNames)
        //C#
        public void mReadMapFor(XmlDocument aDoc, RecordSetMD aRecordSetMD, JniPMMLItem aJniPMMLItem, PrintWriter pw, Boolean bFillDictionaryNames)
        //throws com.WDataSci.WDS.WDSException
        {
            try {
                int jj = -1;
                int j  = -1;


                //are we using a JniPMML object (as when called from C# and does it have PMMLMatter
                Boolean bUsingJniPMML        = (aJniPMMLItem != null);
                Boolean bCheckingAgainstPMML = (aJniPMMLItem != null && aJniPMMLItem.PMMLMatter.Doc != null);

                String[] lFieldStringNames = null;
                int      nDataFieldNames   = 0;

                if (bCheckingAgainstPMML)
                {
                    lFieldStringNames = aJniPMMLItem.PMMLDataFieldStringNames();
                    nDataFieldNames   = lFieldStringNames.Length;
                }


                if (aRecordSetMD.SchemaMatter == null)
                {
                    throw new com.WDataSci.WDS.WDSException("Error, aRecordSetMD.SchemaMatter not populated");
                }

                String rns = aRecordSetMD.SchemaMatter.RecordSetElementName;
                String rn  = aRecordSetMD.SchemaMatter.RecordElementName;

                if (rns == null || rns.isEmpty())
                {
                    rns = Util.RecordSetElementName(aRecordSetMD.SchemaMatter.InputSchema);
                }
                if (rn == null || rn.isEmpty())
                {
                    rn = Util.RecordSingleName(rns);
                }
                if (rns.equals(rn))
                {
                    throw new com.WDataSci.WDS.WDSException("Error, RecordSetMD needs a valid RecordSetElementName, it's singular version, and they cannot be equal");
                }

                if (aRecordSetMD.SchemaMatter.RecordSetElementName == null)
                {
                    aRecordSetMD.SchemaMatter.RecordSetElementName = rns;
                }
                if (aRecordSetMD.SchemaMatter.RecordElementName == null)
                {
                    aRecordSetMD.SchemaMatter.RecordElementName = rn;
                }

                String xPathQ = "/node()/child::*[local-name()='element' and @name='" + rns + "']" +
                                "//*[local-name()='element' and @name='" + rn + "']" +
                                "//*[local-name()='element']";
                //Java XPath xPath = XPathFactory.newInstance().newXPath();
                //Java NodeList xnl = (NodeList) xPath.evaluate(xPathQ, aDoc, XPathConstants.NODESET);
                //C#
                XmlNodeList xnl = aDoc.SelectNodes(xPathQ);

                int xnlLength = xnl.getLength();

                aRecordSetMD.Column = new FieldMD[xnlLength];

                //for when the Length is packed into the XSD type for limiting strings
                int[] typl = new int[1];
                for (jj = 0; jj < xnlLength; jj++)
                {
                    aRecordSetMD.Column[jj] = new FieldMD();
                    FieldMD cm = aRecordSetMD.Column[jj];

                    //Get the XML/XSD element
                    //Java Element xn = (Element) xnl.item(jj);
                    //C#
                    XmlNode xn = xnl[jj];

                    //Get the name and initialize the mapped names
                    //Java cm.Name = xn.getAttribute("name");
                    //C#
                    cm.Name = xn.Attributes.GetNamedItem("name").Value;

                    //Get the XML/XSD - type
                    //Java String typ = xn.getAttribute("type");
                    //C#
                    String typ = xn.Attributes.GetNamedItem("type").Value;
                    //Java cm.DTyp = FieldMDEnums.eDTyp.FromAlias(typ, typl);
                    //C#
                    cm.DTyp = FieldMDExt.eDTyp_FromAlias(typ, ref typl);
                    if (typl[0] > 0)
                    {
                        cm.StringMaxLength = typl[0];
                    }
                    else if (typl[0] < 0)
                    {
                        //C#
                        XmlNode wds_StringMaxLength = xn.Attributes.GetNamedItem("wds:StringMaxLength");
                        //Java String wds_StringMaxLength = xn.getAttribute("wds:StringMaxLength");
                        if (wds_StringMaxLength != null)
                        {
                            try {
                                //C#
                                cm.StringMaxLength = int.Parse(wds_StringMaxLength.Value);
                                //Java cm.StringMaxLength = Integer.parseInt(wds_StringMaxLength);
                            } catch (Exception e) {
                                cm.StringMaxLength = FieldMD.Default.StringMaxLength;
                            }
                        }
                        else
                        {
                            /* Java >>> *
                             * if (xn.hasAttributes()) {
                             *  for ( int ani = 0; ani < xn.getAttributes().getLength(); ani++ ) {
                             *      if ( xn.getAttributes().item(ani).getNodeName().toLowerCase().endsWith("maxlength") ) {
                             *          cm.StringMaxLength = Integer.parseInt(xn.getAttributes().item(ani).getNodeValue());
                             *          typl[0] = 0;
                             *          break;
                             *      }
                             *  }
                             * }
                             * /* <<< Java */
                            /* C# >>> */
                            for (int ani = 0; ani < xn.Attributes.Count; ani++)
                            {
                                if (xn.Attributes.Item(ani).LocalName.toLowerCase().endsWith("maxlength"))
                                {
                                    cm.StringMaxLength = int.Parse(xn.Attributes.Item(ani).Value);
                                    typl[0]            = 0;
                                    break;
                                }
                            }
                            /* <<< C# */
                            if (typl[0] < 0)
                            {
                                xPathQ = "//*[local-name()='simpleType' and @name='" + typ + "']//*[local-name()='maxLength']";
                                //Java NodeList xnr = (NodeList) xPath.evaluate(xPathQ, aDoc, XPathConstants.NODESET);
                                //C#
                                XmlNodeList xnr = aDoc.SelectNodes(xPathQ);
                                if (xnr.getLength() == 1)
                                {
                                    try {
                                        //Java cm.StringMaxLength = Integer.parseInt(((Element) xnr.item(0)).getAttribute("value"));
                                        //Cs
                                        cm.StringMaxLength = int.Parse(xnr[0].Attributes.GetNamedItem("value").Value);
                                    }
                                    catch (Exception e) {
                                        cm.StringMaxLength = FieldMD.Default.StringMaxLength;
                                    }
                                }
                                else
                                {
                                    cm.StringMaxLength = FieldMD.Default.StringMaxLength;
                                }
                            }
                        }
                    }

                    if (bCheckingAgainstPMML)
                    {
                        //Search for PMML DataFieldName map
                        for (j = 0; j < nDataFieldNames; j++)
                        {
                            if (cm.Name.equals(lFieldStringNames[j]))
                            {
                                cm.MapToMapKey(lFieldStringNames[j]);
                                break;
                            }
                        }
                    }
                    else if (bFillDictionaryNames)
                    {
                        cm.MapToMapKey(cm.Name);
                    }
                }
            }
            catch (Exception e) {
                throw new com.WDataSci.WDS.WDSException("Error mapping input columns:", e);
            }
        }