public void SaveToFile(string filePath, DatasourceFileType fileType) { try { switch (fileType) { case DatasourceFileType.Rdfxml: // RDF/XML FastRdfXmlWriter rxtw = new FastRdfXmlWriter(); rxtw.Save(myGraph, filePath); break; case DatasourceFileType.NTriples: // NTriples NTriplesWriter wr = new NTriplesWriter(); wr.Save(myGraph, filePath); break; } } catch (Exception ex) { MySoapFault fault = new MySoapFault(); fault.Operation = "SaveToFile"; fault.Reason = "Error in saving datasource from graph to file ."; fault.Details = ex.Message; fault.MoreDetails = ex.StackTrace; throw new FaultException <MySoapFault>(fault); } }
private void SaveButton_Click(object sender, RoutedEventArgs e) { try { SaveFileDialog sfd = new SaveFileDialog(); sfd.InitialDirectory = Environment.CurrentDirectory; sfd.Filter = "RDF Files (*.rdf)|*.rdf|Turtle Files (*.ttl)|*.ttl|All Files (*.*)|*.*"; if (sfd.ShowDialog().Value) { string filePath = sfd.FileName; switch (ModeComboBox.SelectedIndex) { case 0: // RDF/XML FastRdfXmlWriter rxtw = new FastRdfXmlWriter(); rxtw.Save(myGraph, filePath); break; case 1: // NTriples NTriplesWriter wr = new NTriplesWriter(); wr.Save(myGraph, filePath); break; } MessageBox.Show("Your Current Graph Saved Successfully", "Save Graph", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.StackTrace, "ERROR", MessageBoxButton.OK); } }
private void button1_Click(object sender, RoutedEventArgs e) { /* Connect To DBPedia * //First define a SPARQL Endpoint for DBPedia * SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("http://dbpedia.org/sparql")); * * //Next define our query * //We're going to ask DBPedia to describe the first thing it finds which is a Person * String query = "DESCRIBE ?person WHERE {?person a <http://dbpedia.org/ontology/Person>} LIMIT 1"; * * //Get the result * Graph g = endpoint.QueryWithResultGraph(query); * * FastRdfXmlWriter rxtw = new FastRdfXmlWriter(); * rxtw.Save(g, "dbp.txt");*/ Graph g = new Graph(); UriNode omid = g.CreateUriNode(new Uri("http://www.omidey.co.cc")); UriNode says = g.CreateUriNode(new Uri("http://www.sample.com/says")); LiteralNode hello = g.CreateLiteralNode("Hello World!!!"); LiteralNode sallam = g.CreateLiteralNode("Sallam 2nyaaa!!!", "fa"); g.Assert(new Triple(omid, says, hello)); g.Assert(new Triple(omid, says, sallam)); //foreach (Triple t in g.Triples) //{ // MessageBox.Show(t.ToString()); //} String query = "SELECT ?n ?p WHERE {?n ?p 'Hello World!!!'}"; // like select * => "SELECT ?n ?p ?m WHERE {?n ?p ?m}" SparqlResultSet res = (SparqlResultSet)g.ExecuteQuery(query); foreach (SparqlResult r in res) { MessageBox.Show(r.ToString()); } FastRdfXmlWriter rxtw = new FastRdfXmlWriter(); rxtw.Save(g, "omid.txt"); //TripleStore ts = new TripleStore(); //Object res = ts.ExecuteQuery("SELECT * WHERE {?s ?p ?o}"); //if (res is SparqlResultSet) //{ // SparqlResultSet results = (SparqlResultSet)res; // foreach (SparqlResult sr in results) // { // Console.WriteLine(sr.ToString()); // } //} }
private void button1_Click(object sender, RoutedEventArgs e) { // Connect To DBPedia //First define a SPARQL Endpoint for DBPedia SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("http://dbpedia.org/sparql")); //Next define our query //We're going to ask DBPedia to describe the first thing it finds which is a Person String query = "DESCRIBE ?person WHERE {?person a <http://dbpedia.org/ontology/Person>} LIMIT 1"; //Get the result Graph g = endpoint.QueryWithResultGraph(query); FastRdfXmlWriter rxtw = new FastRdfXmlWriter(); rxtw.Save(g, "dbp.txt"); //foreach (Triple t in g.Triples) //{ // MessageBox.Show(t.ToString()); //} ////String query = "SELECT ?n ?p WHERE {?n ?p 'Hello World!!!'}"; // like select * => "SELECT ?n ?p ?m WHERE {?n ?p ?m}" ////SparqlResultSet res = (SparqlResultSet)myGraph.ExecuteQuery(query); ////foreach (SparqlResult r in res) ////{ //// MessageBox.Show(r.ToString()); ////} ////FastRdfXmlWriter rxtw = new FastRdfXmlWriter(); ////rxtw.Save(myGraph, "omid.txt"); //TripleStore ts = new TripleStore(); //Object res = ts.ExecuteQuery("SELECT * WHERE {?s ?p ?o}"); //if (res is SparqlResultSet) //{ // SparqlResultSet results = (SparqlResultSet)res; // foreach (SparqlResult sr in results) // { // Console.WriteLine(sr.ToString()); // } //} }