コード例 #1
0
        protected override PlaceDataObject DoGet(PlaceDataObject entity, LambdaExpression securityFilterExpression, List <string> includes, IObjectsDataSet context, Dictionary <string, object> parameters)
        {
            var uri = entity.URI;

            SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("http://dbpedia.org/sparql"), "http://dbpedia.org");

            string queryString = @"SELECT ?name, ?abstract
                  WHERE {
                            ?place rdfs:label ?name .
                            ?place dbo:abstract ?abstract .

                            FILTER langMatches(lang(?name), 'en')
                            FILTER langMatches(lang(?abstract), 'en')}";

            queryString = queryString.Replace("?place ", $"<{uri}> ");

            //Make a SELECT query against the Endpoint
            SparqlResultSet results = endpoint.QueryWithResultSet(queryString);

            var result = results.Single();

            var place   = new PlaceDataObject();
            var dataset = ApplicationSettings.Container.Resolve <IObjectsDataSet>();

            dataset.AddObject(place);

            place.URI      = entity.URI;
            place.Name     = (result.Where(r => r.Key == "name").Single().Value as BaseLiteralNode).Value;
            place.Abstract = (result.Where(r => r.Key == "abstract").Single().Value as BaseLiteralNode)?.Value;
            place.IsNew    = false;
            place.IsDirty  = false;

            return(place);
        }
コード例 #2
0
        protected override int DoCount(LambdaExpression securityFilterExpression, string filterPredicate, object[] filterArguments, IObjectsDataSet context, Dictionary <string, object> parameters)
        {
            int count;

            var regex = new Regex("Name\\.Contains\\(\"(.*)\"\\)");

            string nameFilter = null;
            var    match      = regex.Match(filterPredicate);

            if (match.Success)
            {
                nameFilter = match.Groups[1].Value;
            }

            SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("http://dbpedia.org/sparql"), "http://dbpedia.org");

            //Make a SELECT query against the Endpoint
            string query =
                @"SELECT count(?place) WHERE 
                    { 
                    {?place a <http://dbpedia.org/ontology/HistoricPlace>}
                    UNION
                    {?place a <http://dbpedia.org/ontology/Monument>}
                    UNION
                    {?place a <http://dbpedia.org/ontology/Garden>}
                    UNION
                    {?place a <http://dbpedia.org/ontology/Cemetery>}
                    UNION
                    {?place a <http://dbpedia.org/ontology/ArchitecturalStructure>}
                    UNION
                    {?place a <http://dbpedia.org/ontology/Park>}
                    UNION
                    {?place a <http://dbpedia.org/ontology/NaturalPlace>}
                    
                    ?place rdfs:label ?name .
                    FILTER langMatches(lang(?name), 'en')

                    ";

            if (!String.IsNullOrEmpty(nameFilter))
            {
                query += $"FILTER regex(?name,\"{nameFilter}\",\"i\")";
            }

            query += "}";

            //Make a SELECT query against the Endpoint
            SparqlResultSet results = endpoint.QueryWithResultSet(query);

            var res = results.Single();

            count = Convert.ToInt32((res.Single().Value as BaseLiteralNode).Value);

            return(count);
        }
コード例 #3
0
        protected override int DoCount(LambdaExpression securityFilterExpression, string filterPredicate, object[] filterArguments, IObjectsDataSet context, Dictionary <string, object> parameters)
        {
            int count;

            SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("http://dbpedia.org/sparql"), "http://dbpedia.org");

            //Make a SELECT query against the Endpoint
            SparqlResultSet results = endpoint.QueryWithResultSet("SELECT count(?country) WHERE { ?country a <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> }");

            var res = results.Single();

            count = Convert.ToInt32((res.Single().Value as BaseLiteralNode).Value);

            return(count);
        }