Ejemplo n.º 1
0
        /* <<< C# */

        public void mUpdateWithPMMLSchema(JniPMMLItem aJniPMML)
        //throws com.WDataSci.WDS.WDSException
        {
            try {
                /* Java >>> *
                 * FieldName[] lFieldNames = aJniPMML.PMMLDataFieldNames();
                 * String[] lFieldStringNames = aJniPMML.PMMLDataFieldStringNames();
                 * int nDataFieldNames = lFieldNames.Length;
                 *
                 * for ( int i = 0; i < this.Column.Length; i++ ) {
                 * FieldMD cm = this.Column[i];
                 * //Search for PMML DataFieldName map
                 * for ( int j = 0; j < nDataFieldNames; j++ ) {
                 * if ( cm.Name.equals(lFieldStringNames[j]) ) {
                 * cm.MapToMapKey(lFieldNames[j]);
                 * break;
                 * }
                 * }
                 * }
                 * /* <<< Java */
            }
            catch (Exception e) {
                throw new WDSException("Error, RecordSetMD.mUpdateWithPMMLSchema:", e);
            }
        }
Ejemplo n.º 2
0
        public JniPMMLItem CreateHandle(String aEvaluatorType, String aTag, object bFileOrString, String src)
        {
            JniPMMLItem aJniPMMLItem = null;

            lock (this)
            {
                aJniPMMLItem = this.GetOrAddItemWithTag(aTag);
                String method;
                if (bFileOrString.Equals(0) && src.startsWith("<?"))
                {
                    method = "mPMMLLoadFromString";
                }
                else
                {
                    method = "mPMMLLoadFromFile";
                }
                List <object> cmargs = new List <object> {
                    aJniPMMLItem.__Handle, src
                };
                aJniPMMLItem.HandleMajorMinor = AddIn.__JniPMML.__Java.CallMethod <string>(method
                                                                                           , "(ILjava/lang/String;)Ljava/lang/String;"
                                                                                           , cmargs);
            }
            return(aJniPMMLItem);
        }
Ejemplo n.º 3
0
 public Boolean TryGetObject(int aHandle, out JniPMMLItem value)
 {
     if (this.Item.TryGetValue(aHandle, out value))
     {
         return(true);
     }
     value = null;
     return(false);
 }
Ejemplo n.º 4
0
 public object CreateHandle(String aEvaluatorType, object[] args, Func <String, object[], JniPMMLItem> lFunc)
 {
     if (ExcelDnaUtil.IsInFunctionWizard())
     {
         return("In Function Wizard, holding calls to Java");
     }
     return(ExcelAsyncUtil.Observe(aEvaluatorType
                                   , args
                                   , () => {
         JniPMMLItem aJniPMMLItem = this.CreateHandle(aEvaluatorType, args[0].ToString(), args[1], args[2].ToString());
         return aJniPMMLItem;
     }
                                   ));
 }
Ejemplo n.º 5
0
        public Boolean TryGetObject(String aTag, out JniPMMLItem value)
        {
            if (!this.__Handle.ContainsKey(aTag))
            {
                value = null;
                return(false);
            }
            int aHandle = this.__Handle[aTag];

            if (this.Item.TryGetValue(aHandle, out value))
            {
                return(true);
            }
            value = null;
            return(false);
        }
Ejemplo n.º 6
0
 public JniPMMLItem Add(JniPMMLItem aJniPMMLItem)
 {
     if (aJniPMMLItem.__Tag.startsWith("Internal") && this.__Tag.ContainsKey(aJniPMMLItem.__Handle))
     {
         //clean up  any Internal's, only one can run at a time
         String[] aHandles = this.__Handle.Keys.ToArray();
         foreach (String aTag in aHandles)
         {
             if (aTag.startsWith("Internal"))
             {
                 this.Remove(aTag);
             }
         }
     }
     this.__Handle.Add(aJniPMMLItem.__Tag, aJniPMMLItem.__Handle);
     this.__Tag.Add(aJniPMMLItem.__Handle, aJniPMMLItem.__Tag);
     this.Item.Add(aJniPMMLItem.__Handle, aJniPMMLItem);
     return(aJniPMMLItem);
 }
Ejemplo n.º 7
0
        public RecordSetMD mReadMapFor(JniPMMLItem aJniPMMLItem, PrintWriter pw, Boolean bFillDictionaryNames)
        //throws com.WDataSci.WDS.WDSException
        {
            try {
                if (!this.Mode.bIn(RecordSetMDEnums.eMode.Input, RecordSetMDEnums.eMode.Internal))
                {
                    throw new WDSException("Error, wrong mode for RecordSetMD.mReadMapFor(JniPMML)!");
                }

                if (this.SchemaType.equals(RecordSetMDEnums.eSchemaType.XSD))
                {
                    this.SchemaMatter.mReadMapFor(this, aJniPMMLItem, pw, bFillDictionaryNames);
                }
                else if (this.SchemaType.equals(RecordSetMDEnums.eSchemaType.NamingConvention) && this.Type.isFlatFile())
                {
                    this.FileMatter.mReadMapFor(this, aJniPMMLItem, pw, bFillDictionaryNames);
                }
                else if (this.Type.equals(RecordSetMDEnums.eType.HDF5))
                {
                    this.HDF5Matter.mReadMapFor(this, aJniPMMLItem, pw, bFillDictionaryNames);
                }
                else if (this.Type.equals(RecordSetMDEnums.eType.DBB))
                {
                    this.DBBMatter.mReadMap(this, aJniPMMLItem, pw, bFillDictionaryNames);
                }

                if (pw != null)
                {
                    pw.printf("leaving RecordSetMD.mReadMapFor constructor\n");
                }
                if (pw != null)
                {
                    pw.flush();
                }
                return(this);
            }
            catch (Exception e) {
                throw new WDSException("Error in RecordSetMD.mReadMapFor", e);
            }
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
0
        //Java public RecordSetMD mPrepForOutput(RecordSetMD aInputRecordSetMD, JniPMML aJniPMML, List<Map<FieldName, Object>> Results)
        //C#
        public RecordSetMD mPrepForOutput <T>(RecordSetMD aInputRecordSetMD, JniPMMLItem aJniPMML, List <Map <T, Object> > Results)
        //throws Exception
        {
            int i  = -1;
            int j  = -1;
            int k  = -1;
            int jj = -1;

            int nInputMap = aInputRecordSetMD.nColumns();

            //C#
            throw new com.WDataSci.WDS.WDSException("Error, not implemented on the C# side");

            /* Java >>> *
             * //Output
             * List<Model> m = aJniPMML.PMMLMatter.Doc.getModels();
             * org.dmg.pmml.Output mo = m.get(0).getOutput();
             * List<org.dmg.pmml.OutputField> mol = mo.getOutputFields();
             *
             * //Java Set<FieldName> ks = Results.get(0).keySet();
             * //Java FieldName[] ksa = new FieldName[ks.size()];
             * //Java ks.toArray(ksa);
             *
             * //C#
             * FieldName[] ksa = Results.get(0).keyArray();
             *
             * int nResultColumns = ks.size();
             * int nColumns = nResultColumns;
             * int nRows = Results.size();
             *
             * if ( this.ModeMatter == null ) this.ModeMatter = new __ModeMatter();
             *
             * if ( this.ModeMatter.bRepeatInputFields ) {
             * nColumns += nInputMap;
             * this.ModeMatter.nInputFields = nInputMap;
             * this.Column = new FieldMD[nColumns];
             * for (j = 0; j < nInputMap; j++) {
             * this.Column[j] = new FieldMD(aInputRecordSetMD.Column[j]);
             * this.Column[j].Name = aInputRecordSetMD.Column[j].Name + this.ModeMatter.CompositeNameDlm + this.ModeMatter.CompositeInputNameSuffix;
             * }
             * jj = nInputMap;
             * }
             * else {
             * this.Column = new FieldMD[nColumns];
             * jj = 0;
             * }
             *
             * for (k = 0, j = jj; k < nResultColumns; k++, j++) {
             * this.Column[j] = new FieldMD();
             * this.Column[j].Name = ksa[k].toString();
             * this.Column[j].MapToMapKey(ksa[k]);
             *
             * org.dmg.pmml.OutputField of = mol.get(k);
             * org.dmg.pmml.DataType ofdtyp = of.getDataType();
             *
             * if ( nResultColumns != mol.size() )
             * throw new WDSException("Error, difference between result field count and model output field count!");
             *
             * //if the output field does not have a type, does it match an input field? This can happen with a result feature.
             * Boolean found = false;
             * if ( ofdtyp == null ) {
             * for (i = 0; !found && i < nInputMap; i++) {
             * if ( aInputRecordSetMD.Column[i].hasMapKey() && aInputRecordSetMD.Column[i].MapKey.getValue().equals(this.Column[j].Name) ) {
             * found = true;
             * this.Column[j].Copy(aInputRecordSetMD.Column[i]);
             * break;
             * }
             * }
             * if ( found && of.getResultFeature() != null ) {
             * this.Column[j].Name = this.Column[j].Name + this.ModeMatter.CompositeNameDlm + of.getResultFeature().toString();
             * }
             * }
             * if ( !found ) {
             * //If not found as an input field or a feature of one, extract the rest of the X mapping info from the PMML
             * if ( of.getDataType().equals(org.dmg.pmml.DataType.DOUBLE) || of.getDataType().equals(org.dmg.pmml.DataType.FLOAT) ) {
             * this.Column[j].DTyp = FieldMDEnums.eDTyp.Dbl;
             * }
             * else if ( of.getDataType().equals(org.dmg.pmml.DataType.INTEGER) ) {
             * this.Column[j].DTyp = FieldMDEnums.eDTyp.Int;
             * //there may not be a long PMML output type, double check if field is named like an input long
             * for (found = false, i = 0; !found && i < nInputMap; i++) {
             * if ( this.Column[i].hasMapKey() && this.Column[i].MapKey.getValue().equals(this.Column[j].Name) ) {
             * found = true;
             * if ( this.Column[i].DTyp.equals(FieldMDEnums.eDTyp.Lng) ) {
             * this.Column[j].DTyp = FieldMDEnums.eDTyp.Lng;
             * }
             * }
             * }
             * }
             * else if ( of.getDataType().equals(org.dmg.pmml.DataType.DATE) ) {
             * this.Column[j].DTyp = FieldMDEnums.eDTyp.Dte;
             * }
             * else if ( of.getDataType().equals(org.dmg.pmml.DataType.DATE_TIME) ) {
             * this.Column[j].DTyp = FieldMDEnums.eDTyp.DTm;
             * }
             * else if ( of.getDataType().equals(org.dmg.pmml.DataType.STRING) ) {
             * this.Column[j].DTyp = FieldMDEnums.eDTyp.VLS;
             * }
             * else if ( of.getDataType().equals(org.dmg.pmml.DataType.BOOLEAN) ) {
             * throw new WDSException("Error, OutputColumn DataType for Boolean not implemented!");
             * }
             * else {
             * throw new WDSException("Error, un-implemented OutputColumn DataType !");
             * }
             * }
             * }
             *
             * return this;
             * /* <<< Java */
        }
Ejemplo n.º 10
0
 public void Remove(JniPMMLItem arg)
 {
     int aHandle = arg.Handle(); this.Item[aHandle].PreDispose();  String aTag = arg.Tag(); this.__Handle.Remove(aTag);  this.__Tag.Remove(aHandle); this.Item.Remove(aHandle);
 }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
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);
            }
        }
Ejemplo n.º 13
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);
            }
        }