private static object Execute(string name, Dictionary <string, string> values) { var endpoint = Resources.DB.Endpoints[name]; if (endpoint.Type == EndpointType.HardCoded) { return(FixedQueryController.ExecuteHardCoded(name, values)); } else { return(FixedQueryController.ExecuteNamedSparql(name, values)); } }
private static object Execute(string name, Dictionary <string, string> values) { var endpoint = Resources.GetApiPathItem(name); var endpointType = Resources.GetEndpointType(endpoint); if (endpointType == EndpointType.HardCoded) { return(FixedQueryController.ExecuteHardCoded(name, values)); } else { return(FixedQueryController.ExecuteNamedSparql(name, values)); } }
public static IGraph webarticle_by_id(Dictionary <string, string> values) { var webarticle_id = values["webarticle_id"]; var uri = new Uri(Global.InstanceUri, webarticle_id).AbsoluteUri; var articleExists = FixedQueryController.ExecuteNamedSparql("exists", new Dictionary <string, string> { { "uri", uri } }) as SparqlResultSet; if (!articleExists.Result) { throw new HttpResponseException(HttpStatusCode.NotFound); } try { return(Contentful.Engine.GetArticle(webarticle_id)); } catch (Contentful.EntryNotFoundException) { throw new HttpResponseException(HttpStatusCode.NotFound); } }
public static IGraph with_schema(Dictionary <string, string> values) { // Run the original query var endpoint_name = values["endpoint_name"]; var originalGraph = FixedQueryController.ExecuteNamedSparql(endpoint_name, values) as IGraph; // Collect types and predicates from the result of the original query // and get ontology information about them. var predicates = originalGraph.Triples.PredicateNodes; var types = originalGraph.GetTriplesWithPredicate(new Uri(RdfSpecsHelper.RdfType)).Select(t => t.Object); var ontologyResources = string.Join(" ", predicates.Union(types).Distinct().Cast <IUriNode>().Select(p => "<" + p.Uri.AbsoluteUri + ">")); var ontologyQuery = @" PREFIX owl: <http://www.w3.org/2002/07/owl#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> CONSTRUCT { ?ontology ?ontologyProperty ?ontologyValue . ?ontologyResource ?resourceProperty ?resourceValue . } FROM <http://www.ontotext.com/explicit> WHERE { VALUES ?ontologyResource {@ontologyResources} ?ontology ?ontologyProperty ?ontologyValue . ?ontologyResource ?resourceProperty ?resourceValue ; rdfs:isDefinedBy ?ontology. FILTER(?resourceProperty != owl:inverseOf) }".Replace("@ontologyResources", ontologyResources); var ontologyGraph = BaseController.ExecuteList(new SparqlParameterizedString(ontologyQuery)) as IGraph; // Collect classes from across both the result of the original query and the ontology generated for it // (could be types from the original, classes from the ontology or domains and ranges from the ontology) // and see if any are sub-classes of any other var domains = ontologyGraph.GetTriplesWithPredicate(ontologyGraph.CreateUriNode(new Uri(OntologyHelper.PropertyDomain))).Select(t => t.Object); var ranges = ontologyGraph.GetTriplesWithPredicate(ontologyGraph.CreateUriNode(new Uri(OntologyHelper.PropertyRange))).Select(t => t.Object); var classes = ontologyGraph.GetTriplesWithPredicateObject(ontologyGraph.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)), ontologyGraph.CreateUriNode(new Uri(OntologyHelper.OwlClass))).Select(t => t.Subject); var classResources = string.Join(" ", domains.Union(ranges).Union(classes).Union(types).Distinct().Cast <IUriNode>().Select(p => "<" + p.Uri.AbsoluteUri + ">")); var subClassQuery = @" PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> CONSTRUCT { ?class rdfs:subClassOf ?superClass . } FROM <http://www.ontotext.com/explicit> WHERE { VALUES ?class {@classResources} VALUES ?superClass {@classResources} ?class rdfs:subClassOf ?superClass . }".Replace("@classResources", classResources); var subClassGraph = BaseController.ExecuteList(new SparqlParameterizedString(subClassQuery)) as IGraph; // The result is all three graphs above merged. var resultGraph = new Graph(); resultGraph.Merge(originalGraph); resultGraph.Merge(ontologyGraph); resultGraph.Merge(subClassGraph); return(resultGraph); }