Example #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;
        }
Example #2
0
 public static void RetractByObject(this IGraph graph, GraphObject o)
 {
     foreach (var t in graph.GetByObject(o).ToList())
     {
         graph.Retract(t);
     }
 }
Example #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()));
            }
        }
Example #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);
        }
Example #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());
     }
 }
Example #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));
                    }
                }
            }
        }
Example #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));
                    }
                }
            }
        }
Example #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));
                    }
                }
            }
        }
Example #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);
        }
Example #10
0
 public IEnumerable <Triple> GetByObjectSubject(GraphObject to, string ts)
 {
     return(_innerGraph.GetByObjectSubject(to, ts));
 }
Example #11
0
 public void WriteObject(GraphObject o)
 {
     _currentObjects.Add(o);
 }
Example #12
0
 public Triple(string s, string p, GraphObject o)
 {
     Subject   = s;
     Predicate = p;
     Object    = o;
 }
Example #13
0
 public bool Assert(string s, string p, GraphObject o)
 {
     return(Assert(new Triple(s, p, o)));
 }
Example #14
0
 public bool Exists(string ts, string tp, GraphObject to)
 {
     return(_innerGraph.Exists(ts, tp, to));
 }
Example #15
0
 public IEnumerable <Triple> GetByPredicateObject(string tp, GraphObject to)
 {
     return(_innerGraph.GetByPredicateObject(tp, to));
 }
Example #16
0
 public IEnumerable <Triple> GetByObject(GraphObject to)
 {
     return(_innerGraph.GetByObject(to));
 }
Example #17
0
 public bool Retract(string s, string p, GraphObject o)
 {
     return(Retract(new Triple(s, p, o)));
 }