private IList <Resource> TransformQueryResults(SparqlResultSet results, string id = "")
        {
            if (results.IsEmpty)
            {
                return(new List <Resource>());
            }

            var groupedResults = results.GroupBy(result => result.GetNodeValuesFromSparqlResult("subject").Value);

            var counter        = 0;
            var inboundCounter = 0;

            return(groupedResults.Select(result => CreateResourceFromGroupedResult(result, counter, inboundCounter)).ToList());
        }
        private IList <Entity> TransformQueryResults(SparqlResultSet results, string id = "")
        {
            if (results.IsEmpty)
            {
                return(null);
            }

            var groupedResults = results.GroupBy(result => result.GetNodeValuesFromSparqlResult("subject").Value);

            IList <Entity> foundEntities = groupedResults.Select(result =>
            {
                var subGroupedResults = result.GroupBy(res => res.GetNodeValuesFromSparqlResult("predicate").Value);
                var newEntity         = new Entity
                {
                    Id         = id == string.Empty ? result.Key : id,
                    Properties = subGroupedResults.ToDictionary(x => x.Key, x => x.Select(property => GetEntityPropertyFromSparqlResult(property)).ToList())
                };

                return(newEntity);
            }).ToList();

            return(foundEntities);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// IMPORTANT: It's neccesary to identify the colums with "id", "predicate" and "object" when you query the graph, so the fields can be transformed properly.
        /// </summary>
        /// <param name="results"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        protected virtual IList <T> TransformQueryResults(SparqlResultSet results, string id = "", Uri namedGraph = null)
        {
            if (results.IsEmpty)
            {
                return(new List <T>());
            }

            var groupedResults = results.GroupBy(result => result.GetNodeValuesFromSparqlResult("subject").Value);

            IList <T> foundEntities = groupedResults.Select(result =>
            {
                var subGroupedResults = result.GroupBy(res => res.GetNodeValuesFromSparqlResult("predicate").Value);
                var newEntity         = new T
                {
                    Id         = id == string.Empty ? result.Key : id,
                    Properties = subGroupedResults.ToDictionary(x => x.Key, x => GetResultListBySupportedLanguage(x).ToList <dynamic>())
                };

                return(newEntity);
            }).ToList();

            return(foundEntities);
        }