public void ParsingN3VariableContexts() { String prefixes = "@prefix rdf: <" + NamespaceMapper.RDF + ">. @prefix rdfs: <" + NamespaceMapper.RDFS + ">."; List <String> tests = new List <string>() { prefixes + "@forAll :x :type . { :x a :type } => {:x rdfs:label \"This has a type\" } .", prefixes + "@forSome :x :type . { :x a :type } => {:x rdfs:label \"This has a type\" } .", prefixes + "@forAll :h . @forSome :g . :g :loves :h .", prefixes + "@forSome :h . @forAll :g . :g :loves :h .", prefixes + "{@forSome :a . :Joe :home :a } a :Formula . :Joe :phone \"555-1212\" ." }; Notation3Parser parser = new Notation3Parser(); Notation3Writer writer = new Notation3Writer(); foreach (String test in tests) { Graph g = new Graph(); g.BaseUri = new Uri("http://example.org/n3rules"); StringParser.Parse(g, test, parser); Console.WriteLine(StringWriter.Write(g, writer)); Console.WriteLine(); } }
public Form3() { InitializeComponent(); kb = new Graph(); Notation3Parser n3p = new Notation3Parser(); n3p.Load(kb, @"kbFile.n3"); string query1 = @" prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix process: <URN:process:> prefix input: <URN:input> prefix output: <URN:output> prefix sprint: <urn:sprint:> prefix owl: <http://www.w3.org/2002/07/owl#> SELECT DISTINCT ?sprint WHERE { ?pr rdfs:subClassOf ?var1; rdfs:comment ?var2; rdf:label ?var3; rdfs:Properties ?var4; rdf:Resource ?var5; owl:oneOf (?sprint); rdfs:seeAlso ?var6.}"; SparqlResultSet srRez = (SparqlResultSet)kb.ExecuteQuery(query1); treeView1.Nodes.Add("Number of Sprint in Project"); foreach (SparqlResult sr in srRez) { treeView1.Nodes.Add(sr["sprint"].ToString()); } TreeNode myNode = treeView1.Nodes[0]; }
private void button2_Click(object sender, EventArgs e) { yy = new Graph(); Notation3Parser n3p = new Notation3Parser(); n3p.Load(yy, @"AssertedFile.n3"); string query2 = @" prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix owl: <http://www.w3.org/2002/07/owl#> prefix sensor: <sensor:> prefix pixel: <pixel:> prefix detection: <detection:> prefix individual: <individual:> SELECT DISTINCT ?x ?a WHERE { ?x rdf:type ?a.}"; SparqlResultSet srRez1 = (SparqlResultSet)yy.ExecuteQuery(query2); foreach (SparqlResult sr1 in srRez1) { treeView2.Nodes.Add(sr1["x"].ToString() + " a " + sr1["a"].ToString()); } }
static void Main() { var parser = new Notation3Parser(); var graph = new Graph(); Console.WriteLine("Loading Notation-3 file."); //parser.Load(graph, @"n3\ontology.n3"); parser.Load(graph, @"n3\converter.n3"); Console.WriteLine("Loaded Notation-3 file."); Console.WriteLine("Nodes:"); foreach (Triple triple in graph.Triples) { Console.WriteLine("{0} {1} {2}", GetNodeString(triple.Subject), GetNodeString(triple.Predicate), GetNodeString(triple.Object)); } Console.WriteLine(); Console.WriteLine("Results of 'insomnia' query:"); Console.WriteLine(); SparqlResultSet resultSet = graph.ExecuteQuery(getInsomnia) as SparqlResultSet; if (resultSet != null) { Console.WriteLine("Results for variable 'name':"); for (int i = 0; i < resultSet.Count; i++) { SparqlResult result = resultSet[i]; Console.WriteLine("{0}. {1}", i + 1, result["name"]); } } Console.ReadLine(); }
public Form1() { InitializeComponent(); kb = new Graph(); Notation3Parser n3p = new Notation3Parser(); n3p.Load(kb, @"KB.n3"); string t = "Treeview of PROGCNN"; string query1 = @" prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix process: <process:> SELECT ?pr ?project ?lab WHERE { ?pr rdfs:subClassOf process:PROGCNN; rdf:label ?lab.}"; SparqlResultSet srRez = (SparqlResultSet)kb.ExecuteQuery(query1); treeView1.Nodes.Add("Tree View *-*"); treeView1.Nodes.Add(srRez[0]["lab"].ToString()); TreeNode myNode = treeView1.Nodes[0]; }
public KnowledgeBase(string s_Path) { g_Graph = new Graph(); n_Parser = new Notation3Parser(); this.s_Path = s_Path; // Получение БЗ из файла n_Parser.Load(g_Graph, s_Path); l_LayersKnowledgeNet = null; }
public KnowledgeBase(string s_Path) { g_Graph = new Graph(); n_Parser = new Notation3Parser(); d_DataAboutFormulas = null; this.s_Path = s_Path; // Получение БЗ из файла n_Parser.Load(g_Graph, this.s_Path); }
public void ParsingDefaultPrefixFallbackNotation3_2() { String data = @"@prefix : <http://default/ns#> . :subj :pred :obj ."; IRdfReader parser = new Notation3Parser(); Graph g = new Graph(); parser.Load(g, new StringReader(data)); Assert.False(g.IsEmpty); Assert.Equal(1, g.Triples.Count); }
private SparqlResultSet sparqlSend(string query) { var parser = new Notation3Parser(); var graph = new Graph(); parser.Load(graph, @"n3\\converter.n3"); SparqlResultSet resultSet = graph.ExecuteQuery(query) as SparqlResultSet; return(resultSet); }
private void button2_Click(object sender, EventArgs e) { var epochs = ""; yb = new Graph(); Notation3Parser n3p = new Notation3Parser(); n3p.Load(yb, @"Properties.n3"); string query1 = @" prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix process: <process:> SELECT ?pr ?epochs WHERE { ?pr rdf:epochs ?epochs.}"; SparqlResultSet srRez1 = (SparqlResultSet)yb.ExecuteQuery(query1); epochs = srRez1[0]["epochs"].ToString(); string query2 = @" prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix process: <process:> SELECT ?pr ?cnntrainingfilename ?project ?intrepetor WHERE { ?pr rdfs:subClassOf ?project; rdf:nntraining ?cnntrainingfilename; rdf:intrepetor ?intrepetor.}"; SparqlResultSet srRez2 = (SparqlResultSet)yb.ExecuteQuery(query2); var cnntrainingfilename = (srRez2[0]["cnntrainingfilename"].ToString()); var intrepetor = (srRez2[0]["intrepetor"].ToString()); var psi = new ProcessStartInfo(); psi.FileName = @intrepetor; var script = cnntrainingfilename; var epochs1 = int.Parse(epochs); psi.Arguments = string.Format("{0} {1}", script, epochs1); psi.UseShellExecute = true; psi.CreateNoWindow = false; psi.RedirectStandardOutput = false; psi.RedirectStandardError = false; var errors = ""; using (Process process = Process.Start(psi)) Console.WriteLine("Errors"); Console.WriteLine(errors); Console.WriteLine(); }
private void button4_Click(object sender, EventArgs e) { yb = new Graph(); Notation3Parser n3p = new Notation3Parser(); Notation3Writer n3w = new Notation3Writer(); n3p.Load(yb, @"Properties.n3"); INode subject = yb.CreateUriNode("process:retrain"); INode predicate = yb.CreateUriNode("rdf:epochs"); INode simple = yb.CreateLiteralNode(textBox1.Text); Extensions.Assert(yb, subject, predicate, simple); n3w.Save(yb, "C:\\Users\\misha\\OneDrive\\Рабочий стол\\proj1\\proj1\\bin\\Debug\\Properties.n3"); }
private void button1_Click(object sender, EventArgs e) { var parser = new Notation3Parser(); var graph = new Graph(); parser.Load(graph, @"rdf.txt"); parser.Load(graph, @"rdf.owl"); //var owlGraph = new Graph(); //owlGraph.LoadFromFile("rdf.owl", new TurtleParser()); int number_triplets; //number_triplets = graph.Triples.Count + owlGraph.Triples.Count; number_triplets = graph.Triples.Count; dataGridView1.RowCount = number_triplets; Column1.HeaderText = "Subject"; Column2.HeaderText = "Property"; Column3.HeaderText = "Object"; ListBox listbox1 = new ListBox(); ListBox listbox2 = new ListBox(); ListBox listbox3 = new ListBox(); for (int i = 0; i < dataGridView1.RowCount; i++) { foreach (Triple triple in graph.Triples) { listbox1.Items.Add(GetNodeString(triple.Subject)); listbox2.Items.Add(GetNodeString(triple.Predicate)); listbox3.Items.Add(GetNodeString(triple.Object)); dataGridView1.Rows[i].Cells[0].Value = listbox1.Items[i]; dataGridView1.Rows[i].Cells[1].Value = listbox2.Items[i]; dataGridView1.Rows[i].Cells[2].Value = listbox3.Items[i]; } /*foreach (Triple triple in owlGraph.Triples) * { * listbox1.Items.Add(GetNodeString(triple.Subject)); * listbox2.Items.Add(GetNodeString(triple.Predicate)); * listbox3.Items.Add(GetNodeString(triple.Object)); * dataGridView1.Rows[i].Cells[0].Value = listbox1.Items[i]; * dataGridView1.Rows[i].Cells[1].Value = listbox2.Items[i]; * dataGridView1.Rows[i].Cells[2].Value = listbox3.Items[i]; * }*/ } textBox2.Text = Convert.ToString(number_triplets); }
public void ParsingN3Variables() { String TestFragment = "@prefix rdfs: <" + NamespaceMapper.RDFS + ">. { ?s a ?type } => { ?s rdfs:label \"This has a type\" } ."; Notation3Parser parser = new Notation3Parser(); Graph g = new Graph(); StringParser.Parse(g, TestFragment, parser); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString()); } StringWriter.Write(g, new Notation3Writer()); }
private void button3_Click(object sender, EventArgs e) { textBox1.Text = "Nodes:" + Environment.NewLine; var parser = new Notation3Parser(); var graph = new Graph(); parser.Load(graph, @"n3\\converter.n3"); foreach (Triple triple in graph.Triples) { textBox1.Text += (GetNodeString(triple.Subject) + " " + GetNodeString(triple.Predicate) + " " + GetNodeString(triple.Object)); textBox1.Text += Environment.NewLine; } }
static private Graph LoadN3(string path) { var g = new Graph(); var parser = new Notation3Parser(); try { parser.Load(g, path); return(g); } catch { return(null); } }
private void button5_Click(object sender, EventArgs e) { //float nb_test_samples = float.Parse(textBox3.Text); var result = ""; yb = new Graph(); Notation3Parser n3p = new Notation3Parser(); n3p.Load(yb, @"Properties.n3"); string query8 = @" prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix process: <process:> SELECT ?pr ?CNNMMfile ?project ?intrepetor WHERE { ?pr rdfs:subClassOf ?project; rdf:CNNMMfile ?CNNMMfile; rdf:intrepetor ?intrepetor.}"; SparqlResultSet srRez9 = (SparqlResultSet)yb.ExecuteQuery(query8); var CNNMMfile = (srRez9[0]["CNNMMfile"].ToString()); var intrepetor1 = (srRez9[0]["intrepetor"].ToString()); var psi = new ProcessStartInfo(); psi.FileName = @intrepetor1; var script1 = CNNMMfile; psi.Arguments = string.Format("{0}", script1); psi.UseShellExecute = false; psi.CreateNoWindow = false; psi.RedirectStandardOutput = true; psi.RedirectStandardError = false; using (Process process = Process.Start(psi)) { using (StreamReader reader1 = process.StandardOutput) { result = reader1.ReadToEnd(); } } textBox2.Clear(); textBox2.AppendText(result); textBox2.AppendText(Environment.NewLine); }
private void button2_Click(object sender, EventArgs e) { listBox1_1.Items.Clear(); var parser = new Notation3Parser(); var graph = new Graph(); parser.Load(graph, @"rdf.txt"); parser.Load(graph, @"rdf.owl"); Column1.HeaderText = "Subject"; Column2.HeaderText = "Property"; Column3.HeaderText = "Object"; label4.Visible = true; ListBox listBox1 = new ListBox(); ListBox listBox2 = new ListBox(); ListBox listBox3 = new ListBox(); foreach (Triple triple in graph.Triples) { listBox1.Items.Add(GetNodeString(triple.Subject)); listBox2.Items.Add(GetNodeString(triple.Predicate)); listBox3.Items.Add(GetNodeString(triple.Object)); } ListBox class_property4 = new ListBox(); ListBox class_sub4 = new ListBox(); ListBox class_obj4 = new ListBox(); int i = 0; while (i < listBox1.Items.Count) { if (Convert.ToString(listBox3.Items[i]) == "ObjectProperty") { class_property4.Items.Add(listBox2.Items[i]); class_sub4.Items.Add(listBox1.Items[i]); class_obj4.Items.Add(listBox3.Items[i]); } i++; } textBox2.Text = Convert.ToString(class_property4.Items.Count); for (int J = 0; J < class_property4.Items.Count; J++) { listBox1_1.Items.Add(class_sub4.Items[J]); } listBox1_1.Items.Add("subClassOf"); listBox1_1.Items.Add("type"); listBox1_1.Items.Add("name"); label5.Visible = true; label5.Text = "ObjectProperty"; }
private void button1_Click(object sender, EventArgs e) { y = new Graph(); Notation3Writer n3w = new Notation3Writer(); b = new Graph(); Notation3Parser n3p = new Notation3Parser(); n3p.Load(b, @"reasoning.n3"); string query1 = @" prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix owl: <http://www.w3.org/2002/07/owl#> SELECT DISTINCT ?A ?B ?x WHERE { ?A rdfs:subClassOf ?B. ?x rdf:type ?Y. FILTER (?A = ?Y)}"; SparqlResultSet srRez1 = (SparqlResultSet)b.ExecuteQuery(query1); foreach (SparqlResult sr1 in srRez1) { n3p.Load(y, @"reasoning.n3"); INode subject = y.CreateUriNode(sr1["x"].ToString()); INode predicate = y.CreateUriNode("rdf:type");; INode simple = y.CreateUriNode(sr1["B"].ToString()); Extensions.Assert(y, subject, predicate, simple); } n3p.Load(y, @"Properties.n3"); string query10 = @" prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix process: <process:> SELECT ?pr ?AssertedFile ?project ?intrepetor WHERE { ?pr rdfs:subClassOf ?project; rdf:AssertedFile ?AssertedFile; rdf:intrepetor ?intrepetor.}"; SparqlResultSet srRez10 = (SparqlResultSet)y.ExecuteQuery(query10); var AssertedFile = (srRez10[0]["AssertedFile"].ToString()); n3w.Save(y, @AssertedFile); }
static void AQuery() { IGraph g = new Graph(); Notation3Parser n3parser = new Notation3Parser(); try { //Load using Filename n3parser.Load(g, "szepmuveszeti.n3"); } catch (RdfParseException parseEx) { //This indicates a parser error e.g unexpected character, premature end of input, invalid syntax etc. Console.WriteLine("Parser Error"); Console.WriteLine(parseEx.Message); } catch (RdfException rdfEx) { //This represents a RDF error e.g. illegal triple for the given syntax, undefined namespace Console.WriteLine("RDF Error"); Console.WriteLine(rdfEx.Message); } TripleStore store = new TripleStore(); store.Add(g); ISparqlDataset ds = new InMemoryDataset(g); //Get the Query processor LeviathanQueryProcessor processor = new LeviathanQueryProcessor(ds); SparqlQuery q = new SparqlQueryParser().ParseFromString("PREFIX ecrm:<http://erlangen-crm.org/current/> SELECT ?actor {?actor a ecrm:E39_Actor}"); Object results = processor.ProcessQuery(q); if (results is SparqlResultSet) { //Print out the Results //Console.WriteLine("working up to this "); SparqlResultSet rset = (SparqlResultSet)results; foreach (SparqlResult result in rset.Results) { Console.WriteLine(result.ToString()); } } }
private static void PerformanceTestWithDatabase() { Stopwatch sw = new Stopwatch(); sw.Start(); IGraph g = new Graph(); Notation3Parser n3parser = new Notation3Parser(); try { //Load using Filename n3parser.Load(g, "szepmuveszeti.n3"); } catch (RdfParseException parseEx) { //This indicates a parser error e.g unexpected character, premature end of input, invalid syntax etc. Console.WriteLine("Parser Error"); Console.WriteLine(parseEx.Message); } catch (RdfException rdfEx) { //This represents a RDF error e.g. illegal triple for the given syntax, undefined namespace Console.WriteLine("RDF Error"); Console.WriteLine(rdfEx.Message); } IBlankNode b = g.GetBlankNode("nodeID"); if (b != null) { Console.WriteLine("Blank Node with ID " + b.InternalID + " exists in the Graph"); } else { Console.WriteLine("No Blank Node with the given ID existed in the Graph"); } sw.Stop(); Console.WriteLine("Load time: " + sw.ElapsedMilliseconds + " ms"); }
private void tampil_5(object sender, EventArgs e) { string sens1 = "Sensor1"; string butt = "Button"; string ReadPort1 = serialPort1.ReadLine(); if (ReadPort1.Contains(butt)) { string ReadPort11 = serialPort1.ReadLine(); if (ReadPort11.Contains(sens1)) { string[] Sensor1 = ReadPort11.Split(' '); string val = Sensor1[2]; textBox1.Text = "Nodes After Replace:" + Environment.NewLine; var parser = new Notation3Parser(); var graph = new Graph(); parser.Load(graph, @"n3\\converter.n3"); Triple R = new Triple( graph.CreateUriNode(new Uri("http://www.semanticweb.org/laith/ontologies/2017/10/untitled-ontology-11#" + "Interval_1")), graph.CreateUriNode(new Uri("http://www.semanticweb.org/laith/ontologies/2017/10/untitled-ontology-11#" + "Max")), graph.CreateLiteralNode(Convert.ToString("20"), new Uri("http://www.w3.org/2001/XMLSchema#integer"))); graph.Retract(R); Triple A = new Triple( graph.CreateUriNode(new Uri("http://www.semanticweb.org/laith/ontologies/2017/10/untitled-ontology-11#" + "Interval_1")), graph.CreateUriNode(new Uri("http://www.semanticweb.org/laith/ontologies/2017/10/untitled-ontology-11#" + "Max")), graph.CreateLiteralNode((Convert.ToString(val)), new Uri("http://www.w3.org/2001/XMLSchema#integer"))); graph.Assert(A); foreach (Triple triple in graph.Triples) { textBox1.Text += (GetNodeString(triple.Subject) + " " + GetNodeString(triple.Predicate) + " " + GetNodeString(triple.Object)); textBox1.Text += Environment.NewLine; } } } }
private void button4_Click(object sender, EventArgs e) { yb = new Graph(); Notation3Parser n3p = new Notation3Parser(); n3p.Load(yb, @"retrain.n3"); string query1 = @" prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix process: <URN:process:> SELECT ?pr ?epochs ?project WHERE { ?pr rdfs:subClassOf ?project; rdf:epochs ?epochs.}"; SparqlResultSet srRez1 = (SparqlResultSet)yb.ExecuteQuery(query1); var epochs = (srRez1[0]["epochs"].ToString()); var psi = new ProcessStartInfo(); psi.FileName = @"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python.exe"; var script = @"D:\Workspace\VS\ResearchMethods\Main_System.py"; psi.Arguments = $"\"{script}\""; psi.UseShellExecute = false; psi.CreateNoWindow = false; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; var errors = ""; using (Process process = Process.Start(psi)) { errors = process.StandardError.ReadToEnd(); } Console.WriteLine("Errors"); Console.WriteLine(errors); Console.WriteLine(); }
private static void ProcessTriplesDeserialization(Stream stream, IGraph graph, string accepted) { IRdfReader reader = null; switch (accepted) { case TextTurtle: case ApplicationTurtle: case ApplicationXTurtle: case TextNTriplesTurtle: reader = new TurtleParser(); break; case ApplicationOwlXml: case ApplicationRdfXml: reader = new RdfXmlParser(); break; case ApplicationNTriples: case ApplicationNTriples2: case ApplicationXnTriples: case ApplicationRdfTriples: case TextPlain: reader = new NTriplesParser(); break; case TextN3: case TextRdfN3: reader = new Notation3Parser(); break; } using (var textWriter = new StreamReader(stream)) { reader.Load(graph, textWriter); } }
public Form1() { InitializeComponent(); kb = new Graph(); Notation3Parser n3p = new Notation3Parser(); n3p.Load(kb, @"kbFile.n3"); string query1 = @" prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix process: <URN:process:> prefix input: <URN:input> prefix output: <URN:output> SELECT ?pr ?label WHERE { ?pr rdfs:subClassOf process:AMPBB; rdf:label ?label .}"; SparqlResultSet srRez = (SparqlResultSet)kb.ExecuteQuery(query1); treeView1.Nodes.Add("TREE_VIEW_OF_AMPBB"); treeView1.Nodes.Add(srRez[0]["label"].ToString()); TreeNode myNode = treeView1.Nodes[0]; }
// Освобождение ресурсов public void Dispose() { g_Graph.Dispose(); n_Parser = null; l_LayersKnowledgeNet = null; }
public static Object LoadFromReader(Reader r, string baseUri, org.openrdf.rio.RDFFormat rdff) { Object obj; if (rdff == dotSesameFormats.RDFFormat.N3) { obj = new Graph(); if (baseUri != null) { ((IGraph)obj).BaseUri = new Uri(baseUri); } Notation3Parser parser = new Notation3Parser(); parser.Load((IGraph)obj, r.ToDotNetReadableStream()); } else if (rdff == dotSesameFormats.RDFFormat.NTRIPLES) { obj = new Graph(); if (baseUri != null) { ((IGraph)obj).BaseUri = new Uri(baseUri); } NTriplesParser parser = new NTriplesParser(); parser.Load((IGraph)obj, r.ToDotNetReadableStream()); } else if (rdff == dotSesameFormats.RDFFormat.RDFXML) { obj = new Graph(); if (baseUri != null) { ((IGraph)obj).BaseUri = new Uri(baseUri); } RdfXmlParser parser = new RdfXmlParser(); parser.Load((IGraph)obj, r.ToDotNetReadableStream()); } else if (rdff == dotSesameFormats.RDFFormat.TRIG) { obj = new TripleStore(); TriGParser trig = new TriGParser(); trig.Load((ITripleStore)obj, new StreamParams(r.ToDotNetReadableStream().BaseStream)); } else if (rdff == dotSesameFormats.RDFFormat.TRIX) { obj = new TripleStore(); TriXParser trix = new TriXParser(); trix.Load((ITripleStore)obj, new StreamParams(r.ToDotNetReadableStream().BaseStream)); } else if (rdff == dotSesameFormats.RDFFormat.TURTLE) { obj = new Graph(); if (baseUri != null) { ((IGraph)obj).BaseUri = new Uri(baseUri); } TurtleParser parser = new TurtleParser(); parser.Load((IGraph)obj, r.ToDotNetReadableStream()); } else { throw new RdfParserSelectionException("The given Input Format is not supported by dotNetRDF"); } return(obj); }
/// <summary> /// Internal Method which performs multi-threaded reading of data /// </summary> private void LoadGraphs(FolderStoreParserContext context) { //Create the relevant Parser IRdfReader parser; switch (context.Format) { case FolderStoreFormat.Turtle: parser = new TurtleParser(); break; case FolderStoreFormat.Notation3: parser = new Notation3Parser(); break; case FolderStoreFormat.RdfXml: parser = new RdfXmlParser(); break; default: parser = new TurtleParser(); break; } try { String file = context.GetNextFilename(); while (file != null) { //Read from Disk Graph g = new Graph(); String sourceFile = Path.Combine(context.Folder, file); parser.Load(g, sourceFile); //Add to Graph Collection foreach (Triple t in g.Triples) { if (context.Terminated) { break; } if (!context.Handler.HandleTriple(t)) { ParserHelper.Stop(); } } if (context.Terminated) { break; } //Get the Next Filename file = context.GetNextFilename(); } } catch (ThreadAbortException) { //We've been terminated, don't do anything #if !SILVERLIGHT Thread.ResetAbort(); #endif } catch (RdfParsingTerminatedException) { context.Terminated = true; context.ClearFilenames(); } catch (Exception ex) { throw new RdfStorageException("Error in Threaded Reader in Thread ID " + Thread.CurrentThread.ManagedThreadId, ex); } }
private void button7_Click(object sender, EventArgs e) { var graph = new Graph(); var parser = new Notation3Parser(); parser.Load(graph, @"rdf.txt"); parser.Load(graph, @"rdf.owl"); ListBox listBox1 = new ListBox(); ListBox listBox2 = new ListBox(); ListBox listBox3 = new ListBox(); foreach (Triple triple in graph.Triples) { listBox1.Items.Add(triple.Subject); listBox2.Items.Add(triple.Object); listBox3.Items.Add(triple.Predicate); } listBox1_1.Items.Clear(); listBox1_1.Items.Clear(); //int sel1 = comboBox1.SelectedIndex; //Object sel11 = comboBox1.SelectedItem; //string sub = sel11.ToString(); //sub = " :" + sub; string getInsomnia = @" PREFIX :<http://wopqw.blogspot.com/> PREFIX schema:<http://schema.org/> PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> PREFIX foaf:<http://xmlns.com/foaf/0.1/> PREFIX dbo:<http://dbpedia.org/ontology/> PREFIX yago:<http://yago-knowledge.org/resource/> PREFIX skos:<http://www.w3.org/2004/02/skos/core/> PREFIX dcterms:<http://purl.org/dc/elements/1.1/subject> PREFIX oplweb:<http://www.openlinksw.com/schemas/oplweb#> PREFIX cc:<https://creativecommons.org/ns#> SELECT ?sub ?prop ?obj WHERE { ?sub ?prop ?obj. }"; string s = ""; SparqlResultSet resultSet = graph.ExecuteQuery(getInsomnia) as SparqlResultSet; dataGridView1.RowCount = resultSet.Count + 1; var subjects = new List <string>(); var props = new List <string>(); var objs = new List <string>(); for (int i = 0; i < resultSet.Count; i++) { SparqlResult result = resultSet[i]; if (GetNodeString(result["prop"]).Contains("manage") || GetNodeString(result["prop"]).Contains("canCall") || GetNodeString(result["prop"]).Contains("isCausedBy") || GetNodeString(result["prop"]).Contains("isPartOf") || GetNodeString(result["prop"]).Contains("hasProperty")) { subjects.Add(GetNodeString(resultSet[i]["sub"])); props.Add(GetNodeString(resultSet[i]["prop"])); objs.Add(GetNodeString(resultSet[i]["obj"])); } } var zipped = props.Zip(subjects, (prop, subj) => Tuple.Create(prop, subj)).Zip(objs, (t1, obj) => Tuple.Create(t1.Item2, t1.Item1, obj)); zipped.GroupBy(tuple => Tuple.Create(tuple.Item1, tuple.Item2)) .Where(group => group.Count() > 1) .SelectMany(group => group) .Select((el, i) => Tuple.Create(i, el)) .ToList() .ForEach(tuple => { dataGridView1.Rows[tuple.Item1].Cells[0].Value = tuple.Item2.Item1; dataGridView1.Rows[tuple.Item1].Cells[1].Value = tuple.Item2.Item2; dataGridView1.Rows[tuple.Item1].Cells[2].Value = tuple.Item2.Item3; } ); }
public Form1() { InitializeComponent(); //загружаем данные из файла в граф var parser = new Notation3Parser(); var graph = new Graph(); parser.Load(graph, @"rdf.txt"); //var owlGraph = new Graph(); //owlGraph.LoadFromFile("rdf.owl", new TurtleParser()); ListBox listBox1 = new ListBox(); ListBox listBox2 = new ListBox(); ListBox listBox3 = new ListBox(); // распределяем элементы трипла по спискам foreach (Triple triple in graph.Triples) { listBox1.Items.Add(GetNodeString(triple.Subject)); listBox2.Items.Add(GetNodeString(triple.Object)); listBox3.Items.Add(GetNodeString(triple.Predicate)); } /*foreach (Triple triple in owlGraph.Triples) * { * listBox1.Items.Add(GetNodeString(triple.Subject)); * listBox2.Items.Add(GetNodeString(triple.Object)); * listBox3.Items.Add(GetNodeString(triple.Predicate)); * }*/ //выводит все объекты, субъекты и индивиды в комбобокс без повторений for (int i = 0; i < listBox1.Items.Count; i++) { if (list1.Items.IndexOf(listBox1.Items[i]) == -1) { list1.Items.Add(listBox1.Items[i]); } } for (int i = 0; i < list1.Items.Count; i++) { comboBox1.Items.Add(list1.Items[i]); } for (int i = 0; i < listBox2.Items.Count; i++) { if (list2.Items.IndexOf(listBox2.Items[i]) == -1) { list2.Items.Add(listBox2.Items[i]); } } for (int i = 0; i < list2.Items.Count; i++) { comboBox2.Items.Add(list2.Items[i]); } for (int i = 0; i < listBox3.Items.Count; i++) { if (list3.Items.IndexOf(listBox3.Items[i]) == -1) { list3.Items.Add(listBox3.Items[i]); } } for (int i = 0; i < list3.Items.Count; i++) { comboBox3.Items.Add(list3.Items[i]); } }
private void button5_Click(object sender, EventArgs e) { var graph = new Graph(); var parser = new Notation3Parser(); parser.Load(graph, @"rdf.txt"); parser.Load(graph, @"rdf.owl"); ListBox listBox1 = new ListBox(); ListBox listBox2 = new ListBox(); ListBox listBox3 = new ListBox(); foreach (Triple triple in graph.Triples) { listBox1.Items.Add(triple.Subject); listBox2.Items.Add(triple.Object); listBox3.Items.Add(triple.Predicate); } // ищет все триплы для заданного субъекта if (comboBox1.Text != "" && comboBox3.Text == "" && comboBox2.Text == "") { listBox1_1.Items.Clear(); int sel1 = comboBox1.SelectedIndex; Object sel11 = comboBox1.SelectedItem; string sub = sel11.ToString(); sub = " :" + sub; string getInsomnia = @" PREFIX :<http://wopqw.blogspot.com/> PREFIX schema:<http://schema.org/> PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> PREFIX foaf:<http://xmlns.com/foaf/0.1/> PREFIX dbo:<http://dbpedia.org/ontology/> PREFIX yago:<http://yago-knowledge.org/resource/> PREFIX skos:<http://www.w3.org/2004/02/skos/core/> PREFIX dcterms:<http://purl.org/dc/elements/1.1/subject> PREFIX oplweb:<http://www.openlinksw.com/schemas/oplweb#> PREFIX cc:<https://creativecommons.org/ns#> SELECT ?prop ?obj WHERE { " + sub + @" ?prop ?obj . }"; string s = ""; SparqlResultSet resultSet = graph.ExecuteQuery(getInsomnia) as SparqlResultSet; dataGridView1.RowCount = resultSet.Count + 1; if (resultSet != null) { for (int i = 0; i < resultSet.Count; i++) { SparqlResult result = resultSet[i]; dataGridView1.Rows[i].Cells[0].Value = ""; dataGridView1.Rows[i].Cells[1].Value = GetNodeString(result["prop"]); dataGridView1.Rows[i].Cells[2].Value = GetNodeString(result["obj"]); } } } // ищет все триплы для заданного свойства if (comboBox3.Text != "" && comboBox1.Text == "" && comboBox2.Text == "") { listBox1_1.Items.Clear(); int sel2 = comboBox3.SelectedIndex; Object sel22 = comboBox3.SelectedItem; string prop = sel22.ToString(); if (prop == "isDefinedBy") { prop = "oplweb:" + prop; } else if (prop.StartsWith("type")) { prop = "rdf:" + prop; } else if (prop.StartsWith("subClassOf")) { prop = "rdfs:" + prop; } else if (prop.StartsWith("isPartOf")) { prop = "schema:" + prop; } else if (prop.StartsWith("name")) { prop = "foaf:" + prop; } else if (prop.StartsWith("license")) { prop = "cc:" + prop; } else if (prop.StartsWith("morePermissions")) { prop = "cc:" + prop; } else if (prop.StartsWith("attributionName")) { prop = "cc:" + prop; } else if (prop.StartsWith("memberList")) { prop = "skos:" + prop; } else if (prop.StartsWith("member")) { prop = "skos:" + prop; } else if (prop.StartsWith("subjectdescrip")) { prop = "skos:" + prop; } else if (prop.StartsWith("manage")) { prop = ":" + prop; } string getInsomnia = @" PREFIX :<http://wopqw.blogspot.com/> PREFIX schema:<http://schema.org/> PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> PREFIX foaf:<http://xmlns.com/foaf/0.1/> PREFIX dbo:<http://dbpedia.org/ontology/> PREFIX yago:<http://yago-knowledge.org/resource/> PREFIX skos:<http://www.w3.org/2004/02/skos/core/> PREFIX dcterms:<http://purl.org/dc/elements/1.1/subject> PREFIX oplweb:<http://www.openlinksw.com/schemas/oplweb#> PREFIX cc:<https://creativecommons.org/ns#> SELECT ?sub ?obj WHERE { ?sub " + prop + @" ?obj .}"; SparqlResultSet resultSet = graph.ExecuteQuery(getInsomnia) as SparqlResultSet; dataGridView1.RowCount = resultSet.Count + 1; if (resultSet != null) { for (int i = 0; i < resultSet.Count; i++) { SparqlResult result = resultSet[i]; dataGridView1.Rows[i].Cells[1].Value = ""; dataGridView1.Rows[i].Cells[0].Value = GetNodeString(result["sub"]); dataGridView1.Rows[i].Cells[2].Value = GetNodeString(result["obj"]); } } } // ищет все триплы для заданного объекта if (comboBox2.Text != "" && comboBox1.Text == "" && comboBox3.Text == "") { listBox1_1.Items.Clear(); int sel1 = comboBox2.SelectedIndex; Object sel11 = comboBox2.SelectedItem; string obj = sel11.ToString(); if (obj == "Individual") { obj = "rdf:type " + obj; } else if (obj == "Class") { obj = ":" + obj; } else if (obj == "ObjectProperty") { obj = ":" + obj; } else if (!obj.StartsWith("?")) { obj = ":" + obj; } string getInsomnia = @" PREFIX :<http://wopqw.blogspot.com/> PREFIX schema:<http://schema.org/> PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> PREFIX foaf:<http://xmlns.com/foaf/0.1/> PREFIX dbo:<http://dbpedia.org/ontology/> PREFIX yago:<http://yago-knowledge.org/resource/> PREFIX skos:<http://www.w3.org/2004/02/skos/core/> PREFIX dcterms:<http://purl.org/dc/elements/1.1/subject> PREFIX oplweb:<http://www.openlinksw.com/schemas/oplweb#> PREFIX cc:<https://creativecommons.org/ns#> SELECT ?sub ?prop WHERE { ?sub ?prop " + obj + @". }"; SparqlResultSet resultSet = graph.ExecuteQuery(getInsomnia) as SparqlResultSet; dataGridView1.RowCount = resultSet.Count + 1; if (resultSet != null) { for (int i = 0; i < resultSet.Count; i++) { SparqlResult result = resultSet[i]; dataGridView1.Rows[i].Cells[2].Value = ""; dataGridView1.Rows[i].Cells[1].Value = GetNodeString(result["prop"]); dataGridView1.Rows[i].Cells[0].Value = GetNodeString(result["sub"]); } } } // ищет свойства связывающее для субъекта и объекта if (comboBox1.Text != "" && comboBox2.Text != "" && comboBox3.Text == "") { int sel1 = comboBox1.SelectedIndex; Object sel11 = comboBox1.SelectedItem; string sub = sel11.ToString(); if (!sub.StartsWith("?")) { sub = ":" + sub; } int sel2 = comboBox2.SelectedIndex; Object sel22 = comboBox2.SelectedItem; string obj = sel22.ToString(); if (!obj.StartsWith("?")) { obj = ":" + obj; } string getInsomnia = @" PREFIX :<https://ddddtryyaiafarjfka.blogspot.ru/> SELECT ?prop WHERE { " + sub + @"?prop " + obj + @". }"; string s = ""; label5.Visible = true; label5.Text = "Properties"; SparqlResultSet resultSet = graph.ExecuteQuery(getInsomnia) as SparqlResultSet; dataGridView1.RowCount = resultSet.Count + 1; if (resultSet != null) { for (int i = 0; i < resultSet.Count; i++) { SparqlResult result = resultSet[i]; dataGridView1.Rows[i].Cells[2].Value = ""; dataGridView1.Rows[i].Cells[1].Value = GetNodeString(result["prop"]); dataGridView1.Rows[i].Cells[0].Value = ""; } } } // ищет все триплы для заданного субъекта и свойства if (comboBox1.Text != "" && comboBox3.Text != "" && comboBox2.Text == "") { int sel1 = comboBox1.SelectedIndex; Object sel11 = comboBox1.SelectedItem; string sub = sel11.ToString(); if (!sub.StartsWith("?")) { sub = " :" + sub; } int sel2 = comboBox3.SelectedIndex; Object sel22 = comboBox3.SelectedItem; string prop = sel22.ToString(); if (prop == "isDefinedBy") { prop = "oplweb:" + prop; } else if (prop.StartsWith("type")) { prop = "rdf:" + prop; } else if (prop.StartsWith("subClassOf")) { prop = "rdfs:" + prop; } else if (prop.StartsWith("isPartOf")) { prop = "schema:" + prop; } else if (prop.StartsWith("name")) { prop = "foaf:" + prop; } else if (prop.StartsWith("license")) { prop = "cc:" + prop; } else if (prop.StartsWith("morePermissions")) { prop = "cc:" + prop; } else if (prop.StartsWith("attributionName")) { prop = "cc:" + prop; } else if (prop.StartsWith("description")) { prop = "dcterms:" + prop; } else if (prop.StartsWith("manage")) { prop = ":" + prop; } string getInsomnia = @" PREFIX :<http://wopqw.blogspot.com/> PREFIX schema:<http://schema.org/> PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> PREFIX foaf:<http://xmlns.com/foaf/0.1/> PREFIX dbo:<http://dbpedia.org/ontology/> PREFIX yago:<http://yago-knowledge.org/resource/> PREFIX skos:<http://www.w3.org/2004/02/skos/core/> PREFIX dcterms:<http://purl.org/dc/elements/1.1/subject> PREFIX oplweb:<http://www.openlinksw.com/schemas/oplweb#> PREFIX cc:<https://creativecommons.org/ns#> SELECT ?prop ?obj WHERE { " + sub + " " + prop + @"?obj . }"; SparqlResultSet resultSet = graph.ExecuteQuery(getInsomnia) as SparqlResultSet; dataGridView1.RowCount = resultSet.Count + 1; if (resultSet != null) { for (int i = 0; i < resultSet.Count; i++) { SparqlResult result = resultSet[i]; dataGridView1.Rows[i].Cells[0].Value = ""; dataGridView1.Rows[i].Cells[1].Value = ""; dataGridView1.Rows[i].Cells[2].Value = GetNodeString(result["obj"]); } } } // ищет все триплы для заданного объекта и свойства if (comboBox2.Text != "" && comboBox3.Text != "" && comboBox1.Text == "") { int sel2 = comboBox2.SelectedIndex; Object sel22 = comboBox2.SelectedItem; string obj = sel22.ToString(); if (obj == "Individual") { obj = "rdf:type" + obj; } else if (obj == "Class") { obj = "rdf:type" + obj; } else if (obj == "ObjectProperty") { obj = "rdf:type:" + obj; } else if (!obj.StartsWith("?")) { obj = ":" + obj; } int sel3 = comboBox3.SelectedIndex; Object sel33 = comboBox3.SelectedItem; string prop = sel33.ToString(); if (prop == "isDefinedBy") { prop = "oplweb:" + prop; } else if (prop.StartsWith("type")) { prop = "rdf:" + prop; } else if (prop.StartsWith("subClassOf")) { prop = "rdfs:" + prop; } else if (prop.StartsWith("isPartOf")) { prop = "schema:" + prop; } else if (prop.StartsWith("name")) { prop = "foaf:" + prop; } else if (prop.StartsWith("license")) { prop = "cc:" + prop; } else if (prop.StartsWith("morePermissions")) { prop = "cc:" + prop; } else if (prop.StartsWith("attributionName")) { prop = "cc:" + prop; } else if (prop.StartsWith("description")) { prop = "dcterms:" + prop; } else if (prop.StartsWith("manage")) { prop = ":" + prop; } string getInsomnia = @" PREFIX :<http://wopqw.blogspot.com/> PREFIX schema:<http://schema.org/> PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> PREFIX foaf:<http://xmlns.com/foaf/0.1/> PREFIX dbo:<http://dbpedia.org/ontology/> PREFIX yago:<http://yago-knowledge.org/resource/> PREFIX skos:<http://www.w3.org/2004/02/skos/core/> PREFIX dcterms:<http://purl.org/dc/elements/1.1/subject> PREFIX oplweb:<http://www.openlinksw.com/schemas/oplweb#> PREFIX cc:<https://creativecommons.org/ns#> SELECT ?sub WHERE { ?sub " + prop + " " + obj + @". }"; SparqlResultSet resultSet = graph.ExecuteQuery(getInsomnia) as SparqlResultSet; dataGridView1.RowCount = resultSet.Count + 1; if (resultSet != null) { for (int i = 0; i < resultSet.Count; i++) { SparqlResult result = resultSet[i]; dataGridView1.Rows[i].Cells[2].Value = ""; dataGridView1.Rows[i].Cells[1].Value = ""; dataGridView1.Rows[i].Cells[0].Value = GetNodeString(result["sub"]); } } } }