Esempio n. 1
0
        /// <summary>
        /// Get all the predicates from the triples with given subject IRI, sorted according to the popularity of predicates
        /// </summary>
        public static async Task RetrievePredicatesAndObjectCounts(PredicateResultWrapperList list, string subjectIri, string language, SparqlRemoteEndpoint endpoint)
        {
            Config.AssertAbsoluteUri(subjectIri);

            SparqlQuery query = QueryCreating.CreateQuery(QueryTemplates.SelectDistinctPredicateAndObjectCount, subjectIri, language);

            var holder = await RetrieveResultHolder(query, endpoint);

            foreach (var result in holder.QueryResultSet)
            {
                var predicate = await CreatePredicateNodeFromSparqlResult(subjectIri, holder.QueryEndpoint, result);

                list.InsertPredicateWrapper(predicate);
            }
            list.Sort();
        }
Esempio n. 2
0
        /// <summary>
        /// Get all the predicates from the triples with given subject IRI from multiple endpoints, sorted according to the popularity of predicates
        /// </summary>
        public static async Task RetrievePredicatesAndObjectCounts(PredicateResultWrapperList list, string subjectIri, string language, List <SparqlRemoteEndpoint> endpoints)
        {
            Config.AssertAbsoluteUri(subjectIri);

            SparqlQuery query = QueryCreating.CreateQuery(QueryTemplates.SelectDistinctPredicateAndObjectCount, subjectIri, language);

            /*** create tasks ***/
            List <Task <ResultHolder> > tasks = new List <Task <ResultHolder> >(capacity: endpoints.Count);

            try
            {
                foreach (var endpoint in endpoints)
                {
                    tasks.Add(RetrieveResultHolder(query, endpoint));
                }
            }
            catch (Exception)
            {
                throw;
            }
            /*** process results ***/
            try
            {
                foreach (var task in tasks)
                {
                    var endpoint = task.Result.QueryEndpoint;
                    foreach (var result in task.Result.QueryResultSet)
                    {
                        var predicate = await CreatePredicateNodeFromSparqlResult(subjectIri, endpoint, result);

                        list.InsertPredicateWrapper(predicate);
                    }
                }
            }
            catch (AggregateException)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }

            list.Sort();
            //TODO: handle duplicates
        }