private IEnumerable <T> CreateEntityResultSet <T>(IEnumerable <RomanticWeb.Model.IEntityQuad> quads, IEnumerable <EntityId> actualEntities)
        {
            var groupedTriples = from triple in quads
                                 group triple by triple.EntityId into tripleGroup
                                 select tripleGroup;

            foreach (var triples in groupedTriples)
            {
                _store.AssertEntity(triples.Key, triples);
            }

            var createMethodInfo = EntityLoadMethod.MakeGenericMethod(new[] { typeof(T) });

            return(actualEntities.Select(id => (T)createMethodInfo.Invoke(_entityContext, new object[] { id })));
        }
        /// <summary>Loads an entity using SPARQL query and loads the resulting triples to the <paramref name="store"/>.</summary>
        public void LoadEntity(IEntityStore store, EntityId entityId)
        {
            // todo: maybe this should return EntityTriples instead and they should be asserted in EntityContext?
            var sparql = QueryBuilder.Select("s", "p", "o", "g")
                                   .Graph("?g", graph => graph.Where(triple => triple.Subject("s").Predicate("p").Object("o")))
                                   .Where(triple => triple.Subject("g").PredicateUri("foaf:primaryTopic").Object(entityId.Uri));
            sparql.Prefixes.Import(_namespaces);
            var triples = from result in ExecuteSelect(sparql.BuildQuery())
                          let subject = result["s"].WrapNode(entityId)
                          let predicate = result["p"].WrapNode(entityId)
                          let @object = result["o"].WrapNode(entityId)
                          let graph = result.HasBoundValue("g") ? result["g"].WrapNode(entityId) : null
                          select new EntityQuad(entityId, subject, predicate, @object, graph);

            store.AssertEntity(entityId, triples);
        }
Example #3
0
 /// <summary>Initializes given entity with data.</summary>
 /// <param name="entity">Entity to be initialized</param>
 public void InitializeEnitity(IEntity entity)
 {
     _entityStore.AssertEntity(entity.Id, _entitySource.LoadEntity(entity.Id));
 }