public void test9(string file) { IOwlParser parser = new OwlXmlParser(); IOwlGraph graph = parser.ParseOwl(file); Console.WriteLine("Retrieving some specific data:"); // Here we will retrieve the enumerator in order to get all the nodes from the file IDictionaryEnumerator nEnumerator = (IDictionaryEnumerator)graph.Nodes.GetEnumerator(); while (nEnumerator.MoveNext()) { // Get the node from the graph OwlNode node = (OwlNode)graph.Nodes[(nEnumerator.Key).ToString()]; // We will cast the node to a OwlIndividual because we are looking for individuals OwlIndividual indNode = node as OwlIndividual; // If indNode is different from null, then we are dealing with an OwlIndividual -> OK // If the indNode is not anonymous, means that we have an individual with a proper name -> OK if ((indNode != null) && (!indNode.IsAnonymous())) { // So, now we have a good owl-individual Console.WriteLine(indNode.ID); } } }
private void ExtractFactsFromIndividual(OwlIndividual owlIndividual, TreeNode nodeIndividual, string text) { if (owlIndividual is OwlIndividual) { List <string> keyWords = new List <string>(); string script = ""; string table = ""; foreach (OwlEdge owlAttribute in owlIndividual.ChildEdges) { if (OntologyForm.ConvertNameNode(owlAttribute) == "HasKeyWord") { OwlNode Attribute = (OwlNode)(owlAttribute.ChildNode); keyWords.Add(Attribute.ID); } if (OntologyForm.ConvertNameNode(owlAttribute) == "HasScript") { OwlNode attribute = (OwlNode)(owlAttribute.ChildNode); script = attribute.ID; } if (OntologyForm.ConvertNameNode(owlAttribute) == "HasTable") { OwlNode attribute = (OwlNode)(owlAttribute.ChildNode); table = attribute.ID; } } foreach (string fact in GetFacts(script, keyWords, text)) { facts.Add(new Fact(fact, table)); nodeIndividual.Nodes.Add(fact); } } }
private void MainExtractFacts(OwlClass owlClass, string text) { if (factsExtracted) { return; } string owlClassName = OntologyForm.ConvertNameNode(owlClass); foreach (OwlEdge owlEdge in owlClass.ParentEdges) { OwlIndividual owlIndividual = (OwlIndividual)(owlEdge.ParentNode); string owlIndividualName = OntologyForm.ConvertNameNode(owlIndividual); TreeNode nodeIndividual = new TreeNode(owlIndividualName); try { ExtractFactsFromIndividual(owlIndividual, nodeIndividual, text); nodes.Add(nodeIndividual); } catch (Exception exception) { nodes.Add(new TreeNode(owlIndividualName + ": " + exception.Message)); } } factsExtracted = true; }
public void test5(string file) { IOwlParser parser = new OwlXmlParser(); IOwlGraph graph = parser.ParseOwl(file); string baseUri = "http://www.owl-ontologies.com/travel.owl#"; OwlClass hotelNode = (OwlClass)graph.Nodes["http://www.owl-ontologies.com/travel.owl#LuxuryHotel"]; OwlIndividual newHotel = new OwlIndividual(baseUri + "PellensPalace", hotelNode); graph.Nodes.Add(newHotel); IOwlGenerator generator = new OwlXmlGenerator(); generator.GenerateOwl(graph, @"c:\travelnew.owl"); }
public void test2() { OwlGraph ontology = new OwlGraph(); ontology.NameSpaces["xmlns:" + OwlNamespaceCollection.OwlNamespacePrefix] = OwlNamespaceCollection.OwlNamespace; ontology.NameSpaces["xmlns:" + OwlNamespaceCollection.RdfSchemaNamespacePrefix] = OwlNamespaceCollection.RdfSchemaNamespace; ontology.NameSpaces["xmlns:daml"] = "http://www.daml.org/2001/03/daml+oil#"; ontology.NameSpaces["xmlns:domain"] = "http://www.owl-ontologies.com/domain.owl#"; ontology.NameSpaces["xmlns:dc"] = "http://purl.org/dc/elements/1.1/"; ontology.NameSpaces["xmlns"] = "http://www.owl-ontologies.com/test.owl#"; ontology.NameSpaces["xml:base"] = "http://www.owl-ontologies.com/test.owl"; string baseUri = "http://www.owl-ontologies.com/test.owl#"; string altUri = "http://www.owl-ontologies.com/domain.owl#"; OwlOntology o = new OwlOntology(baseUri + "testOntology"); ontology.Nodes.Add(o); OwlClass a = new OwlClass(altUri + "ClassA"); //ontology.Nodes.Add(a); OwlIndividual inst = new OwlIndividual(baseUri + "Car", a); ontology.Nodes.Add(inst); //OwlClass b = new OwlClass(baseUri + "ClassB"); //ontology.Nodes.Add(b); // OwlClass concept = new OwlClass(altUri+node.Type); //Create a concept node // // OwlIndividual instance = new OwlIndividual(baseUri + node.ID, concept); // create an instance node as individual of concept node // _description.Nodes.Add(instance); //OwlEdge relation = new OwlEdge(OwlNamespaceCollection.RdfSchemaNamespace + "subClassOf"); //relation.AttachParentNode(a); //relation.AttachChildNode(b); //ontology.Edges.Add(relation); IOwlGenerator generator = new OwlXmlGenerator(); generator.GenerateOwl(ontology, @"c:\example2.owl"); }
public void test7(string file) { // First of all, we will create the parser object and parse the // file that we want IOwlParser parser = new OwlXmlParser(); IOwlGraph graph = parser.ParseOwl(file); // Lookup the instance of course for which we want to search for // the prerequisites, in our ontology, this is CourseA OwlIndividual instanceCourseA = (OwlIndividual)graph.Nodes["http://www.owl-ontologies.com/test.owl#CourseA"]; // With this loop, we will go through all the nodes in the graph IDictionaryEnumerator nEnumerator = (IDictionaryEnumerator)graph.Nodes.GetEnumerator(); while (nEnumerator.MoveNext()) { OwlNode node = (OwlNode)graph.Nodes[(nEnumerator.Key).ToString()]; // If the node we are encountering is an individual (so an // instance, then we will continue OwlIndividual i = node as OwlIndividual; if (i != null) { Console.WriteLine("Course: " + i.ID); // For this node, we will now look for all the edges that // we want, in our case the isPrerequisite edges IOwlEdgeList prerequisiteEdges = (IOwlEdgeList)node.ChildEdges["http://www.owl-ontologies.com/test.owl#isPrerequisite"]; if (prerequisiteEdges != null) { // Finally, a loop over all the edges and if we // encounter one which has an equal id to our // instance, then print the OK. foreach (OwlEdge s in prerequisiteEdges) { if (s.ChildNode.ID == instanceCourseA.ID) { Console.WriteLine("-- Ok"); } } } } } }
private void btnCalcCountKeyWords_Click(object sender, EventArgs e) { List <string> keyWords = new List <string>(); OwlClass owlMainClass = (OwlClass)((OwlItem)cbHeadOwlClass.SelectedItem).owlNode; foreach (OwlEdge owlEdge in owlMainClass.ParentEdges) { OwlIndividual owlIndividual = (OwlIndividual)owlEdge.ParentNode; foreach (OwlEdge owlAttribute in owlIndividual.ChildEdges) { if (OntologyForm.ConvertNameNode(owlAttribute) == "HasKeyWord") { OwlNode attribute = (OwlNode)(owlAttribute.ChildNode); keyWords.Add(attribute.ID); } } } foreach (ListViewItem lvi in lvReviews.SelectedItems) { Review review = (Review)lvi.Tag; review.CalcCountKeyWords(keyWords); lvi.SubItems[3].Text = review.CountKeyWords.ToString(); } }
public void test1(string file) { IOwlParser parser = new OwlXmlParser(); IOwlGraph graph = parser.ParseOwl(file); ArrayList errors = ((OwlParser)parser).Errors; ArrayList warnings = ((OwlParser)parser).Warnings; ArrayList messages = ((OwlParser)parser).Messages; //FileStream info = new FileStream("c:/info.txt", FileMode.OpenOrCreate); //StreamWriter sw = new StreamWriter(info); //sw.AutoFlush = true; //IOwlGenerator generator = new OwlXmlGenerator(); //generator.GenerateOwl(graph, @"c:\example1.owl"); //info = new FileStream("C:/generated.txt", FileMode.OpenOrCreate); //sw = new StreamWriter(info); //sw.AutoFlush = true; // foreach(string msg in messages) // { // sw.WriteLine(msg); // } // // Console.WriteLine("Graph parsed successfully with {0} errors and {1} warnings\n\n",errors.Count,warnings.Count); // // foreach(string err in errors) // { // Console.WriteLine("Error: "+err); // } // // foreach(string war in warnings) // { // Console.WriteLine("Warning: "+war); // } // // Console.WriteLine("The graph contains {0} node(s) and {1} edge(s).", graph.Nodes.Count, graph.Edges.Count); string baseuri = graph.NameSpaces["xmlns"]; Console.WriteLine("The basuri is " + baseuri); OwlClass owlAnnotation = new OwlClass(baseuri + "Annotation"); //Create a parent (Annotation) node to relate to OwlGraph newGraph = new OwlGraph(); newGraph.NameSpaces["xmlns:" + OwlNamespaceCollection.OwlNamespacePrefix] = OwlNamespaceCollection.OwlNamespace; newGraph.NameSpaces["xmlns:" + OwlNamespaceCollection.RdfSchemaNamespacePrefix] = OwlNamespaceCollection.RdfSchemaNamespace; newGraph.NameSpaces["xmlns:daml"] = "http://www.daml.org/2001/03/daml+oil#"; newGraph.NameSpaces["xmlns:domain"] = "http://www.owl-ontologies.com/domain.owl#"; newGraph.NameSpaces["xmlns:dc"] = "http://purl.org/dc/elements/1.1/"; newGraph.NameSpaces["xmlns"] = "http://www.owl-ontologies.com/test.owl#"; newGraph.NameSpaces["xml:base"] = "http://www.owl-ontologies.com/test.owl"; newGraph.NameSpaces["xmlns:meta"] = baseuri; string newUri = "http://www.owl-ontologies.com/test.owl#"; OwlIndividual pp = new OwlIndividual(newUri + "Test", owlAnnotation); //Create the annotation newGraph.Nodes.Add(pp); IOwlGenerator generator = new OwlXmlGenerator(); generator.GenerateOwl(newGraph, @"c:\example2.owl"); }
public void test9(string file) { parser = new OwlXmlParser(); graph = parser.ParseOwl(file); System.Windows.Forms.Form form = new System.Windows.Forms.Form(); form.Size = new Size(1200, 700); //create a viewer object viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); //create a graph object graph2 = new Microsoft.Msagl.Drawing.Graph("graph2"); graph2.LayoutAlgorithmSettings = new Microsoft.Msagl.Layout.MDS.MdsLayoutSettings(); form2 = new System.Windows.Forms.Form(); lista.Size = new Size(200, 30); lista.Location = new Point(40, 30); lista2.Size = new Size(200, 30); lista2.Location = new Point(40, 80); System.Windows.Forms.Button button = new System.Windows.Forms.Button(); button.Size = new Size(200, 30); button.Location = new Point(40, 130); button.Text = "Wybierz"; button.Click += button_click; IDictionaryEnumerator nEnumerator = (IDictionaryEnumerator)graph.Nodes.GetEnumerator(); while (nEnumerator.MoveNext()) { // Get the node from the graph OwlNode node = (OwlNode)graph.Nodes[(nEnumerator.Key).ToString()]; // We will cast the node to a OwlIndividual because we are looking for individuals OwlIndividual indNode = node as OwlIndividual; // If indNode is different from null, then we are dealing with an OwlIndividual -> OK // If the indNode is not anonymous, means that we have an individual with a proper name -> OK if ((indNode != null) && (!indNode.IsAnonymous())) { // So, now we have a good owl-individual Console.WriteLine(indNode.ID.Replace("urn:absolute:sample#", "") + ":"); foreach (OwlEdge a in indNode.ChildEdges) { Console.WriteLine((a.ParentNode.ID + " " + a.ID + " " + a.ChildNode.ID)); if (a.ChildNode.ID != "http://www.w3.org/2002/07/owl#NamedIndividual") { Microsoft.Msagl.Drawing.Edge edge = graph2.AddEdge(a.ParentNode.ID, a.ChildNode.ID); edge.LabelText = a.ID; if (!lista.Items.Contains(a.ParentNode.ID)) { lista.Items.Add(a.ParentNode.ID); lista2.Items.Add(a.ParentNode.ID); } } } /* * foreach (OwlEdge a in indNode.ParentEdges) * { * Console.WriteLine((a.ParentNode.ID + " " + a.ID + " " + a.ChildNode.ID).Replace("urn:absolute:sample#", "").Replace("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "").Replace("http://www.w3.org/2000/01/rdf-schema#", "")); * } */ Console.Write("\n \n"); } } //bind the graph to the viewer viewer.Graph = graph2; //associate the viewer with the form form.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; form.Controls.Add(viewer); form.ResumeLayout(); //show the form form.Show(); form2.Controls.Add(lista); form2.Controls.Add(lista2); form2.Controls.Add(button); //show the form form2.ShowDialog(); //Console.WriteLine(graph.Edges.Count); Console.ReadLine(); }