예제 #1
0
        public void mReadMapFor(RecordSetMD aRecordSetMD, JniPMMLItem aJniPMMLItem, PrintWriter pw, Boolean bFillDictionaryNames)
        //throws WDSException
        {
            try {
                int i  = -1;
                int ii = -1;
                int j  = -1;
                int jj = -1;
                int k  = -1;
                int kk = -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");
                }

                //if using JniPMML, does it already have InputSchema Matter
                if (aRecordSetMD.SchemaMatter.InputSchemaFileName == null && bUsingJniPMML && aJniPMMLItem.InputMatter._XSDFileName != null)
                {
                    aRecordSetMD.SchemaMatter.InputSchemaFileName = aJniPMMLItem.InputMatter._XSDFileName;
                }
                if (aRecordSetMD.SchemaMatter.InputSchemaString == null && bUsingJniPMML && aJniPMMLItem.InputMatter._XSDString != null)
                {
                    aRecordSetMD.SchemaMatter.InputSchemaString = aJniPMMLItem.InputMatter._XSDString;
                }
                if (aRecordSetMD.SchemaMatter.InputSchema == null && bUsingJniPMML && aJniPMMLItem.InputMatter._XSDDoc != null)
                {
                    aRecordSetMD.SchemaMatter.InputSchema = aJniPMMLItem.InputMatter._XSDDoc;
                }

                //else go get it
                if (aRecordSetMD.SchemaMatter.InputSchema == null)
                {
                    if (aRecordSetMD.SchemaMatter.InputSchemaString == null)
                    {
                        if (aRecordSetMD.SchemaMatter.InputSchemaFileName == null)
                        {
                            throw new com.WDataSci.WDS.WDSException("Error, InputMap XSD not provided or valid!");
                        }
                        aRecordSetMD.SchemaMatter.InputSchemaString = com.WDataSci.WDS.Util.FetchFileAsString(aRecordSetMD.SchemaMatter.InputSchemaFileName);
                    }

                    /* Java >>> *
                     * if ( bUsingJniPMML )
                     *  aRecordSetMD.SchemaMatter.InputSchema = aJniPMMLItem.mReadMapFromXSDString(aRecordSetMD.SchemaMatter.InputSchemaString);
                     * else
                     *  aRecordSetMD.SchemaMatter.InputSchema = new JniPMMLItem().mReadMapFromXSDString(aRecordSetMD.SchemaMatter.InputSchemaString);
                     * /* <<< Java */
                    /* C# >>> */
                    aRecordSetMD.SchemaMatter.InputSchema = new XmlDocument();
                    aRecordSetMD.SchemaMatter.InputSchema.LoadXml(aRecordSetMD.SchemaMatter.InputSchemaString);
                    /* <<< C# */
                }

                this.mReadMapFor(aRecordSetMD.SchemaMatter.InputSchema, aRecordSetMD, aJniPMMLItem, pw, bFillDictionaryNames);
            }
            catch (Exception e) {
                throw new com.WDataSci.WDS.WDSException("Error mapping input columns:", e);
            }
        }
예제 #2
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);
            }
        }
예제 #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);
            }
        }