Clone() static private method

static private Clone ( JToken value ) : JToken
value JToken
return JToken
コード例 #1
0
        /// <exception cref="JsonLD.Core.JsonLdError"></exception>
        public static JObject Frame(JToken input, JToken frame, JsonLdOptions
                                    options)
        {
            if (frame is JObject)
            {
                frame = JsonLdUtils.Clone((JObject)frame);
            }
            // TODO string/IO input
            JToken    expandedInput = Expand(input, options);
            JArray    expandedFrame = Expand(frame, options);
            JsonLdApi api           = new JsonLdApi(expandedInput, options);
            JArray    framed        = api.Frame(expandedInput, expandedFrame);
            Context   activeCtx     = api.context.Parse(frame["@context"
                                                        ]);
            JToken compacted = api.Compact(activeCtx, null, framed);

            if (!(compacted is JArray))
            {
                JArray tmp = new JArray();
                tmp.Add(compacted);
                compacted = tmp;
            }
            string  alias = activeCtx.CompactIri("@graph");
            JObject rval  = activeCtx.Serialize();

            rval[alias] = compacted;
            JsonLdUtils.RemovePreserve(activeCtx, rval, options);
            return(rval);
        }
コード例 #2
0
 /// <summary>Copies this UniqueNamer.</summary>
 /// <remarks>Copies this UniqueNamer.</remarks>
 /// <returns>a copy of this UniqueNamer.</returns>
 public virtual JsonLD.Core.UniqueNamer Clone()
 {
     JsonLD.Core.UniqueNamer copy = new JsonLD.Core.UniqueNamer(this.prefix);
     copy.counter  = this.counter;
     copy.existing = (JObject)JsonLdUtils.Clone(this.existing);
     return(copy);
 }
コード例 #3
0
        /// <summary>Copies this UniqueNamer.</summary>
        /// <remarks>Copies this UniqueNamer.</remarks>
        /// <returns>a copy of this UniqueNamer.</returns>
        public virtual UniqueNamer Clone()
        {
            var copy = new UniqueNamer(prefix);

            copy.counter  = counter;
            copy.existing = (JObject)JsonLdUtils.Clone(existing);
            return(copy);
        }
コード例 #4
0
 public Permutator(JArray list)
 {
     this.list = (JArray)JsonLdUtils.Clone(list);
     this.list.SortInPlace();
     this.done = false;
     this.left = new Dictionary <string, bool>();
     foreach (string i in this.list)
     {
         this.left[i] = true;
     }
 }
コード例 #5
0
            /// <summary>Gets the next permutation.</summary>
            /// <remarks>
            ///     Gets the next permutation. Call hasNext() to ensure there is another
            ///     one first.
            /// </remarks>
            /// <returns>the next permutation.</returns>
            public virtual JArray Next()
            {
                var rval = (JArray)JsonLdUtils.Clone(list);

                // Calculate the next permutation using Steinhaus-Johnson-Trotter
                // permutation algoritm
                // get largest mobile element k
                // (mobile: element is grater than the one it is looking at)
                string k      = null;
                var    pos    = 0;
                var    length = list.Count;

                for (var i = 0; i < length; ++i)
                {
                    var element = (string)list[i];
                    var left    = this.left[element];
                    if ((k == null || string.CompareOrdinal(element, k) > 0) &&
                        (left && i > 0 && string.CompareOrdinal(element, (string)list[i - 1]) > 0 ||
                         !left && i < length - 1 && string.CompareOrdinal(element, (string)list[i + 1]) > 0))
                    {
                        k   = element;
                        pos = i;
                    }
                }

                // no more permutations
                if (k == null)
                {
                    done = true;
                }
                else
                {
                    // swap k and the element it is looking at
                    var swap = left[k] ? pos - 1 : pos + 1;
                    list[pos]  = list[swap];
                    list[swap] = k;

                    // reverse the direction of all element larger than k
                    for (var i_1 = 0; i_1 < length; i_1++)
                    {
                        if (string.CompareOrdinal((string)list[i_1], k) > 0)
                        {
                            left[(string)list[i_1]] = !left[(string)list[i_1]];
                        }
                    }
                }

                return(rval);
            }
コード例 #6
0
        /// <exception cref="JsonLdError"></exception>
        public static async Task <JObject> FrameAsync(JToken input,
                                                      JToken frame,
                                                      JsonLdOptions options)
        {
            if (frame is JObject)
            {
                frame = JsonLdUtils.Clone((JObject)frame);
            }

            // TODO string/IO input
            JToken expandedInput = await ExpandAsync(input, options);

            var expandedFrame = await ExpandAsync(frame, options);

            var api = await JsonLdApi.CreateAsync(expandedInput, options);

            var framed    = api.Frame(expandedInput, expandedFrame);
            var activeCtx = await api.context.ParseAsync(frame["@context"
                                                         ]);

            var compacted = api.Compact(activeCtx, null, framed);

            if (!(compacted is JArray))
            {
                compacted = new JArray {
                    compacted
                };
            }

            var alias = activeCtx.CompactIri("@graph");
            var rval  = activeCtx.Serialize();

            rval[alias] = compacted;
            JsonLdUtils.RemovePreserve(activeCtx, rval, options);
            return(rval);
        }
コード例 #7
0
ファイル: Urdna2015.cs プロジェクト: FluidChains/json-ld.net
        private static IDictionary <string, string> modifyFirstDegreeComponent(IDictionary <string, string> component, string id)
        {
            if (!component["type"].Equals("blank node"))
            {
                return(component);
            }

            IDictionary <string, string> componentClone = (IDictionary <string, string>)JsonLdUtils.Clone(JToken.FromObject(component));

            if (componentClone["value"].Equals(id))
            {
                componentClone["value"] = "_:a";
            }
            else
            {
                componentClone["value"] = "_:z";
            }
            return(componentClone);
        }