Пример #1
0
        internal GraphObject(JValue data)
        {
            GraphObject t = null;

            switch (data.Type)
            {
            case JTokenType.String:
            case JTokenType.Date:
            case JTokenType.TimeSpan:
            case JTokenType.Guid:
            case JTokenType.Uri:
                t = GraphObject.FromData(data.ToString());
                break;

            case JTokenType.Integer:
                t = GraphObject.FromData(data.Value <long>());
                break;

            case JTokenType.Boolean:
                t = GraphObject.FromData(data.Value <bool>());
                break;

            case JTokenType.Float:
                t = GraphObject.FromData(data.Value <double>());
                break;

            default:
                throw new InvalidOperationException($"{data.Type} not support as object");
            }
            IsID   = t.IsID;
            _value = t._value;
        }
Пример #2
0
 public static void RetractByObject(this IGraph graph, GraphObject o)
 {
     foreach (var t in graph.GetByObject(o).ToList())
     {
         graph.Retract(t);
     }
 }
Пример #3
0
        // implementation of framing/compact processing

        private static JToken ProcessObject(WriteContext context, IGraph graph, GraphObject o)
        {
            if (o.IsID)
            {
                return(ProcessSubject(context, graph, o.Id));
            }
            else
            {
                return(JToken.Parse(o.ToJSON()));
            }
        }
Пример #4
0
        public bool Exists(string ts, string tp, GraphObject to)
        {
            IDictionary <string, ISet <GraphObject> > po;

            if (_spo.TryGetValue(ts, out po))
            {
                ISet <GraphObject> o;
                if (po.TryGetValue(tp, out o))
                {
                    return(o.Contains(to));
                }
            }
            return(false);
        }
Пример #5
0
 private void InnerWriteObject(GraphObject o)
 {
     if (o.IsID)
     {
         _writer.WriteStartObject();
         _writer.WritePropertyName("@id");
         _writer.WriteValue(o.Id);
         _writer.WriteEndObject();
     }
     else
     {
         _writer.WriteRawValue(o.ToJSON());
     }
 }
Пример #6
0
        public IEnumerable <Triple> GetByObject(GraphObject to)
        {
            IDictionary <string, ISet <string> > sp;

            if (_osp.TryGetValue(to, out sp))
            {
                foreach (var s in sp)
                {
                    foreach (var p in s.Value)
                    {
                        yield return(new Triple(s.Key, p, to));
                    }
                }
            }
        }
Пример #7
0
        public IEnumerable <Triple> GetByObjectSubject(GraphObject to, string ts)
        {
            IDictionary <string, ISet <string> > sp;

            if (_osp.TryGetValue(to, out sp))
            {
                ISet <string> p;
                if (sp.TryGetValue(ts, out p))
                {
                    foreach (var tp in p)
                    {
                        yield return(new Triple(ts, tp, to));
                    }
                }
            }
        }
Пример #8
0
        public IEnumerable <Triple> GetByPredicateObject(string tp, GraphObject to)
        {
            IDictionary <GraphObject, ISet <string> > os;

            if (_pos.TryGetValue(tp, out os))
            {
                ISet <string> s;
                if (os.TryGetValue(to, out s))
                {
                    foreach (var ts in s)
                    {
                        yield return(new Triple(ts, tp, to));
                    }
                }
            }
        }
Пример #9
0
        public bool Retract(string s, string p, GraphObject o)
        {
            if (s == null || p == null || o == null || o.IsNull)
            {
                return(false);
            }

            if (Retract(_spo, s, p, o))
            {
                if (Retract(_pos, p, o, s))
                {
                    if (Retract(_osp, o, s, p))
                    {
                        Count--;
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #10
0
 public IEnumerable <Triple> GetByObjectSubject(GraphObject to, string ts)
 {
     return(_innerGraph.GetByObjectSubject(to, ts));
 }
Пример #11
0
 public void WriteObject(GraphObject o)
 {
     _currentObjects.Add(o);
 }
Пример #12
0
 public Triple(string s, string p, GraphObject o)
 {
     Subject   = s;
     Predicate = p;
     Object    = o;
 }
Пример #13
0
 public bool Assert(string s, string p, GraphObject o)
 {
     return(Assert(new Triple(s, p, o)));
 }
Пример #14
0
 public bool Exists(string ts, string tp, GraphObject to)
 {
     return(_innerGraph.Exists(ts, tp, to));
 }
Пример #15
0
 public IEnumerable <Triple> GetByPredicateObject(string tp, GraphObject to)
 {
     return(_innerGraph.GetByPredicateObject(tp, to));
 }
Пример #16
0
 public IEnumerable <Triple> GetByObject(GraphObject to)
 {
     return(_innerGraph.GetByObject(to));
 }
Пример #17
0
 public bool Retract(string s, string p, GraphObject o)
 {
     return(Retract(new Triple(s, p, o)));
 }