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 ClassificationOwlNodes() { ListOwlClass = new List <OwlClass>(); ListOwlProperty = new List <OwlProperty>(); ListOwlIndividual = new List <OwlIndividual>(); ListOwlDatatypeProperty = new List <OwlDatatypeProperty>(); IDictionaryEnumerator enumerator = (IDictionaryEnumerator)OwlGraph.Nodes.GetEnumerator(); while (enumerator.MoveNext()) { OwlNode owlNode = (OwlNode)OwlGraph.Nodes[(string)enumerator.Key]; if (!owlNode.IsAnonymous()) { if (owlNode is OwlClass) { ListOwlClass.Add((OwlClass)owlNode); } if (owlNode is OwlProperty) { ListOwlProperty.Add((OwlProperty)owlNode); } if (owlNode is OwlIndividual) { ListOwlIndividual.Add((OwlIndividual)owlNode); } if (owlNode is OwlDatatypeProperty) { ListOwlDatatypeProperty.Add((OwlDatatypeProperty)owlNode); } } } WriteStructure(); }
private void lbIndividuals_SelectedIndexChanged(object sender, EventArgs e) { tvDataProperty.Nodes.Clear(); foreach (OwlIndividual individual in ListOwlIndividual) { if (ConvertNameNode(individual) == lbIndividuals.Text) { TreeNode hasKeyWord = new TreeNode("HasKeyWord"); TreeNode hasScript = new TreeNode("HasScript"); TreeNode hasTable = new TreeNode("HasTable"); foreach (OwlEdge owlAttribute in individual.ChildEdges) { OwlNode attribute = (OwlNode)(owlAttribute.ChildNode); if (OntologyForm.ConvertNameNode(owlAttribute) == "HasKeyWord") { hasKeyWord.Nodes.Add(attribute.ID); } if (OntologyForm.ConvertNameNode(owlAttribute) == "HasScript") { hasScript.Nodes.Add(attribute.ID); } if (OntologyForm.ConvertNameNode(owlAttribute) == "HasTable") { hasTable.Nodes.Add(attribute.ID); } } tvDataProperty.Nodes.Add(hasKeyWord); tvDataProperty.Nodes.Add(hasScript); tvDataProperty.Nodes.Add(hasTable); tvDataProperty.ExpandAll(); break; } } }
Dictionary <string, List <string> > GetNonVisualFeatures(IOwlLiteral literal) { Dictionary <string, List <string> > result = new Dictionary <string, List <string> >(); OwlNode nodeClass = (OwlNode)literal.ParentEdges[0].ParentNode; foreach (IOwlEdge edge in nodeClass.ChildEdges) { string edgeMap = edge.ID; if (annotations.ContainsKey(edgeMap)) { string featureName = edgeMap.Substring(eAnnotation.Length); if (featureName[0] == '_') { featureName = featureName.Substring(1); if (!result.ContainsKey(featureName)) { result.Add(featureName, new List <string>()); } List <string> featuresValue = result[featureName]; string[] values = edge.ChildNode.ID.Split('\n'); featuresValue.AddRange(values); } } } return(result); }
List <MyWordInfo> GetMaplex(IOwlLiteral conceptLiteral) { try { OwlNode nodeClass = (OwlNode)conceptLiteral.ParentEdges[0].ParentNode; string Maplex = nodeClass.ChildEdges[eMaplex, 0].ChildNode.ID.Split('^')[0]; string[] allMaplexes = Maplex.Split('\n'); List <MyWordInfo> result = new List <MyWordInfo>(); for (int i = 0; i < allMaplexes.Length; i++) { MyWordInfo word = new MyWordInfo(); string[] parts = allMaplexes[i].Split('-'); word.Word = parts[0]; //TODO: handle the adjective and adverb switch (parts[1][0]) { case 'n': case 'N': word.Pos = PartsOfSpeech.Noun; break; case 'v': case 'V': word.Pos = PartsOfSpeech.Verb; break; case 'a': case 'A': if (parts[1][2] == 'j' || parts[1][2] == 'J') { word.Pos = PartsOfSpeech.Adj; } else { word.Pos = PartsOfSpeech.Adv; } break; default: word.Pos = PartsOfSpeech.Unknown; break; } int index = 1; for (; parts[1][index] < '0' || parts[1][index] > '9'; index++) { ; } string senseNumber = parts[1].Substring(index); word.Sense = int.Parse(senseNumber); result.Add(word); } return(result); } catch (Exception) { return(new List <MyWordInfo>()); } }
public static string ConvertNameNode(OwlNode owlNode) { string[] name = owlNode.ID.Split('#'); if (name.Length > 1) { return(name[1]); } else { return("---"); } }
string GetDefinition(IOwlLiteral conceptLiteral) { try { OwlNode nodeClass = (OwlNode)conceptLiteral.ParentEdges[0].ParentNode; return(nodeClass.ChildEdges[eDefinition, 0].ChildNode.ID.Split('^')[0]); } catch (Exception) { return(""); } }
private void WriteTree(OwlClass owlClass, TreeNode treeNode) { foreach (OwlEdge owlEdge in owlClass.ParentEdges) { OwlNode owlNode = (OwlNode)owlEdge.ParentNode; if (owlNode is OwlClass) { TreeNode childTreeNode = new TreeNode(ConvertNameNode(owlNode)); WriteTree((OwlClass)owlNode, childTreeNode); treeNode.Nodes.Add(childTreeNode); } } }
OwlLiteral GetParent(IOwlLiteral conceptLiteral) { try { OwlNode nodeClass = (OwlNode)conceptLiteral.ParentEdges[0].ParentNode; OwlNode parentClass = (OwlNode)nodeClass.ChildEdges[eSubClass, 0].ChildNode; return((OwlLiteral)parentClass.ChildEdges[eLabel, 0].ChildNode); } catch (Exception) { return(null); } }
List <OwlLiteral> GetChildren(IOwlLiteral conceptLiteral) { try { List <OwlLiteral> result = new List <OwlLiteral>(); OwlNode nodeClass = (OwlNode)conceptLiteral.ParentEdges[0].ParentNode; IOwlEdgeCollection edges = nodeClass.ParentEdges; foreach (IOwlEdge edge in edges) { OwlNode childClass = (OwlNode)edge.ParentNode; result.Add((OwlLiteral)childClass.ChildEdges[eLabel, 0].ChildNode); } return(result); } catch (Exception) { return(new List <OwlLiteral>()); } }
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"); } } } } } }
public void test3(string file) { IOwlParser parser = new OwlXmlParser(); IOwlGraph graph = parser.ParseOwl(file); Console.WriteLine("The nodes of the graph are:"); IDictionaryEnumerator nEnumerator = (IDictionaryEnumerator)graph.Nodes.GetEnumerator(); while (nEnumerator.MoveNext()) { OwlNode node = (OwlNode)graph.Nodes[(nEnumerator.Key).ToString()]; if (!node.IsAnonymous()) { Console.WriteLine(node.ID); } } Console.WriteLine(Environment.NewLine); Console.WriteLine("Retrieving some specific data:"); IOwlNode hotelNode = (IOwlNode)graph.Nodes["http://www.owl-ontologies.com/travel.owl#Hotel"]; Console.WriteLine(Environment.NewLine); Console.WriteLine("The edges are: "); OwlEdgeCollection edges = (OwlEdgeCollection)hotelNode.ChildEdges; foreach (OwlEdge e in edges) { Console.WriteLine(e.ID); } Console.WriteLine("The subClassOf edges are:"); IOwlEdgeList subclassEdges = (IOwlEdgeList)hotelNode.ChildEdges["http://www.w3.org/2000/01/rdf-schema#subClassOf"]; foreach (OwlEdge s in subclassEdges) { Console.WriteLine(s.ChildNode.ID); } }
public void test4(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 OwlClass because we are looking for classes OwlClass clsNode = node as OwlClass; // If clsNode is different from null, then we are dealing with an OwlClass -> OK // If the clsNode is not anonymous, means that we have a class with a proper name -> OK if ((clsNode != null) && (!clsNode.IsAnonymous())) { // So, now we have a good owl-class, we will look for any subClassOf relations (edges) IOwlEdgeList subclassEdges = (IOwlEdgeList)node.ChildEdges["http://www.w3.org/2000/01/rdf-schema#subClassOf"]; if (subclassEdges != null) { // We will list all the edges and check if the target of the edge is the class we want to // have as the superclass foreach (OwlEdge s in subclassEdges) { if (s.ChildNode.ID == "http://www.owl-ontologies.com/travel.owl#Accommodation") { Console.WriteLine(node.ID); } } } } } }
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 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(); }
private IEnumerator OpenOwl() { string filename = m_OwlFile; IOwlParser parser = new OwlXmlParser(); m_OwlGraph = parser.ParseOwl(filename); m_numNodes = m_OwlGraph.Nodes.Count; m_winText.text += "There are " + m_numNodes + " node(s) in the ontology '" + m_OwlFile + "'\n"; string oldText = m_winText.text; IDictionaryEnumerator nodeIter = (IDictionaryEnumerator)m_OwlGraph.Nodes.GetEnumerator(); int cnt = 0; while (nodeIter.MoveNext()) { //string owlKey = (nodeIter.Key).ToString(); string owlKey = ((OwlNode)nodeIter.Value).ID; OwlNode owlNode = (OwlNode)nodeIter.Value; if (owlNode.IsAnonymous()) { continue; } cnt++; NodeInstance graphNode = new NodeInstance(); graphNode.m_owlNode = owlNode; graphNode.m_pathSegments = new ArrayList(); //Debug.Log("owlKey = <" + owlKey + ">"); //Debug.Log("owlNode = " + owlNode); var uri = new Uri(owlKey); //Debug.Log("absURI = " + uri.AbsoluteUri); //Debug.Log("path = " + uri.PathAndQuery); //Debug.Log("host = " + uri.Host); // build up the node's path segments graphNode.m_pathSegments.Add(uri.Host); foreach (string element in uri.Segments) { //if (element == "/") continue; graphNode.m_pathSegments.Add(element);//.TrimEnd('/')); } if (uri.Fragment != null) { graphNode.m_pathSegments[graphNode.m_pathSegments.Count - 1] += (uri.Fragment); } OwlTreeNode owlTreeNode = m_owlNodeTree.addNode(graphNode); graphNode.m_treeNode = owlTreeNode; //statsElem.mNode = graphNode; m_NodeDictionary.Add(owlKey, graphNode); if (cnt % m_addElementInterval == 0) { string[] dots = { ".", "..", "..." }; for (int jj = 0; jj < 3; jj++) { m_winText.text = oldText + "Opening OWL file" + dots[cnt % 3]; } //Debug.Log("cnt = " + cnt); if (m_testing) { yield break; } else { yield return(null);// new WaitForSeconds(0.052f); } } } m_winText.text = oldText; yield return(null); }
public OwlItem(OwlNode owlNode) { this.owlNode = owlNode; }