public static dynamic GetDyno(string data, bool autoquotation = true, bool treatUri = true, bool skipTriplesWithEmptyObject = false, bool mindAsterisk = false, bool useStore = false, string defaultGraphUri = "http://test.org/defaultgraph") { DynamicSPARQLSpace.dotNetRDF.Connector connector = null; if (useStore) { var store = new VDS.RDF.TripleStore(); store.LoadFromString(data); connector = new Connector(new InMemoryDataset(store, new Uri(defaultGraphUri))); } else { var graph = new VDS.RDF.Graph(); graph.LoadFromString(data); connector = new Connector(new InMemoryDataset(graph)); } dynamic dyno = DynamicSPARQL.CreateDyno(connector.GetQueryingFunction(), updateFunc: connector.GetUpdateFunction(), autoquotation: autoquotation, treatUri: treatUri, skipTriplesWithEmptyObject:skipTriplesWithEmptyObject, mindAsterisk:mindAsterisk); return dyno; }
/// <summary>Loads data from string with optional automated graph generation.</summary> /// <param name="store">Target store to be loaded with data.</param> /// <param name="data">String with data.</param> /// <param name="parser">RDF reader.</param> /// <param name="metaGraphUri">When provided, store will have automatically created graphs for all resources that are mentioned in the meta graph provided.</param> public static void LoadFromString(this ITripleStore store, string data, IRdfReader parser, Uri metaGraphUri) { ITripleStore targetStore = (metaGraphUri != null ? new TripleStore() : store); IGraph graph = new Graph(); targetStore.Add(graph); graph.LoadFromString(data, parser); if (metaGraphUri != null) { store.ExpandGraphs((TripleStore)targetStore, metaGraphUri); } }
private void CompareResultGraphs(string results, string expectedResultsPath, bool reduced) { var expectedResultGraph = new Graph(); FileLoader.Load(expectedResultGraph, expectedResultsPath); var resultSet = expectedResultGraph.GetUriNode(new Uri("http://www.w3.org/2001/sw/DataAccess/tests/result-set#ResultSet")); if (resultSet != null) { var rdfParser = new SparqlRdfParser(); var xmlParser = new SparqlXmlParser(); var actualResultSet = new SparqlResultSet(); var expectedResultSet = new SparqlResultSet(); using (var tr = new StringReader(results)) { xmlParser.Load(actualResultSet, tr); } rdfParser.Load(expectedResultSet, expectedResultsPath); var bnodeMap = new Dictionary<string, string>(); CompareSparqlResults(actualResultSet, expectedResultSet, reduced, bnodeMap); } else { // This is a constructed graph var actualGraph = new Graph(); actualGraph.LoadFromString(results); CompareTripleCollections(actualGraph.Triples, expectedResultGraph.Triples, reduced); } }
private void CompareResultGraphs(string results, string expectedResultsPath, bool reduced) { var expectedResultGraph = new Graph(); FileLoader.Load(expectedResultGraph, expectedResultsPath); var resultSet = expectedResultGraph.GetUriNode(new Uri("http://www.w3.org/2001/sw/DataAccess/tests/result-set#ResultSet")); if (resultSet != null) { var rdfParser = new SparqlRdfParser(); var xmlParser = new SparqlXmlParser(); var actualResultSet = new SparqlResultSet(); var expectedResultSet = new SparqlResultSet(); using (var tr = new StringReader(results)) { xmlParser.Load(actualResultSet, tr); } rdfParser.Load(expectedResultSet, expectedResultsPath); var bnodeMap = new Dictionary<string, string>(); CompareSparqlResults(actualResultSet, expectedResultSet, reduced, bnodeMap); } else { // This is a constructed graph var actualGraph = new Graph(); actualGraph.LoadFromString(results); var toReplace = actualGraph.Triples.Where( t => IsGenid(t.Subject) || IsGenid(t.Predicate) || IsGenid(t.Object)).ToList(); foreach (var t in toReplace) { var mapped = MapGenidToBlank(t); actualGraph.Retract(t); actualGraph.Assert(mapped); } CompareTripleCollections(actualGraph.Triples, expectedResultGraph.Triples, reduced); } }
public void WritingRdfXmlWithDtds() { String fragment = "@prefix xsd: <" + NamespaceMapper.XMLSCHEMA + ">. @prefix : <http://example.org/>. :subj a :obj ; :has \"string\"^^xsd:string ; :has 23 ."; Graph g = new Graph(); g.LoadFromString(fragment); this.CheckRoundTrip(g); }
public void WritingRdfXmlSimpleCollection() { String fragment = "@prefix : <http://example.org/>. :subj :pred ( 1 2 3 )."; Graph g = new Graph(); g.LoadFromString(fragment); this.CheckRoundTrip(g); }
public void WritingRdfXmlSimpleBNodeCollection3() { String fragment = "@prefix : <http://example.org/>. :subj :pred [ a :BNode ; :another :thing ]."; Graph g = new Graph(); g.LoadFromString(fragment); this.CheckRoundTrip(g); }