Esempio n. 1
0
 internal bool ColsUnchanged()
 {
     if (ColCount != ParentMatrix.ColCount)
     {
         return(false);
     }
     return(ColKeys.SequenceEqual(ParentMatrix.ColKeys));
 }
Esempio n. 2
0
        /// <summary>
        ///
        /// This method will map another tag within the pulled Xml to a column of the target table.
        ///
        /// <param name="psName">The column name of the target table</param>
        /// <param name="poType">The data type of the column in the target table</param>
        /// <param name="pbIsKey">The indicator of whether the target table's column is part of the primary key</param>
        /// <param name="pnLength">The length of the table's column (if the type is text)</param>
        /// <param name="psXPath">The XPath of the tag mapped to the target table's column</param>
        /// <param name="pbIsXmlBody">The indicator of whether the XPath points to a single node's value or a composite that should be serialized</param>
        /// <returns>None.</returns>
        /// </summary>
        public void AddTargetColumn(string psName, SqlDbType poType, bool pbIsKey, int pnLength, string psXPath, bool pbIsXmlBody)
        {
            SoughtColumns[psName]      = poType;
            SoughtColKeys[psName]      = pbIsKey;
            SoughtColLengths[psName]   = pnLength;
            SoughtColXPaths[psName]    = psXPath;
            SoughtColXmlBodies[psName] = pbIsXmlBody;

            if (pbIsKey)
            {
                ColKeys.Add(psName);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the DenseMatrix class that wraps a .NET 2-D array
        /// </summary>
        /// <param name="valueArray">The 2-D .NET array to wrap.</param>
        /// <param name="rowKeySequence">A sequence of row keys. The items will become the RowKeys of the Matrix.</param>
        /// <param name="colKeySequence">A sequence of colKeys. The items will come the ColKeys of the Matrix.</param>
        /// <param name="missingValue">The special value that represents missing.</param>
        public DenseMatrix(ref TValue[,] valueArray, IEnumerable <TRowKey> rowKeySequence, IEnumerable <TColKey> colKeySequence, TValue missingValue)
        {
            _rowKeys = new ReadOnlyCollection <TRowKey>(rowKeySequence.ToList());
            _colKeys = new ReadOnlyCollection <TColKey>(colKeySequence.ToList());
            Helper.CheckCondition(valueArray.GetLength(0) == _rowKeys.Count, "Expect the # of rows in the input array to match the # of items in varList");
            Helper.CheckCondition(valueArray.GetLength(1) == _colKeys.Count, "Expect the # of cols in the input array to match the # of items in cidList");

            //!!!Matrix - these lines appear in many places
            _indexOfRowKey = RowKeys.Select((key, index) => new { key, index }).ToDictionary(pair => pair.key, pair => pair.index);
            _indexOfColKey = ColKeys.Select((key, index) => new { key, index }).ToDictionary(pair => pair.key, pair => pair.index);

            ValueArray    = valueArray;
            _missingValue = missingValue;
        }
Esempio n. 4
0
 /// <summary>
 /// Writes the matrix to a TextWriter in dense format. The first line is "var" TAB and then the tab-delimited col keys.
 /// Next is one line per row key. Each line is the row key TAB and then the tab-limited values.
 /// Values may include the special Missing value.
 /// </summary>
 /// <param name="textWriter">The TextWriter to write to.</param>
 virtual public void WriteDense(TextWriter textWriter)
 {
     textWriter.WriteLine("var\t{0}", ColKeys.StringJoin("\t"));
     foreach (TRowKey rowKey in RowKeys)
     {
         textWriter.Write(rowKey);
         foreach (TColKey colKey in ColKeys)
         {
             textWriter.Write("\t");
             textWriter.Write(GetValueOrMissing(rowKey, colKey));
         }
         textWriter.WriteLine();
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the DenseMatrix class that wraps a .NET 2-D array
        /// </summary>
        /// <param name="valueArray">The 2-D .NET array to wrap.</param>
        /// <param name="rowKeySequence">A sequence of row keys. The items will become the RowKeys of the Matrix.</param>
        /// <param name="colKeySequence">A sequence of colKeys. The items will come the ColKeys of the Matrix.</param>
        /// <param name="missingValue">The special value that represents missing.</param>
        public DenseMatrix(ref TValue[,] valueArray, IEnumerable <TRowKey> rowKeySequence, IEnumerable <TColKey> colKeySequence, TValue missingValue)
        {
            _rowKeys = new ReadOnlyCollection <TRowKey>(rowKeySequence.ToList());
            _colKeys = new ReadOnlyCollection <TColKey>(colKeySequence.ToList());
            Helper.CheckCondition(valueArray.GetLength(0) == _rowKeys.Count, Properties.Resource.ExpectedRowKeysCountToEqualValueArrayCount, _rowKeys.Count, valueArray.GetLength(0));
            Helper.CheckCondition(valueArray.GetLength(1) == _colKeys.Count, Properties.Resource.ExpectedColumnKeysCountToEqualValueArrayCount, _colKeys.Count, valueArray.GetLength(1));

            //!!!Matrix - these lines appear in many places
            _indexOfRowKey = RowKeys.Select((key, index) => new { key, index }).ToDictionary(pair => pair.key, pair => pair.index);
            _indexOfColKey = ColKeys.Select((key, index) => new { key, index }).ToDictionary(pair => pair.key, pair => pair.index);

            ValueArray    = valueArray;
            _missingValue = missingValue;
        }
Esempio n. 6
0
        /// <summary>
        /// Determines whether two Matrix&lt;TRowKey,TColKey,TValue&gt; are equal. They are equal if they
        ///   0. The 2nd one is not null
        ///   3. Have the same missing values
        ///   1. have the same rowKeys, in the same order
        ///   2. have the same colKeys, in the same order
        ///   4. Have the same nonmissing values
        /// May be as slow as O(rowCount * colCount)
        /// </summary>
        /// <param name="otherMatrix">The matrix to compare to</param>
        /// <returns>true, if they are equal in terms of rowKeys, colKeys, missing and nonMissing values. Otherwise, false.</returns>
        public bool MatrixEquals(Matrix <TRowKey, TColKey, TValue> otherMatrix)
        {
            if (otherMatrix == null)
            {
                return(false);
            }

            if (!IsMissing(otherMatrix.MissingValue))
            {
                return(false);
            }

            if (!RowKeys.SequenceEqual(otherMatrix.RowKeys))
            {
                return(false);
            }

            if (!ColKeys.SequenceEqual(otherMatrix.ColKeys))
            {
                return(false);
            }


            for (int rIdx = 0; rIdx < RowCount; rIdx++)
            {
                for (int cIdx = 0; cIdx < ColCount; cIdx++)
                {
                    TValue value1 = GetValueOrMissing(rIdx, cIdx);
                    TValue value2 = otherMatrix.GetValueOrMissing(rIdx, cIdx);
                    if (value1 == null)
                    {
                        if (value2 != null)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (!value1.Equals(value2))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Write out the RowKeys file for a matrix. This file is an index to the rows of another file.
        /// </summary>
        /// <param name="simpleFileName">The rowKeys file to write to. It must not include any path information. It will be created in the other file's directory.</param>
        public void WriteRowKeys(string simpleFileName)
        {
            Helper.CheckCondition(String.IsNullOrEmpty(Path.GetDirectoryName(simpleFileName)), Properties.Resource.FileNameMustNotContainPathInformation);
            string fileName = Path.Combine(Path.GetDirectoryName(DenseStructFileName), simpleFileName);

            FileUtils.CreateDirectoryForFileIfNeeded(fileName);
            using (TextWriter textWriter = File.CreateText(fileName))
            {
                textWriter.WriteLine("rowKey\t{0}", ColKeys.StringJoin("\t")); //!!!const
                textWriter.WriteLine(Path.GetFileName(DenseStructFileName));
                foreach (string rowKey in RowKeys)
                {
                    textWriter.WriteLine("{0}\t{1}", rowKey, RowKeyToFilePosition[rowKey]);
                }
            }
        }
Esempio n. 8
0
        internal void SetUp(Matrix <TRowKey, TColKey, TValue> parentMatrix, IEnumerable <TRowKey> rowKeySequence, IEnumerable <TColKey> colKeySequence)
        {
            ParentMatrix = parentMatrix;
            _rowKeys     = new ReadOnlyCollection <TRowKey>(rowKeySequence.ToList());
            _colKeys     = new ReadOnlyCollection <TColKey>(colKeySequence.ToList());

            Helper.CheckCondition(_rowKeys.All(row => parentMatrix.IndexOfRowKey.ContainsKey(row)), Properties.Resource.ExpectedMatrixViewRowKeysToBeSubsetOfParentMatrix);
            Helper.CheckCondition(_colKeys.All(col => parentMatrix.IndexOfColKey.ContainsKey(col)), Properties.Resource.ExpectedMatrixViewColKeysToBeSubsetOfParentMatrix);

            //!!!Matrix - these lines appear in many places
            _indexOfRowKey = RowKeys.Select((key, index) => new { key, index }).ToDictionary(pair => pair.key, pair => pair.index);
            _indexOfColKey = ColKeys.Select((key, index) => new { key, index }).ToDictionary(pair => pair.key, pair => pair.index);

            IndexOfParentRowKey = new ReadOnlyCollection <int>(_rowKeys.Select(rowKey => parentMatrix.IndexOfRowKey[rowKey]).ToList());
            IndexOfParentColKey = new ReadOnlyCollection <int>(_colKeys.Select(colKey => parentMatrix.IndexOfColKey[colKey]).ToList());
        }
Esempio n. 9
0
        internal void SetUp(Matrix <TRowKey, TColKey, TValue> parentMatrix, IEnumerable <TRowKey> rowKeySequence, IEnumerable <TColKey> colKeySequence)
        {
            ParentMatrix = parentMatrix;
            _rowKeys     = new ReadOnlyCollection <TRowKey>(rowKeySequence.ToList());
            _colKeys     = new ReadOnlyCollection <TColKey>(colKeySequence.ToList());

            Helper.CheckCondition(_rowKeys.All(row => parentMatrix.IndexOfRowKey.ContainsKey(row)), "The rowKeys of the MatrixView must be a subset the rowKeys of the parentMatrix. The sets can also be equal");
            Helper.CheckCondition(_colKeys.All(col => parentMatrix.IndexOfColKey.ContainsKey(col)), "The colKeys of the MatrixView must be a subset the colKeys of the parentMatrix. The sets can also be equal");

            //!!!Matrix - these lines appear in many places
            _indexOfRowKey = RowKeys.Select((key, index) => new { key, index }).ToDictionary(pair => pair.key, pair => pair.index);
            _indexOfColKey = ColKeys.Select((key, index) => new { key, index }).ToDictionary(pair => pair.key, pair => pair.index);

            IndexOfParentRowKey = new ReadOnlyCollection <int>(_rowKeys.Select(rowKey => parentMatrix.IndexOfRowKey[rowKey]).ToList());
            IndexOfParentColKey = new ReadOnlyCollection <int>(_colKeys.Select(colKey => parentMatrix.IndexOfColKey[colKey]).ToList());
        }
Esempio n. 10
0
        /// <summary>
        /// Write out the RowKeys file for a matrix. This file is an index to the rows of another file.
        /// </summary>
        /// <param name="simpleFileName">The rowKeys file to write to. It must not include any path information. It will be created in the other file's directory.</param>
        public void WriteRowKeys(string simpleFileName)
        {
            Helper.CheckCondition(Path.GetDirectoryName(simpleFileName) == "", "The file name must not include any path information. It will be create in the other file's directory");
            string fileName = Path.Combine(Path.GetDirectoryName(DenseStructFileName), simpleFileName);

            FileUtils.CreateDirectoryForFileIfNeeded(fileName);
            using (TextWriter textWriter = File.CreateText(fileName))
            {
                textWriter.WriteLine("rowKey\t{0}", ColKeys.StringJoin("\t")); //!!!const
                textWriter.WriteLine(Path.GetFileName(DenseStructFileName));
                foreach (string rowKey in RowKeys)
                {
                    textWriter.WriteLine("{0}\t{1}", rowKey, RowKeyToFilePosition[rowKey]);
                }
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Writes the matrix to a TextWriter in dense format. The first line is "var" TAB and then the tab-delimited col keys.
 /// Next is one line per row key. Each line is the row key TAB and then the tab-limited values.
 /// Values may include the special Missing value.
 /// </summary>
 /// <param name="textWriter">The TextWriter to write to.</param>
 virtual public void WriteDense(TextWriter textWriter)
 {
     textWriter.WriteLine("var\t{0}", ColKeys.StringJoin("\t"));
     foreach (TRowKey rowKey in RowKeys)
     {
         textWriter.Write(rowKey);
         foreach (TColKey colKey in ColKeys)
         {
             textWriter.Write("\t");
             TValue      value  = GetValueOrMissing(rowKey, colKey);
             IEnumerable asEnum = value as IEnumerable;
             if (!(value is string) && asEnum != null)
             {
                 textWriter.Write(asEnum.StringJoin(","));
             }
             else
             {
                 textWriter.Write(value);
             }
         }
         textWriter.WriteLine();
     }
 }
Esempio n. 12
0
 public QDataFrameLite(IEnumerable <TRowKey> rowKeys, IEnumerable <TColKey> colKeys)
 {
     rowKeys.ForEach((x, i) => RowKeys.Add(x, i));
     colKeys.ForEach((x, i) => ColKeys.Add(x, i));
     Data = new TVal[RowKeys.Count, ColKeys.Count];
 }