public void WritingSerializeOwnOneOfVeryLarge() { //Create the Graph for the Test and Generate a List of URIs Graph g = new Graph(); List <IUriNode> nodes = new List <IUriNode>(); for (int i = 1; i <= 10000; i++) { nodes.Add(g.CreateUriNode(new Uri("http://example.org/Class" + i))); } //Use the thingOneOf to generate the Triples thingOneOf(g, nodes.ToArray()); //Dump as NTriples to the Console NTriplesFormatter formatter = new NTriplesFormatter(); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); //Now try to save as RDF/XML IRdfWriter writer = new RdfXmlWriter(); writer.Save(g, "owl-one-of.rdf"); Console.WriteLine("Saved OK using RdfXmlWriter"); Console.WriteLine(); writer = new PrettyRdfXmlWriter(); ((ICompressingWriter)writer).CompressionLevel = WriterCompressionLevel.Medium; writer.Save(g, "owl-one-of-pretty.rdf"); Console.WriteLine("Saved OK using PrettyRdfXmlWriter"); Console.WriteLine(); //Now check that the Graphs are all equivalent Graph h = new Graph(); h.LoadFromFile("owl-one-of.rdf"); Assert.Equal(g, h); Console.WriteLine("RdfXmlWriter serialization was OK"); Console.WriteLine(); Graph j = new Graph(); j.LoadFromFile("owl-one-of-pretty.rdf"); Assert.Equal(g, j); Console.WriteLine("PrettyRdfXmlWriter serialization was OK"); }
public void WritingRdfXmlPrettySubjectCollection1() { String graph = @"@prefix ex: <http://example.com/>. (1) ex:someProp ""Value""."; Graph g = new Graph(); g.LoadFromString(graph, new TurtleParser()); PrettyRdfXmlWriter writer = new PrettyRdfXmlWriter(); System.IO.StringWriter strWriter = new System.IO.StringWriter(); writer.Save(g, strWriter); Console.WriteLine(strWriter.ToString()); Console.WriteLine(); Graph h = new Graph(); h.LoadFromString(strWriter.ToString(), new RdfXmlParser()); Assert.Equal(g, h); }
/// <summary> /// Finds the triples, related to a URL (this is called after URL rewriting has been activated). /// </summary> /// <param name="parameter">The parameter from URL rewriting.</param> /// <returns></returns> /// <remarks></remarks> public static string FindRelated(string parameter) { Graph resultGraph; if (Configuration.Configuration.RdfPrefix + "/" + parameter == Configuration.Configuration.OntologyNamespace || string.IsNullOrEmpty(parameter)) { var endpoint = new SparqlRemoteEndpoint(new Uri(TripleStoreManager.EndpointUrl), Configuration.Configuration.OntologyNamespace); resultGraph = endpoint.QueryWithResultGraph("construct {?a ?b ?c} where {?a ?b ?c}") as Graph; } else { var endpoint = new SparqlRemoteEndpoint(new Uri(TripleStoreManager.EndpointUrl), ""); var genericQuery = Configuration.Configuration.RdfPrefix + "/" + parameter == Configuration.Configuration.ResourceNamespace || Configuration.Configuration.RdfPrefix + "/" + parameter == Configuration.Configuration.ResourceNamespace + "/" ; resultGraph = genericQuery ? endpoint.QueryWithResultGraph( "construct {?a ?b ?c} where {graph <" + Configuration.Configuration.ResourceNamespace + "> {?a ?b ?c . filter not exists {?a <" + Configuration.Configuration.OntologyNamespace + "#hasParent> ?p }}}") as Graph : endpoint.QueryWithResultGraph("construct {<" + Configuration.Configuration.RdfPrefix + "/" + parameter + "> ?b ?c} where {graph ?g {<" + Configuration.Configuration.RdfPrefix + "/" + parameter + "> ?b ?c}}") as Graph; } var sw = new StringWriter(); var writer = new PrettyRdfXmlWriter(); writer.Save(resultGraph, sw); var result = sw.ToString().Replace("encoding=\"utf-16\"", "encoding=\"utf-8\""); return result; }