示例#1
0
        public void TestIndexResourceObservation()
        {
            FhirJsonParser parser      = new FhirJsonParser();
            var            obsResource = parser.Parse <Resource>(exampleObservationJson);

            IKey cpKey = new Key("http://localhost/", "Observation", "blood-pressure", null);

            IndexValue result = sutFull.IndexResource(obsResource, cpKey);

            Assert.IsNotNull(result);
        }
示例#2
0
        public void TestIndexResourceAppointmentComplete()
        {
            FhirJsonParser parser      = new FhirJsonParser();
            var            appResource = parser.Parse <Resource>(exampleAppointmentJson);

            IKey appKey = new Key("http://localhost/", "Appointment", "2docs", null);

            IndexValue result = sutFull.IndexResource(appResource, appKey);

            Assert.IsNotNull(result);
        }
示例#3
0
 private void AddContainedResources(DomainResource resource, IndexValue parent)
 {
     parent.Values.AddRange(
         resource.Contained.Where(c => c is DomainResource)
         .Select(
             c =>
     {
         IKey containedKey = c.ExtractKey();
         return(IndexResourceRecursively(c as DomainResource, containedKey, "contained"));
     }));
 }
示例#4
0
        /// <inheritdoc />
        public async Task Save(IndexValue indexValue)
        {
            using var session = _sessionFunc();
            var values      = indexValue.IndexValues().ToArray();
            var id          = (StringValue)values.First(x => x.Name == "internal_forResource").Values[0];
            var resource    = (StringValue)values.First(x => x.Name == "internal_resource").Values[0];
            var canonicalId = (StringValue)values.First(x => x.Name == "internal_Id").Values[0];
            var entry       = new IndexEntry(id.Value, canonicalId.Value, resource.Value, new Dictionary <string, object>());

            foreach (var value in values)
            {
                var array = value.Values.Where(x => x != null).Select(GetValue).ToHashSet();
                var o     = array.Count == 1 ? array.First() : array;
                if (entry.Values.ContainsKey(value.Name))
                {
                    var existing = entry.Values[value.Name];
                    switch (existing)
                    {
                    case HashSet <object> l:
                        switch (o)
                        {
                        case HashSet <object> list:
                            foreach (var item in list)
                            {
                                l.Add(item);
                            }

                            break;

                        default:
                            l.Add(o);
                            break;
                        }

                        entry.Values[value.Name] = l;
                        break;

                    case object x:
                        entry.Values[value.Name] = new HashSet <object> {
                            x, o
                        };
                        break;
                    }
                }
                else
                {
                    entry.Values.Add(value.Name, o);
                }
            }

            session.DeleteWhere <IndexEntry>(x => x.CanonicalId == canonicalId.Value);
            session.Store(entry);
            await session.SaveChangesAsync().ConfigureAwait(false);
        }
示例#5
0
        public void TestIndexResourceCareplanWithContainedGoal()
        {
            FhirJsonParser parser     = new FhirJsonParser();
            var            cpResource = parser.Parse <Resource>(carePlanWithContainedGoal);

            IKey cpKey = new Key("http://localhost/", "Careplan", "f002", null);

            IndexValue result = sutFull.IndexResource(cpResource, cpKey);

            Assert.IsNotNull(result);
        }
示例#6
0
        public void TestIndexResourcePatientComplete()
        {
            FhirJsonParser parser          = new FhirJsonParser();
            var            patientResource = parser.Parse <Resource>(examplePatientJson);

            IKey patientKey = new Key("http://localhost/", "Patient", "001", null);

            IndexValue result = sutFull.IndexResource(patientResource, patientKey);

            Assert.IsNotNull(result);
        }
示例#7
0
        /// <summary>
        ///     Meant for mapping the root IndexValue (and all the stuff below it)
        /// </summary>
        /// <param name="indexValue"></param>
        /// <returns>List of BsonDocuments, one for the root and one for each contained index in it.</returns>
        public List <BsonDocument> MapEntry(IndexValue indexValue)
        {
            var result = new List <BsonDocument>();

            if (indexValue.Name == "root")
            {
                EntryToDocument(indexValue, 0, result);
                return(result);
            }

            throw new ArgumentException("MapEntry is only meant for mapping a root IndexValue.", nameof(indexValue));
        }
示例#8
0
        protected override void OnProcessOutputSchema(MutableObject newSchema)
        {
            var entries = IndexValue.GetEntries(newSchema);

            foreach (var entry in entries)
            {
                XAxisTarget.SetValue(0f, entry);
                YAxisTarget.SetValue(0f, entry);
            }

            Router.TransmitAllSchema(newSchema);
        }
示例#9
0
        public void TestIndexWithPath_x_()
        {
            Condition cd = new Condition();

            cd.Onset = new FhirDateTime(2015, 6, 15);

            IKey cdKey = new Key("http://localhost/", "Condition", "test", null);

            IndexValue result = sutFull.IndexResource(cd, cdKey);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Values.Where(iv => (iv as IndexValue).Name == "onset"));
        }
示例#10
0
 private static void AddMetaParts(Resource resource, IKey key, IndexValue entry)
 {
     entry.Values.Add(new IndexValue("internal_forResource", new StringValue(key.ToUriString())));
     entry.Values.Add(new IndexValue(IndexFieldNames.RESOURCE, new StringValue(resource.TypeName)));
     entry.Values.Add(
         new IndexValue(IndexFieldNames.ID, new StringValue(resource.TypeName + "/" + key.ResourceId)));
     entry.Values.Add(new IndexValue(IndexFieldNames.JUSTID, new StringValue(resource.Id)));
     entry.Values.Add(
         new IndexValue(
             IndexFieldNames.SELFLINK,
             new StringValue(
                 key.ToUriString()))); //CK TODO: This is actually Mongo-specific. Move it to Spark.Mongo, but then you will have to communicate the key to the MongoIndexMapper.
 }
示例#11
0
        private object Escape(IndexValue value)
        {
            var stringValue = value.ValueAsString;

            if (stringValue == null)
            {
                return(value);
            }
            if (stringValue.Length == 0 || _escaperRegex.IsMatch(stringValue))
            {
                return($"'{stringValue}'");
            }
            return(stringValue);
        }
示例#12
0
        /// <summary>
        /// Chen and Guevara 77
        /// </summary>
        /// <param name="numberOfPoints"></param>
        /// <returns></returns>
        public AttributedPointCollection SelectPointsBaesdOnCAG(int numberOfPoints)
        {
            int numberOfRow = this.NumberOfRows;

            int numberOfColumns = this.NumberOfColumns;

            IndexValue <double>[] significanceValues = new IndexValue <double> [numberOfRow * numberOfColumns];

            for (int i = 1; i < numberOfRow - 1; i++)
            {
                for (int j = 1; j < numberOfColumns - 1; j++)
                {
                    double first = CalculateSecondDifference(i, j, RasterDirection.EastWest);

                    double second = CalculateSecondDifference(i, j, RasterDirection.SouthNorth);

                    double third = CalculateSecondDifference(i, j, RasterDirection.NorthernWestSouthernEast);

                    double fourth = CalculateSecondDifference(i, j, RasterDirection.SouthernWestNorthernEast);

                    significanceValues[i * numberOfColumns + j] =
                        new IndexValue <double>(i * numberOfColumns + j, first + second + third + fourth);
                }
            }

            IndexValue <double>[] sortedSignificanceValues = SortAlgorithm.Heapsort <IndexValue <double> >(significanceValues, SortDirection.Ascending);

            AttributedPointCollection irregularPoints = new AttributedPointCollection();

            for (int i = 0; i < numberOfPoints; i++)
            {
                int row = (int)Math.Floor((double)sortedSignificanceValues[i].Index / numberOfColumns);

                int column = sortedSignificanceValues[i].Index % numberOfColumns;

                irregularPoints.Add(this.GetPoint(row, column));
            }

            //AddBorder
            irregularPoints.Add(this.LowerLeft);

            irregularPoints.Add(this.LoweRight);

            irregularPoints.Add(this.UpperLeft);

            irregularPoints.Add(this.UppeRight);

            return(irregularPoints);
        }
        public SossSessionStateItemCollection(string keyPrefix, int timeout)
        {
            this.keyPrefix = keyPrefix + "_";
            countIndex     = keyPrefix + ".Count";
            versionIndex   = keyPrefix + ".Version";
            createPolicy   = new CreatePolicy(TimeSpan.FromMinutes(timeout));
            infinitePolicy = new CreatePolicy(TimeSpan.Zero);

            namedCache                  = CacheFactory.GetCache("SossSessionState");
            keyPrefixIndexValue         = new IndexValue(this.keyPrefix);
            keyPrefixInternalIndexValue = new IndexValue(keyPrefix + ".");

            SyncRoot       = new object();
            IsSynchronized = true;
        }
示例#14
0
        private void Initialize(int firstNode)
        {
            this.labelWeight = new List <IndexValue <double> >();

            this.intendedIndexes = new List <int>();

            for (int i = 0; i < this.NumberOfNodes; i++)
            {
                labelWeight.Add(new IndexValue <double>(firstNode, double.PositiveInfinity));

                intendedIndexes.Add(i);
            }

            labelWeight[firstNode] = new IndexValue <double>(firstNode, 0);
        }
示例#15
0
        private void EntryToDocument(IndexValue indexValue, int level, List <BsonDocument> result)
        {
            //Add the real values (not contained) to a document and add that to the result.
            var notNestedValues = indexValue.Values.OfType <IndexValue>().Where(exp => exp.Name != "contained").ToList();
            var doc             = new BsonDocument(new BsonElement(InternalField.LEVEL, level));

            doc.AddRange(notNestedValues.Select(IndexValueToElement));
            result.Add(doc);

            //Then do that recursively for all contained indexed resources.
            var containedValues = indexValue.Values.OfType <IndexValue>().Where(exp => exp.Name == "contained").ToList();

            foreach (var contained in containedValues)
            {
                EntryToDocument(contained, level + 1, result);
            }
        }
示例#16
0
        public IndexValue GetObjectByGuid(string id)
        {
            IndexValue tb = new IndexValue();

            if (this.DataCatalogIndex != null)
            {
                var obj = this.DataCatalogIndex.IndexValueIn.Where(x => x.ObjectId == id).FirstOrDefault();
                if (obj != null)
                {
                    tb = obj;
                }
                else
                {
                    tb.IndexName = id;
                }
            }
            return(tb);
        }
示例#17
0
        private BsonElement IndexValueToElement(IndexValue indexValue)
        {
            if (indexValue.Name == "_id")
            {
                indexValue.Name = "fhir_id"; //_id is reserved in Mongo for the primary key and must be unique.
            }
            if (indexValue.Values.Count == 1)
            {
                return(new BsonElement(indexValue.Name, Map(indexValue.Values[0])));
            }
            BsonArray values = new BsonArray();

            foreach (var value in indexValue.Values)
            {
                values.Add(Map(value));
            }
            return(new BsonElement(indexValue.Name, values));
        }
示例#18
0
        public override IEnumerator ReceivePayload(VisualPayload payload)
        {
            var entries = IndexValue.GetEntries(payload.Data);

            foreach (var entry in entries)
            {
                var location = ComputeXYPosition(IndexValue.GetValue(entry));
                XAxisTarget.SetValue(location.x, entry);
                YAxisTarget.SetValue(location.y, entry);
            }

            var iterator = Router.TransmitAll(payload);

            while (iterator.MoveNext())
            {
                yield return(null);
            }
        }
示例#19
0
        public IndexValue GetTabela(string content)
        {
            IndexValue tb = new IndexValue();

            if (content.Contains("finalEntity"))
            {
                var parentIdAr = content.Split(':');
                var xname      = parentIdAr[2].Replace("\"", "").Replace("\",\"disable\"", "").Replace(",disable", "");
                if (this.DataCatalogIndex != null)
                {
                    var obj = this.DataCatalogIndex.IndexValueIn.Where(x => x.ObjectId == xname).FirstOrDefault();
                    if (obj != null)
                    {
                        tb = obj;
                    }
                }
            }
            return(tb);
        }
示例#20
0
        public void TestIndexResourceSimple()
        {
            var patient = new Patient();

            patient.Name.Add(new HumanName().WithGiven("Adriaan").AndFamily("Bestevaer"));

            IKey patientKey = new Key("http://localhost/", "Patient", "001", "v02");

            IndexValue result = sutLimited.IndexResource(patient, patientKey);

            Assert.AreEqual("root", result.Name);
            Assert.AreEqual(1, result.NonInternalValues().Count(), "Expected 1 non-internal result for searchparameter 'name'");
            var first = result.NonInternalValues().First();

            Assert.AreEqual("name", first.Name);
            Assert.AreEqual(2, first.Values.Count);
            Assert.IsInstanceOfType(first.Values[0], typeof(StringValue));
            Assert.IsInstanceOfType(first.Values[1], typeof(StringValue));
        }
示例#21
0
        public override SnQueryPredicate VisitRangePredicate(RangePredicate range)
        {
            var min          = range.Min;
            var max          = range.Max;
            var minExclusive = range.MinExclusive;
            var maxExclusive = range.MaxExclusive;

            IndexValue oneTerm = null;

            _output.Append(range.FieldName);
            _output.Append(":");

            string op = null;

            if (min == null)
            {
                op      = !maxExclusive ? "<=" : "<";
                oneTerm = max;
            }
            if (max == null)
            {
                op      = !minExclusive ? ">=" : ">";
                oneTerm = min;
            }

            if (op == null)
            {
                _output.Append(!minExclusive ? '[' : '{');
                _output.Append(Escape(min));
                _output.Append(" TO ");
                _output.Append(Escape(max));
                _output.Append(!maxExclusive ? ']' : '}');
            }
            else
            {
                _output.Append(op).Append(Escape(oneTerm));
            }
            BoostTostring(range.Boost);

            return(base.VisitRangePredicate(range));
        }
示例#22
0
        private IndexValue IndexResourceRecursively(Resource resource, IKey key, string rootPartName = "root")
        {
            var searchParametersForResource = _fhirModel.FindSearchParameters(resource.GetType());

            if (searchParametersForResource != null)
            {
                var result = new IndexValue(rootPartName);

                AddMetaParts(resource, key, result);

                foreach (var par in searchParametersForResource)
                {
                    var newIndexPart = new IndexValue(par.Code);
                    foreach (var path in par.GetPropertyPath())
                    {
                        _resourceVisitor.VisitByPath(resource,
                                                     obj =>
                        {
                            if (obj is Element)
                            {
                                newIndexPart.Values.AddRange(_elementIndexer.Map(obj as Element));
                            }
                        }
                                                     , path);
                    }
                    if (newIndexPart.Values.Any())
                    {
                        result.Values.Add(newIndexPart);
                    }
                }

                if (resource is DomainResource)
                {
                    AddContainedResources((DomainResource)resource, result);
                }

                return(result);
            }
            return(null);
        }
示例#23
0
 private static object GetValue(Expression expression)
 {
     return(expression switch
     {
         StringValue stringValue => stringValue.Value,
         IndexValue indexValue => indexValue.Values.Count == 1
             ? GetValue(indexValue.Values[0])
             : indexValue.Values.Select(GetValue).ToArray(),
         CompositeValue compositeValue =>
         compositeValue.Components.OfType <IndexValue>().All(x => x.Name == "code")
                 ? compositeValue.Components.OfType <IndexValue>()
         .SelectMany(x => x.Values.Select(GetValue))
         .First()
                 : compositeValue.Components.OfType <IndexValue>()
         .ToDictionary(
             component => component.Name,
             component =>
         {
             var a = component.Values.Select(GetValue).ToArray();
             return a.Length == 1 ? a[0] : a;
         }),
         _ => expression.ToString()
     });
示例#24
0
        public void TestMapRootIndexValue()
        {
            //"root" element should be skipped.
            IndexValue iv = new IndexValue("root");

            iv.Values.Add(new IndexValue("internal_resource", new StringValue("Patient")));

            var results = sut.MapEntry(iv);

            Assert.Single(results);
            var result = results[0];

            Assert.True(result.IsBsonDocument);
            Assert.Equal(2, result.AsBsonDocument.ElementCount);
            var firstElement = result.AsBsonDocument.GetElement(0);

            Assert.Equal("internal_level", firstElement.Name);
            var secondElement = result.GetElement(1);

            Assert.Equal("internal_resource", secondElement.Name);
            Assert.True(secondElement.Value.IsString);
            Assert.Equal("Patient", secondElement.Value.AsString);
        }
示例#25
0
        private string ConvertToTermValue(IndexValue value)
        {
            switch (value.Type)
            {
            case IndexValueType.String:      return(value.StringValue);

            case IndexValueType.StringArray: throw new NotSupportedException();

            case IndexValueType.Bool:        return(value.BooleanValue ? IndexValue.Yes : IndexValue.No);

            case IndexValueType.Int:         return(NumericUtils.IntToPrefixCoded(value.IntegerValue));

            case IndexValueType.Long:        return(NumericUtils.LongToPrefixCoded(value.LongValue));

            case IndexValueType.Float:       return(NumericUtils.FloatToPrefixCoded(value.SingleValue));

            case IndexValueType.Double:      return(NumericUtils.DoubleToPrefixCoded(value.DoubleValue));

            case IndexValueType.DateTime:    return(NumericUtils.LongToPrefixCoded(value.DateTimeValue.Ticks));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public static List <int> GetConvexHullVertexes(PointCollection points)
        {
            int leftBoundIndex = points.LowerBoundIndex;

            IRI.Ket.Geometry.Point initialPoint = points[leftBoundIndex];

            int length = points.Count;

            IndexValue <double>[] list = new IndexValue <double> [length - 1];

            int counter = 0;

            for (int i = 0; i < length; i++)
            {
                if (i == leftBoundIndex)
                {
                    continue;
                }

                list[counter] = new IndexValue <double>(i,
                                                        Math.Atan2(points[i].Y - initialPoint.Y,
                                                                   points[i].X - initialPoint.X));
                counter++;
            }

            list = SortAlgorithm.Heapsort <IndexValue <double> >(list, SortDirection.Descending);

            List <int> result = new List <int>();

            result.Add(leftBoundIndex);

            counter = 0;

            while (counter < list.Length)
            {
                IRI.Ket.Geometry.Point tempPoint = points[list[counter].Index];

                if (result.Count < 2)
                {
                    result.Add(list[counter].Index);

                    counter++;

                    continue;
                }

                PointVectorRelation pointSituation = GetPointVectorRelation(tempPoint,
                                                                            points[result[result.Count - 2]],
                                                                            points[result[result.Count - 1]]);

                if (pointSituation == PointVectorRelation.LiesLeft)
                {
                    result.Add(list[counter].Index);

                    counter++;
                }
                else if (pointSituation == PointVectorRelation.LiesRight)
                {
                    result.RemoveAt(result.Count - 1);
                }
                else
                {
                    if (list[counter].Value == list[0].Value &&
                        CalculateDistance(initialPoint, tempPoint) > CalculateDistance(initialPoint, points[result[result.Count - 1]]))
                    {
                        result.Add(list[counter].Index);

                        counter++;
                    }
                    else if (list[counter].Value == list[length - 2].Value &&
                             CalculateDistance(initialPoint, tempPoint) < CalculateDistance(initialPoint, points[result[result.Count - 1]]))
                    {
                        result.Add(list[counter].Index);

                        counter++;
                    }
                    else
                    {
                        result.RemoveAt(result.Count - 1);
                    }
                }
            }

            return(result);
        }
        public static PointCollection CreateConvexHull(PointCollection points)
        {
            int leftBoundIndex = points.LowerBoundIndex;

            IRI.Ket.Geometry.Point initialPoint = points[leftBoundIndex];

            int length = points.Count;

            IndexValue <double>[] unsortedPoints = new IndexValue <double> [length - 1];

            int counter = 0;

            for (int i = 0; i < length; i++)
            {
                if (i == leftBoundIndex)
                {
                    continue;
                }

                unsortedPoints[counter] = new IndexValue <double>(i,
                                                                  Math.Atan2(points[i].Y - initialPoint.Y,
                                                                             points[i].X - initialPoint.X));
                counter++;
            }

            IndexValue <double>[] sortedPoints = SortAlgorithm.Heapsort <IndexValue <double> >(unsortedPoints, SortDirection.Descending);

            IRI.Ket.Geometry.PointCollection result = new IRI.Ket.Geometry.PointCollection();

            result.Add(points[leftBoundIndex]);

            counter = 0;

            while (counter < sortedPoints.Length)
            {
                IRI.Ket.Geometry.Point tempPoint = points[sortedPoints[counter].Index];

                if (result.Count < 2)
                {
                    result.Add(tempPoint);

                    counter++;

                    continue;
                }

                PointVectorRelation pointSituation = GetPointVectorRelation(tempPoint, result[result.Count - 2], result[result.Count - 1]);

                if (pointSituation == PointVectorRelation.LiesLeft)
                {
                    result.Add(tempPoint);

                    counter++;
                }
                else if (pointSituation == PointVectorRelation.LiesRight)
                {
                    result.RemoveAt(result.Count - 1);
                }
                else
                {
                    if (sortedPoints[counter].Value == sortedPoints[0].Value)
                    {
                        if (CalculateDistance(initialPoint, tempPoint) > CalculateDistance(initialPoint, result[result.Count - 1]))
                        {
                            result.Add(tempPoint);
                        }

                        counter++;
                    }
                    else if (sortedPoints[counter].Value == sortedPoints[length - 2].Value)
                    {
                        if (CalculateDistance(initialPoint, tempPoint) < CalculateDistance(initialPoint, result[result.Count - 1]))
                        {
                            result.Add(tempPoint);
                        }

                        counter++;
                    }
                    else
                    {
                        result.RemoveAt(result.Count - 1);
                    }
                }
            }

            return(result);
        }
示例#28
0
        public static void ED(string inputFileName, string queryFileName, int queryLength)
        {
            FileStream fp = null;
            FileStream qp = null;

            double[] Q = null; // query array
            double[] T = null; // array of current data
            long[]   order;    // ordering of query by |z(q_i)|
            double   bsf;      // best-so-far
            int      m;        // length of query
            long     loc = 0;  // answer: location of the best-so-far match

            double d;
            int    i, j;
            double ex, ex2, mean, std;

            double t1, t2;

            t1 = DateTime.Now.Ticks;

            bsf = double.PositiveInfinity;
            i   = 0;
            j   = 0;
            ex  = ex2 = 0;

            try
            {
                using (qp = File.OpenRead(queryFileName))
                {
                    m = queryLength;

                    // Array for keeping the query data
                    Q = new double[m];
                    // Read the query data from input file and calculate its statistic such as mean, std

                    using (TextReader reader = new StreamReader(qp))
                    {
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            string[] strs = line.Split(' ');

                            for (int k = 0; k < strs.Length && i < m; k++)
                            {
                                if (String.IsNullOrEmpty(strs[k]))
                                {
                                    continue;
                                }
                                d = double.Parse(strs[k]);

                                ex  += d;
                                ex2 += d * d;
                                Q[i] = d;
                                i++;
                            }
                        }
                    }

                    mean = ex / m;
                    std  = ex2 / m;
                    std  = (double)Math.Sqrt(std - mean * mean);
                }

                // Do z_normalixation on query data
                for (i = 0; i < m; i++)
                {
                    Q[i] = (Q[i] - mean) / std;
                }


                // Array for keeping the query data
                order = new long[m];                 // (double *)malloc(sizeof(double)*m);

                IndexValue[] Q_tmp = new IndexValue[m];

                for (i = 0; i < m; i++)
                {
                    Q_tmp[i].Value = Q[i];
                    Q_tmp[i].Index = i;
                }

                // Sort the query data
                Array.Sort(Q_tmp, Comp);

                for (i = 0; i < m; i++)
                {
                    Q[i]     = Q_tmp[i].Value;
                    order[i] = Q_tmp[i].Index;
                }

                // Array for keeping the current data; Twice the size for removing modulo (circulation) in distance calculation
                T = new double[2 * m];               //(double *)malloc(sizeof(double)*2*m);

                double dist = 0;
                i  = 0;
                j  = 0;
                ex = ex2 = 0;

                using (fp = File.OpenRead(inputFileName))
                {
                    // Read data file, one row at a time
                    using (TextReader reader = new StreamReader(fp))
                    {
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            string[] strs = line.Split(' ');

                            for (int k = 0; k < strs.Length; k++)
                            {
                                if (String.IsNullOrEmpty(strs[k]))
                                {
                                    continue;
                                }
                                d = double.Parse(strs[k]);

                                ex            += d;
                                ex2           += d * d;
                                T[i % m]       = d;
                                T[(i % m) + m] = d;

                                // If there is enough data in T, the ED distance can be calculated
                                if (i >= m - 1)
                                {
                                    // the current starting location of T
                                    j = (i + 1) % m;

                                    // Z_norm(T[i]) will be calculated on the fly
                                    mean = ex / m;
                                    std  = ex2 / m;
                                    std  = (double)Math.Sqrt(std - mean * mean);

                                    // Calculate ED distance
                                    dist = distance(Q, T, j, m, mean, std, order, bsf);
                                    if (dist < bsf)
                                    {
                                        bsf = dist;
                                        loc = i - m + 1;
                                    }
                                    ex  -= T[j];
                                    ex2 -= T[j] * T[j];
                                }
                                i++;
                            }
                        }
                    }
                }
                t2 = DateTime.Now.Ticks;

                Console.WriteLine("Location : " + loc);
                Console.WriteLine("Distance : " + Math.Sqrt(bsf));
                Console.WriteLine("Data Scanned : " + i);
                Console.WriteLine("Total Execution Time : " + (t2 - t1) / TimeSpan.TicksPerSecond + " sec");
            }
            catch (OutOfMemoryException)
            {
                error_ed(1);
            }
            catch (FileNotFoundException)
            {
                error_ed(2);
            }
            catch (Exception)
            {
                Environment.Exit(2);
            }
        }
示例#29
0
 /// Comparison function for sorting the query.
 /// The query will be sorted by absolute z-normalization value, |z_norm(Q[i])| from high to low.
 private static int Comp(IndexValue a, IndexValue b)
 {
     return(Convert.ToInt16(Math.Abs(b.Value) - Math.Abs(a.Value)));
 }
示例#30
0
 private bool IsWildcardPredicate(IndexField field, IndexValue predicationValue)
 {
     return(predicationValue.Type == IndexValueType.String && field.Type == IndexValueType.String &&
            (predicationValue.StringValue.Contains("*") || predicationValue.StringValue.Contains("?")));
 }