Пример #1
0
 public virtual void Merge(BaseGraph graph)
 {
     foreach (var triple in graph.Triples)
     {
         Triples.Add(triple);
     }
 }
Пример #2
0
        /// <summary>
        /// Add triple with specified parameters.
        /// </summary>
        /// <param name="subjectStr">Subject</param>
        /// <param name="predicateStr">Predicate</param>
        /// <param name="objectStr">Object</param>
        /// <returns>Returns 'True' if operation completed succeful, 'False' otherwise.</returns>
        /// <example>PutTriplet( “czusr:76087518-4f8e-4d3a-9bfb-2fd2332376eb”, “czpred:favorite”, "cztimeline:3a87bb5c-85f7-4305-8b2f-f2002580cd25")</example>
        public bool PutTriplet(TripleName subjectName, TripleName predicateName, TripleName objectName)
        {
            subjectName   = EnsurePrefix(subjectName);
            predicateName = EnsurePrefix(predicateName);
            objectName    = EnsurePrefix(objectName);
            var shortSubjectStr   = subjectName.ToString();
            var shortPredicateStr = predicateName.ToString();
            var shortObjectStr    = objectName.ToString();

            var tr = Triples.Where(t => t.Subject == shortSubjectStr && t.Predicate == shortPredicateStr).Include(o => o.Objects).FirstOrDefault();

            if (tr != null)
            {
                if (tr.Objects.FirstOrDefault(x => x.Object == shortObjectStr) == null)
                {
                    tr.Objects.Add(
                        new TripleObject
                    {
                        Object          = shortObjectStr,
                        TripleObject_Id = Guid.NewGuid()
                    }
                        );
                }
                else
                {
                    return(true);
                }
                SaveChanges();
                return(true);
            }
            var triple = new Triple
            {
                Subject   = shortSubjectStr,
                Predicate = shortPredicateStr,
                Id        = Guid.NewGuid(),
                Objects   = new Collection <TripleObject>
                {
                    new TripleObject
                    {
                        Object          = shortObjectStr,
                        TripleObject_Id = Guid.NewGuid()
                    }
                }
            };

            Triples.Add(triple);
            SaveChanges();
            return(true);
        }
Пример #3
0
 public void Assert(RDFDataset.Quad quad)
 {
     Triples.Add(new Triple(quad.GetSubject(), quad.GetPredicate(), quad.GetObject()));
 }
Пример #4
0
 public void Assert(RDFDataset.Node subNode, RDFDataset.Node predNode, RDFDataset.Node objNode)
 {
     Triples.Add(new Triple(subNode, predNode, objNode));
 }
Пример #5
0
 public void Assert(Triple triple)
 {
     Triples.Add(triple);
 }