public bool CheckIfResourceExist(Uri pidUri, out string lifeCycleStatus) { lifeCycleStatus = string.Empty; SparqlParameterizedString parameterizedString = new SparqlParameterizedString(); parameterizedString.CommandText = @"Select * @fromResourceNamedGraph @fromMetadataNamedGraph WHERE { ?subject rdf:type [rdfs:subClassOf+ pid3:PID_Concept]. ?subject @hasPid @pidUri . FILTER NOT EXISTS { ?subject @hasPidEntryDraft ?draftSubject } ?subject @lifeCycleStatus ?lifeCycleStatus }"; parameterizedString.SetPlainLiteral("fromResourceNamedGraph", _metadataGraphConfigurationRepository.GetGraphs(InsertingGraph).JoinAsFromNamedGraphs()); parameterizedString.SetPlainLiteral("fromMetadataNamedGraph", _metadataGraphConfigurationRepository.GetGraphs(Graph.Metadata.Constants.MetadataGraphConfiguration.HasMetadataGraph).JoinAsFromNamedGraphs()); parameterizedString.SetUri("hasPid", new Uri(Graph.Metadata.Constants.EnterpriseCore.PidUri)); parameterizedString.SetUri("pidUri", pidUri); parameterizedString.SetUri("lifeCycleStatus", new Uri(Graph.Metadata.Constants.Resource.HasEntryLifecycleStatus)); parameterizedString.SetUri("hasPidEntryDraft", new Uri(Graph.Metadata.Constants.Resource.HasPidEntryDraft)); SparqlResultSet result = _tripleStoreRepository.QueryTripleStoreResultSet(parameterizedString); if (result.Any()) { lifeCycleStatus = result.FirstOrDefault().GetNodeValuesFromSparqlResult("lifeCycleStatus")?.Value; return(true); } return(false); }
private IList <Resource> BuildResourceFromQuery(SparqlParameterizedString parameterizedString, Uri pidUri = null) { using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(100)); var resultsTask = Task.Factory.StartNew(() => _tripleStoreRepository.QueryTripleStoreResultSet(parameterizedString), cancellationTokenSource.Token); var versionsTask = Task.Factory.StartNew(() => GetAllVersionsOfResourceByPidUri(pidUri), cancellationTokenSource.Token); WaitAllTasks(cancellationTokenSource, resultsTask, versionsTask); SparqlResultSet results = resultsTask.Result; IList <VersionOverviewCTO> versions = versionsTask.Result; if (!results.Any()) { throw new EntityNotFoundException("No resource found for given pid uri", pidUri.ToString()); } var entities = TransformQueryResults(results, pidUri?.ToString()); foreach (var entity in entities) { entity.Versions = versions; } return(entities); }
// GET api/<controller>?title="any" public Artwork Get(string title) { using (StardogConnector dog = new StardogConnector(StarDogUrl, DbName, "admin", "admin")) { SparqlResultSet artworkResults = dog.Query( "SELECT distinct ?label ?abstract ?depiction ?museumlabel ?authorLabel WHERE {" + "?artwork a dbo:Artwork ." + "?artwork rdfs:label ?label . " + "?artwork dbo:abstract ?abstract ." + "?artwork foaf:depiction ?depiction ." + "?artwork dbo:author ?author ." + "?author foaf:name ?authorLabel ." + "?artwork dbo:museum ?museum ." + "?museum rdfs:label ?museumlabel ." + "FILTER regex(str(?label), \"" + title + "\")" + "FILTER(lang(?museumlabel) = \"en\") ." + "FILTER(lang(?abstract) = \"en\")}") as SparqlResultSet; if (!artworkResults.Any()) { return(null); } var result = artworkResults[0]; return(new Artwork( result.Value("label").ToString(), result.Value("museumlabel").ToString(), result.Value("abstract").ToString(), result.Value("depiction").ToString(), result.Value("authorLabel").ToString())); } }
private void RunTest(IFullTextIndexer indexer, String query, IEnumerable <INode> expected) { this.EnsureTestData(); indexer.Index(this._dataset); indexer.Dispose(); //Build the SPARQL Query and parse it SparqlParameterizedString queryString = new SparqlParameterizedString(query); queryString.Namespaces = this.GetQueryNamespaces(); SparqlQuery q = this._parser.ParseFromString(queryString); SparqlFormatter formatter = new SparqlFormatter(q.NamespaceMap); Console.WriteLine("Parsed Query:"); Console.WriteLine(formatter.Format(q)); Console.WriteLine("Expected Results:"); foreach (INode n in expected) { Console.WriteLine(n.ToString(formatter)); } Console.WriteLine(); LuceneSearchProvider provider = new LuceneSearchProvider(LuceneTestHarness.LuceneVersion, LuceneTestHarness.Index); try { q.AlgebraOptimisers = new IAlgebraOptimiser[] { new FullTextOptimiser(provider) }; LeviathanQueryProcessor processor = new LeviathanQueryProcessor(this._dataset); SparqlResultSet results = processor.ProcessQuery(q) as SparqlResultSet; if (results != null) { TestTools.ShowResults(results); foreach (INode n in expected) { Assert.IsTrue(results.Any(r => r.HasValue("match") && r["match"] != null && r["match"].Equals(n)), "Did not get expected ?match => " + formatter.Format(n)); } foreach (SparqlResult r in results) { Assert.IsTrue(r.HasValue("match") && r["match"] != null && expected.Contains(r["match"]), "Unexpected Match " + formatter.Format(r["match"])); } } else { Assert.Fail("Did not get a SPARQL Result Set as expected"); } } finally { provider.Dispose(); LuceneTestHarness.Index.Dispose(); } }
public string GetAdRoleForConsumerGroup(string id) { if (string.IsNullOrWhiteSpace(id)) { return(null); } if (!id.IsValidBaseUri()) { throw new InvalidFormatException(Graph.Metadata.Constants.Messages.Identifier.IncorrectIdentifierFormat, id); } SparqlParameterizedString parameterizedString = new SparqlParameterizedString(); var queryString = @" SELECT ?adRole @fromNamedGraphs WHERE { @consumerGroup rdf:type pid:ConsumerGroup. @consumerGroup @adRole ?adRole }"; parameterizedString.CommandText = queryString; parameterizedString.SetUri("consumerGroup", new Uri(id)); parameterizedString.SetUri("adRole", new Uri(Graph.Metadata.Constants.ConsumerGroup.AdRole)); parameterizedString.SetPlainLiteral("fromNamedGraphs", _metadataGraphConfigurationRepository.GetGraphs(QueryGraphs).JoinAsFromNamedGraphs()); SparqlResultSet results = _tripleStoreRepository.QueryTripleStoreResultSet(parameterizedString); var result = results.FirstOrDefault(); if (!results.Any()) { return(null); } return(result.GetNodeValuesFromSparqlResult("adRole").Value ?? null); }