Esempio n. 1
0
 /// <summary>
 ///     Yields and enumeration over the triples in the collection that match the provided pattern.
 /// </summary>
 /// <param name="matchPattern">
 ///     The match pattern specified as a triple where a wildcard match for Subject, Predicate,
 ///     Object or Graph can be specified using NULL
 /// </param>
 /// <returns></returns>
 public IEnumerable <ITriple> GetMatches(ITriple matchPattern)
 {
     if (matchPattern == null)
     {
         throw new ArgumentNullException("matchPattern");
     }
     if (matchPattern.Subject == null)
     {
         foreach (ITriple t in _tripleIndex.Values.SelectMany(subjIndex => GetMatches(subjIndex, matchPattern)))
         {
             yield return(t);
         }
     }
     else
     {
         Dictionary <string, HashSet <ITriple> > si;
         if (_tripleIndex.TryGetValue(matchPattern.Subject, out si))
         {
             foreach (ITriple t in GetMatches(si, matchPattern))
             {
                 yield return(t);
             }
         }
     }
 }
Esempio n. 2
0
        public void Add(ITriple triple)
        {
            if (triple == null)
            {
                throw new ArgumentNullException("triple");
            }
            Dictionary <string, HashSet <ITriple> > subjIndex;

            if (!_tripleIndex.TryGetValue(triple.Subject, out subjIndex))
            {
                _tripleIndex.Add(triple.Subject,
                                 new Dictionary <string, HashSet <ITriple> > {
                    { triple.Predicate, new HashSet <ITriple> {
                          triple
                      } }
                });
            }
            else
            {
                HashSet <ITriple> predTriples;
                if (!subjIndex.TryGetValue(triple.Predicate, out predTriples))
                {
                    subjIndex.Add(triple.Predicate, new HashSet <ITriple> {
                        triple
                    });
                }
                else
                {
                    predTriples.Add(triple);
                }
            }
        }
Esempio n. 3
0
        ///<summary>
        /// Retrieves the value of the property of this data object with the specified property type
        ///</summary>
        ///<param name="type">The property type</param>
        ///<returns>The value of the first property of the specified type or null if no match was found</returns>
        public object GetPropertyValue(IDataObject type)
        {
            CheckLoaded();
            ITriple triple = _triples.FirstOrDefault(t => t.Predicate.Equals(type.Identity.ToString()));

            return(triple != null?CreateTypedObject(triple) : null);
        }
 public void Triple(ITriple t)
 {
     string dt = null;
     if (t.IsLiteral && t.DataType != null) dt = t.DataType.ToString();
     _sink.Triple(t.Subject, t.Subject.StartsWith("_:"),
                  t.Predicate, t.Predicate.StartsWith("_:"),
                  t.Object.ToString(), !t.IsLiteral && t.ToString().StartsWith("_:"),
                  t.IsLiteral, dt, t.LangCode, t.Graph.ToString());
 }
Esempio n. 5
0
 public void Remove(ITriple triple)
 {
     if (triple.IsLiteral)
     {
         RemoveBySubjectPredicateLiteral(triple.Subject, triple.Predicate, triple.Object, triple.DataType,
             triple.LangCode);
     }
     else
     {
         RemoveBySubjectPredicateObject(triple.Subject, triple.Predicate, triple.Object);
     }
 }
Esempio n. 6
0
 public void Remove(ITriple triple)
 {
     if (triple.IsLiteral)
     {
         RemoveBySubjectPredicateLiteral(triple.Subject, triple.Predicate, triple.Object, triple.DataType,
                                         triple.LangCode);
     }
     else
     {
         RemoveBySubjectPredicateObject(triple.Subject, triple.Predicate, triple.Object);
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Returns true if this triple matches the specified triple allowing
 /// either NULL or <see cref="Constants.WildcardUri"/> in Graph, Subject,
 /// Predicate and Object to stand for a wildcard
 /// </summary>
 /// <param name="other">The other triple to match with</param>
 /// <returns>True if there is a match in the non-null parts of both triples, false otherwise</returns>
 public bool MatchesWithWildcard(ITriple other)
 {
     return(NullOrWildcardOrMatch(Graph, other.Graph) &&
            NullOrWildcardOrMatch(Subject, other.Subject) &&
            NullOrWildcardOrMatch(Predicate, other.Predicate) &&
            (Object == null || other.Object == null ||
             (
                 IsLiteral == other.IsLiteral &&
                 DataType == other.DataType &&
                 LangCode == other.LangCode &&
                 Object == other.Object
             )));
 }
Esempio n. 8
0
 /// <summary>
 /// Returns true if this triple matches the specified triple allowing
 /// either NULL or <see cref="Constants.WildcardUri"/> in Graph, Subject, 
 /// Predicate and Object to stand for a wildcard
 /// </summary>
 /// <param name="other">The other triple to match with</param>
 /// <returns>True if there is a match in the non-null parts of both triples, false otherwise</returns>
 public bool MatchesWithWildcard(ITriple other)
 {
     return NullOrWildcardOrMatch(Graph, other.Graph) &&
            NullOrWildcardOrMatch(Subject, other.Subject) &&
            NullOrWildcardOrMatch(Predicate, other.Predicate) &&
            (Object == null || other.Object == null ||
             (
                 IsLiteral == other.IsLiteral &&
                 DataType == other.DataType &&
                 LangCode == other.LangCode &&
                 Object == other.Object
             ));
 }
Esempio n. 9
0
        public void Triple(ITriple t)
        {
            string dt = null;

            if (t.IsLiteral && t.DataType != null)
            {
                dt = t.DataType.ToString();
            }
            _sink.Triple(t.Subject, t.Subject.StartsWith("_:"),
                         t.Predicate, t.Predicate.StartsWith("_:"),
                         t.Object.ToString(), !t.IsLiteral && t.ToString().StartsWith("_:"),
                         t.IsLiteral, dt, t.LangCode, t.Graph.ToString());
        }
Esempio n. 10
0
 /// <summary>
 /// Maps the xsd data type to a .NET type for literal values or creates / looks up a DataObject for
 /// resources. BNodes get mapped to DataObjects.
 /// </summary>
 /// <param name="triple"></param>
 /// <returns></returns>
 private object CreateTypedObject(ITriple triple)
 {
     if (triple.IsLiteral)
     {
         object retValue;
         if (RdfDatatypes.TryParseLiteralString(triple.Object, triple.DataType, triple.LangCode, out retValue))
         {
             return(retValue);
         }
         return(triple.Object);
     }
     return(_store.MakeDataObject(triple.Object));
 }
Esempio n. 11
0
 private Triple ReplaceIdentity(ITriple t, string newIdentity)
 {
     return(new Triple
     {
         Subject = t.Subject.Equals(_identity) ? newIdentity : t.Subject,
         Predicate = t.Predicate,
         IsLiteral = t.IsLiteral,
         Object = t.Object.Equals(_identity) && !t.IsLiteral ? newIdentity : t.Object,
         DataType = t.DataType,
         LangCode = t.LangCode,
         Graph = t.Graph
     });
 }
Esempio n. 12
0
 private static IEnumerable <ITriple> GetMatches(Dictionary <string, HashSet <ITriple> > subjectIndex,
                                                 ITriple matchPattern)
 {
     if (matchPattern.Predicate == null)
     {
         foreach (ITriple t in subjectIndex.Values.SelectMany(hs => hs.Where(matchPattern.Matches)))
         {
             yield return(t);
         }
     }
     else
     {
         HashSet <ITriple> triples;
         if (subjectIndex.TryGetValue(matchPattern.Predicate, out triples))
         {
             foreach (ITriple t in triples.Where(matchPattern.Matches))
             {
                 yield return(t);
             }
         }
     }
 }
Esempio n. 13
0
 public void Add(ITriple triple)
 {
     if (triple == null) throw new ArgumentNullException("triple");
     Dictionary<string, HashSet<ITriple>> subjIndex;
     if (!_tripleIndex.TryGetValue(triple.Subject, out subjIndex))
     {
         _tripleIndex.Add(triple.Subject,
             new Dictionary<string, HashSet<ITriple>> {{triple.Predicate, new HashSet<ITriple> {triple}}});
     }
     else
     {
         HashSet<ITriple> predTriples;
         if (!subjIndex.TryGetValue(triple.Predicate, out predTriples))
         {
             subjIndex.Add(triple.Predicate, new HashSet<ITriple> {triple});
         }
         else
         {
             predTriples.Add(triple);
         }
     }
 }
Esempio n. 14
0
 public bool Compare(ITriple triple)
 {
     if (_s.Value.ToLower() == triple.Subject.Value.ToLower() &&
      _p.Value.ToLower() == triple.Predicate.Value.ToLower() &&
      _o.Value.ToLower() == triple.Object.Value.ToLower())
      return true;
       return false;
 }
Esempio n. 15
0
 /// <summary>
 ///     Yields and enumeration over the triples in the collection that match the provided pattern.
 /// </summary>
 /// <param name="matchPattern">
 ///     The match pattern specified as a triple where a wildcard match for Subject, Predicate,
 ///     Object or Graph can be specified using NULL
 /// </param>
 /// <returns></returns>
 public IEnumerable<ITriple> GetMatches(ITriple matchPattern)
 {
     if (matchPattern == null) throw new ArgumentNullException("matchPattern");
     if (matchPattern.Subject == null)
     {
         foreach (ITriple t in _tripleIndex.Values.SelectMany(subjIndex => GetMatches(subjIndex, matchPattern)))
         {
             yield return t;
         }
     }
     else
     {
         Dictionary<string, HashSet<ITriple>> si;
         if (_tripleIndex.TryGetValue(matchPattern.Subject, out si))
         {
             foreach (ITriple t in GetMatches(si, matchPattern)) yield return t;
         }
     }
 }
Esempio n. 16
0
 private static IEnumerable<ITriple> GetMatches(Dictionary<string, HashSet<ITriple>> subjectIndex,
     ITriple matchPattern)
 {
     if (matchPattern.Predicate == null)
     {
         foreach (ITriple t in subjectIndex.Values.SelectMany(hs => hs.Where(matchPattern.Matches)))
         {
             yield return t;
         }
     }
     else
     {
         HashSet<ITriple> triples;
         if (subjectIndex.TryGetValue(matchPattern.Predicate, out triples))
         {
             foreach (ITriple t in triples.Where(matchPattern.Matches)) yield return t;
         }
     }
 }
 public void AddFromTriple(ITriple t)
 {
     throw new NotImplementedException();
 }
        private IParameterBindingSet GetParameterBindingSetFromQuery(ITriple t, IQuery q)
        {
            IParameterBindingSet qpbs = RootFactory.GetInstance().MakeParameterBindingSet();
              IParameterBinding qpb = null;

              if (q.IsParameter(QueryPart.QuerySubject))
              {
             //compare the bindings with the query+triple subject value
             qpb = qpbs.MakeParameterBinding();
             qpb.Parameter.Value = q.SubjectValue.Value;
             qpb.Binding.Value = t.Subject.Value;
             qpbs.Add(qpb);
              }
              if (q.IsParameter(QueryPart.QueryPredicate))
              {
             //compare the bindings with the query+triple subject value
             qpb = qpbs.MakeParameterBinding();
             qpb.Parameter.Value = q.PredicateValue.Value;
             qpb.Binding.Value = t.Predicate.Value;
             qpbs.Add(qpb);
              }
              if (q.IsParameter(QueryPart.QueryObject))
              {
             //compare the bindings with the query+triple subject value
             qpb = qpbs.MakeParameterBinding();
             qpb.Parameter.Value = q.ObjectValue.Value;
             qpb.Binding.Value = t.Object.Value;
             qpbs.Add(qpb);
              }
              return qpbs;
        }
        public bool IsMatch(ITriple t, IQuery q)
        {
            int intersectCount=0;
              IParameterBindingSet qpbs = GetParameterBindingSetFromQuery(t, q);

              //if parameters intersect and are equal its values
              foreach (IParameterBinding pbFromQuery in qpbs.Bindings)
              {
             foreach (IParameterBinding pb in _bindings)
             {
                if (ParameterBindingIntersects(pb.Parameter.Value, pbFromQuery.Parameter.Value))
                {
                    intersectCount++;
                    if (pb.Binding.Value != string.Empty)
                    {
                       if (!BindigsAreEquals(pb.Binding.Value, pbFromQuery.Binding.Value))
                       {
                          return false;
                       }
                    }
                    else
                    {
                      pb.Binding.Value = pbFromQuery.Binding.Value;
                    }
                }
             }
              }
              if (intersectCount==0)
             return false;

              return true;
        }
Esempio n. 20
0
 /// <summary>
 /// Maps the xsd data type to a .NET type for literal values or creates / looks up a DataObject for 
 /// resources. BNodes get mapped to DataObjects.
 /// </summary>
 /// <param name="triple"></param>
 /// <returns></returns>
 private object CreateTypedObject(ITriple triple)
 {
     if (triple.IsLiteral)
     {
         object retValue;
         if (RdfDatatypes.TryParseLiteralString(triple.Object, triple.DataType, triple.LangCode, out retValue))
         {
             return retValue;
         }
         return triple.Object;
     }
     return _store.MakeDataObject(triple.Object);
 }
Esempio n. 21
0
 private Triple ReplaceIdentity(ITriple t, string newIdentity)
 {
     return new Triple
         {
             Subject = t.Subject.Equals(_identity) ? newIdentity : t.Subject,
             Predicate = t.Predicate,
             IsLiteral = t.IsLiteral,
             Object = t.Object.Equals(_identity) && !t.IsLiteral ? newIdentity : t.Object,
             DataType = t.DataType,
             LangCode = t.LangCode,
             Graph = t.Graph
         };
 }
 private bool containsVar(ITriple triple)
 {
     return(RDFUtil.sameTerm(var, triple.getObject()) ||
            RDFUtil.sameTerm(var, triple.getPredicate()) ||
            RDFUtil.sameTerm(var, triple.getSubject()));
 }
Esempio n. 23
0
 int IComparable <ITriple> .CompareTo(ITriple other)
 {
     return(((IComparable)this).CompareTo(other));
 }
Esempio n. 24
0
 /// <summary>Creates a new instance of <see cref="EntityQuad"/> from given <see cref="ITriple"/>.</summary>
 public EntityQuad(EntityId entityId, ITriple triple) : this(entityId, triple.Subject, triple.Predicate, triple.Object)
 {
 }