Пример #1
0
        public bool Contains(string nodeId, DvText name)
        {
            Check.Invariant(identifiedLocatables != null, "identifiedLocatables must not be null");

            Check.Require(!string.IsNullOrEmpty(nodeId), "nodeId must not be null or empty");
            Check.Require(name != null, "name must not be null");

            LocatableBindingListView <T> namedLocatables = null;

            if (identifiedLocatables.ContainsKey(nodeId))
            {
                namedLocatables = identifiedLocatables[nodeId];
            }

            bool result = false;

            if (namedLocatables != null)
            {
                DvCodedText codedName = name as DvCodedText;
                if (codedName == null)
                {
                    result = namedLocatables.Contains(name.Value);
                }

                else
                {
                    CodePhrase definingCode = codedName.DefiningCode;
                    result = namedLocatables.Contains(definingCode.TerminologyId.Value, definingCode.CodeString);
                }
            }

            return(result);
        }
Пример #2
0
            private void GetSlotNames(int col, ref VBuffer <DvText> dst)
            {
                Contracts.Assert(col == 0);

                var nameList  = new List <DvText>();
                var indexList = new List <int>();

                foreach (var kvp in _collection.GetNonDefaultFeatureNames())
                {
                    nameList.Add(new DvText(kvp.Value));
                    indexList.Add(kvp.Key);
                }

                var vals = dst.Values;

                if (Utils.Size(vals) < nameList.Count)
                {
                    vals = new DvText[nameList.Count];
                }
                Array.Copy(nameList.ToArray(), vals, nameList.Count);
                if (nameList.Count < _collection.Count)
                {
                    var indices = dst.Indices;
                    if (Utils.Size(indices) < indexList.Count)
                    {
                        indices = new int[indexList.Count];
                    }
                    Array.Copy(indexList.ToArray(), indices, indexList.Count);
                    dst = new VBuffer <DvText>(_collection.Count, nameList.Count, vals, indices);
                }
                else
                {
                    dst = new VBuffer <DvText>(_collection.Count, vals, dst.Indices);
                }
            }
Пример #3
0
        public string GetContent(int ifeat)
        {
            Contracts.Assert(0 <= ifeat && ifeat < Count);
            DvText content = _content.GetItemOrDefault(ifeat);

            return(content.HasChars ? content.ToString() : DatasetUtils.GetDefaultTransform(GetName(ifeat)));
        }
Пример #4
0
        public Action(DvText name, string archetypeNodeId, UidBasedId uid,
                      Link[] links, Archetyped archetypeDetails, FeederAudit feederAudit,
                      CodePhrase language, CodePhrase encoding, PartyProxy subject, PartyProxy proider,
                      Participation[] otherParticipations, ObjectRef workflowId, ItemStructure protocol,
                      ObjectRef guidelineId, DvDateTime time, ItemStructure description,
                      IsmTransition ismTransition, InstructionDetails instructionDetails)
            : base(name, archetypeNodeId, uid, links, archetypeDetails, feederAudit, language,
                   encoding, subject, proider, otherParticipations, workflowId, protocol, guidelineId)
        {
            Check.Require(time != null, "time must not be null");
            Check.Require(description != null, "description must not be null");
            Check.Require(ismTransition != null, "ismTransition must not be null");

            this.time        = time;
            this.description = description;
            if (this.description != null)
            {
                this.description.Parent = this;
            }
            this.ismTransition = ismTransition;
            if (this.ismTransition != null)
            {
                this.ismTransition.Parent = this;
            }
            this.instructionDetails = instructionDetails;
            if (this.instructionDetails != null)
            {
                this.instructionDetails.Parent = this;
            }

            SetAttributeDictionary();
            CheckInvariants();
        }
Пример #5
0
        public Composition(DvText name, string archetypeNodeId, Support.Identification.UidBasedId uid,
                           Link[] links, Archetyped archetypeDetails, FeederAudit feederAudit,
                           CodePhrase language, CodePhrase territory, DvCodedText category, EventContext context,
                           Content.ContentItem[] content, PartyProxy composer) :
            base(name, archetypeNodeId, uid, links, archetypeDetails, feederAudit)
        {
            Check.Require(language != null, "language must not be null");
            Check.Require(territory != null, "territory must not be null");
            Check.Require(category != null, "category must not be null");
            Check.Require(composer != null, "composer must not be null");


            this.language  = language;
            this.territory = territory;
            this.category  = category;
            this.context   = context;
            if (this.context != null)
            {
                this.context.Parent = this;
            }
            if (content != null)
            {
                this.content = RmFactory.LocatableList <ContentItem>(this, content);
            }

            this.composer = composer;

            SetAttributeDictionary();
            this.CheckInvariants();
        }
Пример #6
0
        public string GetName(int ifeat)
        {
            Contracts.Assert(0 <= ifeat && ifeat < Count);
            DvText name = _names.GetItemOrDefault(ifeat);

            return(name.HasChars ? name.ToString() : string.Format("f{0}", ifeat));
        }
Пример #7
0
        protected DemographicLocatable(string archetypeNodeId, DvText name)
        {
            ArchetypeNodeId = archetypeNodeId;
            Name            = name;

            CheckInvariants();
        }
 public XmlSerializableExtract(string archetypeNodeId, DvText name, HierObjectId systemId, ExtractChapter[] chapters)
     : base(archetypeNodeId, name, systemId)
 {
     foreach (ExtractChapter chapter in chapters)
     {
         this.Chapters.Add(chapter);
     }
 }
Пример #9
0
 public PointEvent(DvText name, string archetypeNodeId, Support.Identification.UidBasedId uid,
                   Link[] links, Archetyped archetypeDetails, FeederAudit feederAudit,
                   DvDateTime time, T data,
                   ItemStructure.ItemStructure state)
     : base(name, archetypeNodeId, uid, links, archetypeDetails, feederAudit, time, data, state)
 {
     SetAttributeDictionary();
     CheckInvariants();
 }
Пример #10
0
        public void CanSuccessfullyRetrieveQuotedData()
        {
            string dataPath = GetDataPath("QuotingData.csv");
            var    loader   = new Data.TextLoader(dataPath).CreateFrom <QuoteInput>(useHeader: true, separator: ',', allowQuotedStrings: true, supportSparse: false);

            using (var environment = new TlcEnvironment())
            {
                Experiment experiment            = environment.CreateExperiment();
                ILearningPipelineDataStep output = loader.ApplyStep(null, experiment) as ILearningPipelineDataStep;

                experiment.Compile();
                loader.SetInput(environment, experiment);
                experiment.Run();

                IDataView data = experiment.GetOutput(output.Data);
                Assert.NotNull(data);

                using (var cursor = data.GetRowCursor((a => true)))
                {
                    var IDGetter   = cursor.GetGetter <float>(0);
                    var TextGetter = cursor.GetGetter <DvText>(1);

                    Assert.True(cursor.MoveNext());

                    float ID = 0;
                    IDGetter(ref ID);
                    Assert.Equal(1, ID);

                    DvText Text = new DvText();
                    TextGetter(ref Text);
                    Assert.Equal("This text contains comma, within quotes.", Text.ToString());

                    Assert.True(cursor.MoveNext());

                    ID = 0;
                    IDGetter(ref ID);
                    Assert.Equal(2, ID);

                    Text = new DvText();
                    TextGetter(ref Text);
                    Assert.Equal("This text contains extra punctuations and special characters.;*<>?!@#$%^&*()_+=-{}|[]:;'", Text.ToString());

                    Assert.True(cursor.MoveNext());

                    ID = 0;
                    IDGetter(ref ID);
                    Assert.Equal(3, ID);

                    Text = new DvText();
                    TextGetter(ref Text);
                    Assert.Equal("This text has no quotes", Text.ToString());

                    Assert.False(cursor.MoveNext());
                }
            }
        }
Пример #11
0
        public int AddColumn(string name, ReadOnlyMemory <char>[] values)
        {
            var buf = new DvText[values.Length];

            for (int i = 0; i < values.Length; ++i)
            {
                buf[i] = new DvText(values[i]);
            }
            return(AddColumn(name, new DataColumn <DvText>(buf)));
        }
Пример #12
0
        public static void AddColumnToDataFrameString(DataFrame df, string name, string[] values)
        {
            var bval = new DvText[values.Length];

            for (int i = 0; i < values.Length; ++i)
            {
                bval[i] = new DvText(values[i]);
            }
            df.AddColumn(name, bval);
        }
Пример #13
0
        public Element(DvText name, string archetypeNodeId, Support.Identification.UidBasedId uid,
                       Link[] links, Archetyped archetypeDetails, FeederAudit feederAudit,
                       DataValue value, DvCodedText nullFlavour)
            : base(name, archetypeNodeId, uid, links, archetypeDetails, feederAudit)
        {
            this.value       = value;
            this.nullFlavour = nullFlavour;

            SetAttributeDictionary();
            CheckInvariants();
        }
 private void AddTokenAndType(string text, int startIndex, int length, string type)
 {
     Contracts.AssertValue(_tokensList);
     if (length > 0)
     {
         int lim = startIndex + length;
         var token = new DvText(text, startIndex, lim);
         _tokensList.Add(token);
         if (_typesList != null)
             _typesList.Add(new DvText(type));
     }
 }
Пример #15
0
        public Section(DvText name, string archetypeNodeId, Support.Identification.UidBasedId uid,
                       Link[] links, Archetyped archetypeDetails, FeederAudit feederAudit, ContentItem[] items)
            : base(name, archetypeNodeId, uid, links, archetypeDetails, feederAudit)
        {
            if (items != null)
            {
                this.items = RmFactory.LocatableList <ContentItem>(this, items);
            }

            SetAttributeDictionary();
            CheckInvariants();
        }
Пример #16
0
        public ItemTable(DvText name, string archetypeNodeId, Support.Identification.UidBasedId uid,
                         Link[] links, Archetyped archetypeDetails, FeederAudit feederAudit, Cluster[] rows)
            : base(name, archetypeNodeId, uid, links, archetypeDetails, feederAudit)
        {
            if (rows != null)
            {
                this.rows = RmFactory.LocatableList <Cluster>(this, rows);
            }

            SetAttributeDictionary();
            CheckInvariants();
        }
 public static void Convert <T>(ref object src, out T value)
 {
     if ((src as string) != null)
     {
         var dv = new DvText((string)src);
         value = (T)(object)dv;
     }
     else
     {
         value = (T)src;
     }
 }
            /// <summary>
            /// Add tokens (and types if required) that are computed for src to _tokensList/_typesList.
            /// </summary>
            private void Tokenize(ref DvText src, Language lang, GetSpansSimpleCallback addTokenAndType)
            {
                Contracts.Assert(_typesList == null || _tokensList.Count == _typesList.Count);

                if (!src.HasChars)
                    return;

                int ichMin;
                int ichLim;
                string text = src.GetRawUnderlyingBufferInfo(out ichMin, out ichLim);
                Tokenizers[(int)lang].GetSpansSimple(text, ichMin, ichLim - ichMin, addTokenAndType);
                Contracts.Assert(_typesList == null || _tokensList.Count == _typesList.Count);
            }
                private Delegate CreateStringToTextGetter(int index)
                {
                    var peek = DataView._peeks[index] as Peek <TRow, string>;

                    Ch.AssertValue(peek);
                    string buf = null;

                    return((ValueGetter <DvText>)((ref DvText dst) =>
                    {
                        peek(GetCurrentRowObject(), Position, ref buf);
                        dst = new DvText(buf);
                    }));
                }
        private PipelineItemDebugRow[] BuildRows()
        {
            PipelineItemDebugRow[] result = new PipelineItemDebugRow[MaxDisplayRows];

            int       i = 0;
            IDataView pipelineResult = ExecutePipeline();

            if (_pipelineExecutionException != null)
            {
                result[0] = new PipelineItemDebugRow()
                {
                    Values = _pipelineExecutionException.ToString()
                };
                return(result);
            }

            StringBuilder valuesBuilder = new StringBuilder();

            using (var cursor = pipelineResult.GetRowCursor(c => true))
            {
                var colIndices = GetColIndices(pipelineResult);
                var colCount   = colIndices.Count;

                var getters = DataViewUtils.PopulateGetterArray(cursor, colIndices);

                var row = new DvText[colCount];
                while (cursor.MoveNext() && i < MaxDisplayRows)
                {
                    for (int column = 0; column < colCount; column++)
                    {
                        if (column != 0)
                        {
                            valuesBuilder.Append(" | ");
                        }

                        getters[column](ref row[column]);
                        valuesBuilder.Append(row[column]);
                    }

                    result[i] = new PipelineItemDebugRow()
                    {
                        Values = valuesBuilder.ToString()
                    };

                    valuesBuilder.Clear();
                    i++;
                }
            }

            return(result);
        }
Пример #21
0
        protected Locatable(DvText name, string archetypeNodeId, Support.Identification.UidBasedId uid,
                            AssumedTypes.List <Link> links, Archetyped archetypeDetails, FeederAudit feederAudit)
            : this()
        {
            Check.Require(name != null, "name must not be null");
            Check.Require(!string.IsNullOrEmpty(archetypeNodeId), "archetype_node_id must not be null or empty");

            this.name             = name;
            this.archetypeNodeId  = archetypeNodeId;
            this.uid              = uid;
            this.links            = links;
            this.archetypeDetails = archetypeDetails;
            this.feederAudit      = feederAudit;
        }
Пример #22
0
        Cluster CreateClusterPersonName(Patient patient)
        {
            string archetypeNodeId = "openEHR-EHR-CLUSTER.person_name.v1";

            var name   = new DvText("Paciente");
            var at0006 = new Element(new DvText("Name type"), "at0006", null, null, null, null, new DvText("Registered name"), null);
            var at0020 = new Element(new DvText("Registered name"), "at0006", null, null, null, null, new DvCodedText(patient.Name, "at0020", "local"), null);

            var cluster = new Cluster(name, archetypeNodeId, null, null, GetArchetypeDetails(archetypeNodeId), null, new Item[2] {
                at0006, at0020
            });

            return(cluster);
        }
Пример #23
0
        Cluster CreateClusterMedicalDevice()
        {
            string archetypeNodeId = "openEHR-EHR-CLUSTER.device.v1";

            var name   = new DvText("Dispositivo");
            var at0001 = new Element(new DvText("Name"), "at0001", null, null, null, null, new DvText("Bitalino"), null);
            var at0002 = new Element(new DvText("Description"), "at0002", null, null, null, null, new DvText("O BITalino é um kit de ferramentas de hardware e software especificamente projetado para lidar com os requisitos dos sinais corporais."), null);

            var cluster = new Cluster(name, archetypeNodeId, null, null, GetArchetypeDetails(archetypeNodeId), null, new Item[2] {
                at0001, at0002
            });

            return(cluster);
        }
            private void UpdateLanguage(ref Language langToUse, ref DvText langTxt)
            {
                if (_langGetter != null)
                {
                    _langGetter(ref langTxt);
                    Language lang;
                    if (!langTxt.IsNA && LangsDictionary.TryGetValue(langTxt, out lang))
                        langToUse = lang;
                }

                if (!ResourceExists(langToUse))
                    langToUse = Language.Default;
                AddResourceIfNotPresent(langToUse);
            }
Пример #25
0
            private static Action <TRow> CreateTextToStringSetter(IRow input, int col, Delegate poke)
            {
                var getter    = input.GetGetter <DvText>(col);
                var typedPoke = poke as Poke <TRow, string>;

                Contracts.AssertValue(typedPoke);
                DvText value = default(DvText);

                return(row =>
                {
                    getter(ref value);
                    typedPoke(row, value.ToString());
                });
            }
Пример #26
0
        public void TestSaveImages()
        {
            using (var env = new ConsoleEnvironment())
            {
                var dataFile    = GetDataPath("images/images.tsv");
                var imageFolder = Path.GetDirectoryName(dataFile);
                var data        = env.CreateLoader("Text{col=ImagePath:TX:0 col=Name:TX:1}", new MultiFileSource(dataFile));
                var images      = ImageLoaderTransform.Create(env, new ImageLoaderTransform.Arguments()
                {
                    Column = new ImageLoaderTransform.Column[1]
                    {
                        new ImageLoaderTransform.Column()
                        {
                            Source = "ImagePath", Name = "ImageReal"
                        }
                    },
                    ImageFolder = imageFolder
                }, data);

                IDataView cropped = ImageResizerTransform.Create(env, new ImageResizerTransform.Arguments()
                {
                    Column = new ImageResizerTransform.Column[1] {
                        new ImageResizerTransform.Column()
                        {
                            Name = "ImageCropped", Source = "ImageReal", ImageHeight = 100, ImageWidth = 100, Resizing = ImageResizerTransform.ResizingKind.IsoPad
                        }
                    }
                }, images);

                cropped.Schema.TryGetColumnIndex("ImagePath", out int pathColumn);
                cropped.Schema.TryGetColumnIndex("ImageCropped", out int cropBitmapColumn);
                using (var cursor = cropped.GetRowCursor((x) => true))
                {
                    var    pathGetter       = cursor.GetGetter <DvText>(pathColumn);
                    DvText path             = default;
                    var    bitmapCropGetter = cursor.GetGetter <Bitmap>(cropBitmapColumn);
                    Bitmap bitmap           = default;
                    while (cursor.MoveNext())
                    {
                        pathGetter(ref path);
                        bitmapCropGetter(ref bitmap);
                        Assert.NotNull(bitmap);
                        var fileToSave = GetOutputPath(Path.GetFileNameWithoutExtension(path.ToString()) + ".cropped.jpg");
                        bitmap.Save(fileToSave, System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                }
            }
            Done();
        }
        protected override Delegate GetGetterCore(IChannel ch, IRow input, int iinfo, out Action disposer)
        {
            Host.AssertValue(ch, nameof(ch));
            Host.AssertValue(input);
            Host.Assert(0 <= iinfo && iinfo < Infos.Length);
            disposer = null;

            var    getSrc            = GetSrcGetter <DvText>(input, iinfo);
            DvText src               = default;
            ValueGetter <Bitmap> del =
                (ref Bitmap dst) =>
            {
                if (dst != null)
                {
                    dst.Dispose();
                    dst = null;
                }

                getSrc(ref src);

                if (src.Length > 0)
                {
                    // Catch exceptions and pass null through. Should also log failures...
                    try
                    {
                        string path = src.ToString();
                        if (!string.IsNullOrWhiteSpace(_imageFolder))
                        {
                            path = Path.Combine(_imageFolder, path);
                        }
                        dst = new Bitmap(path);
                    }
                    catch (Exception e)
                    {
                        // REVIEW: We catch everything since the documentation for new Bitmap(string)
                        // appears to be incorrect. When the file isn't found, it throws an ArgumentException,
                        // while the documentation says FileNotFoundException. Not sure what it will throw
                        // in other cases, like corrupted file, etc.

                        // REVIEW : Log failures.
                        ch.Info(e.Message);
                        ch.Info(e.StackTrace);
                        dst = null;
                    }
                }
            };

            return(del);
        }
Пример #28
0
        public ItemSingle(DvText name, string archetypeNodeId, Support.Identification.UidBasedId uid,
                          Link[] links, Archetyped archetypeDetails, FeederAudit feederAudit, Element item)
            : base(name, archetypeNodeId, uid, links, archetypeDetails, feederAudit)
        {
            Check.Require(item != null, "item must not be null");

            this.item = item;
            if (this.item != null)
            {
                this.item.Parent = this;
            }

            SetAttributeDictionary();
            CheckInvariants();
        }
Пример #29
0
        protected CareEntry(DvText name, string archetypeNodeId, Support.Identification.UidBasedId uid,
                            Link[] links, Archetyped archetypeDetails, FeederAudit feederAudit,
                            CodePhrase language, CodePhrase encoding, PartyProxy subject, PartyProxy proider,
                            Participation[] otherParticipations, ObjectRef workflowId, ItemStructure protocol,
                            ObjectRef guidelineId)
            : base(name, archetypeNodeId, uid, links, archetypeDetails, feederAudit,
                   language, encoding, subject, proider, otherParticipations, workflowId)
        {
            this.protocol = protocol;
            if (this.protocol != null)
            {
                this.protocol.Parent = this;
            }

            this.guidelineId = guidelineId;
        }
Пример #30
0
        public AdminEntry(DvText name, string archetypeNodeId, Support.Identification.UidBasedId uid,
                          Link[] links, Archetyped archetypeDetails, FeederAudit feederAudit,
                          CodePhrase language, CodePhrase encoding, PartyProxy subject, PartyProxy proider,
                          Participation[] otherParticipations, ObjectRef workflowId,
                          ItemStructure data)
            : base(name, archetypeNodeId, uid, links, archetypeDetails,
                   feederAudit, language, encoding, subject, proider, otherParticipations, workflowId)
        {
            Check.Require(data != null, "data must not be null");

            this.data        = data;
            this.data.Parent = this;

            SetAttributeDictionary();
            this.CheckInvariants();
        }