/// <summary> /// Generate the OWL graph into a file represented by the uri /// </summary> /// <param name="graph">The graph which needs to be generated</param> /// <param name="filename">The name of the file to which the graph needs to be generated</param> public void GenerateOwl(IOwlGraph graph, string filename) { if (filename == null) { throw (new ArgumentNullException("The specified filename is a null reference")); } _owlDocument = new XmlDocument(); GenerateOwl(graph, _owlDocument); try { _owlDocument.Save(filename); } catch (XmlException xe) { OnError(xe); return; } catch (Exception e) { OnError(e); return; } }
OwlLiteral GetConcept(string conceptName) { //TODO: repair this function IOwlGraph graph = null; return((OwlLiteral)graph.Literals[conceptName]); }
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); } } }
/// <summary> /// Merges the srcGraph into this graph object /// </summary> /// <param name="srcGraph">An object that implements the IOwlGraph interace</param> /// <param name="skipDuplicateEdges">A flag that indicates whether duplicate edges present in both graphs should be skipped during the merge process.</param> public void Merge(IOwlGraph srcGraph, bool skipDuplicateEdges) { if (srcGraph == null) { return; } Hashtable literalsAdded = new Hashtable(); //go through all the nodes in the source graph IDictionaryEnumerator enumerator = (IDictionaryEnumerator)srcGraph.Nodes.GetEnumerator(); while (enumerator.MoveNext()) { //Console.WriteLine(((IOwlNode)(enumerator.Value)).ID); //add this node to the graph IOwlNode srcParentNode = (IOwlNode)enumerator.Value; IOwlNode destParentNode = AddNode(srcParentNode.ID); //go through all of the src node's child edges foreach (IOwlEdge srcChildEdge in srcParentNode.ChildEdges) { //for each of the src node's child edges do... IOwlNode destChildNode; if (srcChildEdge.ChildNode is IOwlLiteral) { IOwlLiteral srcChildLiteral = srcChildEdge.ChildNode as IOwlLiteral; literalsAdded[srcChildLiteral] = srcChildLiteral; destChildNode = AddLiteral(srcChildLiteral.Value, srcChildLiteral.LangID, srcChildLiteral.Datatype); } else { destChildNode = AddNode(srcChildEdge.ChildNode.ID); } //Now we have the parent and the child nodes added to the graph.. bool edgeExists = false; if (skipDuplicateEdges) { //does the new parent node and the new child node have an edge with the same ID as srcChildEdge? //go through all the child edges of destParentNode foreach (OwlEdge tempEdge in destParentNode.ChildEdges) { if ((tempEdge.ChildNode == destChildNode) && (tempEdge.ID == srcChildEdge.ID)) { edgeExists = true; break; } } } if (!skipDuplicateEdges || (skipDuplicateEdges && !edgeExists)) { OwlEdge destChildEdge = new OwlEdge(srcChildEdge.ID); destParentNode.AttachChildEdge(destChildEdge); destChildEdge.AttachChildNode(destChildNode); //add the edge to the graph AddEdge(destChildEdge); } } } }
/// <summary> /// Generates the OWL graph into an XmlDocument object /// </summary> /// <param name="graph">The graph which needs to be generated</param> /// <param name="doc">The XmlDocument object used as a destination for the graph</param> public void GenerateOwl(IOwlGraph graph, XmlDocument doc) { if (doc == null) { throw (new ArgumentNullException("The specified XmlDocument object is a null reference")); } Warnings.Clear(); Errors.Clear(); _visited.Clear(); XmlElement root = _owlDocument.CreateElement("rdf:RDF", OwlNamespaceCollection.RdfNamespace); _owlDocument.AppendChild(root); //Added by HM // Create an XML declaration. XmlDeclaration xmldecl = _owlDocument.CreateXmlDeclaration("1.0", null, null); xmldecl.Encoding = "UTF-8"; xmldecl.Standalone = "yes"; // Add the new node to the document. _owlDocument.InsertBefore(xmldecl, root); //End of HM addition _baseUri = graph.NameSpaces["xml:base"]; IDictionaryEnumerator nsEnumerator = (IDictionaryEnumerator)graph.NameSpaces.GetEnumerator(); while (nsEnumerator.MoveNext()) { // Write all the namespaces to the document XmlAttribute nsAttribute = _owlDocument.CreateAttribute((nsEnumerator.Key).ToString()); nsAttribute.Value = (nsEnumerator.Value).ToString(); root.Attributes.Append(nsAttribute); // Also insert the reversed namespaces into the a local variable _namespaces[nsEnumerator.Value.ToString()] = nsEnumerator.Key.ToString(); } IDictionaryEnumerator nEnumerator = (IDictionaryEnumerator)graph.Nodes.GetEnumerator(); while (nEnumerator.MoveNext()) { OwlNode node = (OwlNode)graph.Nodes[(nEnumerator.Key).ToString()]; if (!node.IsAnonymous()) { node.Accept(this, root); } } XmlComment comment = _owlDocument.CreateComment("This file has been generated by the OwlDotNetApi."); _owlDocument.AppendChild(comment); doc = _owlDocument; }
public void test6(string file) { IOwlParser parser = new OwlXmlParser(); IOwlGraph graph = parser.ParseOwl(file); IOwlGenerator generator = new OwlXmlGenerator(); generator.GenerateOwl(graph, @"c:\travelnew.owl"); }
public void InitializeReader(string path) { if(!File.Exists(path)) { throw new InvalidArgumentException( "Specified file not exists.", InvalidArgumentExceptionCode.InvalidFilePath); } filepath = path; owlGraph = owlParser.ParseOwl(path); }
/// <summary> /// Generate the OWL graph into a file represented by the object of type Uri /// </summary> /// <param name="graph">The graph which needs to be generated</param> /// <param name="uri">The Uri object representing the file to which the graph needs to be generated</param> public void GenerateOwl(IOwlGraph graph, Uri uri) { if (uri == null) { throw (new ArgumentNullException("The specified URI is a null reference")); } _owlDocument = new XmlDocument(); GenerateOwl(graph, _owlDocument); // Save the file to the correct uri // This is not supported at the moment }
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 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 test10(string file) { IOwlParser parser = new OwlXmlParser(); IOwlGraph graph = parser.ParseOwl(file); IOwlGenerator generator = new OwlXmlGenerator(); ArrayList errors = ((OwlGenerator)generator).Errors; ArrayList warnings = ((OwlGenerator)generator).Warnings; ArrayList messages = ((OwlGenerator)generator).Messages; FileStream info = new FileStream("c:/info.txt", FileMode.OpenOrCreate); StreamWriter sw = new StreamWriter(info); sw.AutoFlush = true; generator.GenerateOwl(graph, @"c:\test.owl"); foreach (string msg in messages) { sw.WriteLine(msg); } }
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); } } } } } }
public StartEventFactory(Page page, IOwlGraph graph) : base(page, graph) { }
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(); }
public IntermediateCatchEventFactory(Page page, IOwlGraph graph) : base(page, graph) { }
public TaskFactory(Page page, IOwlGraph graph) : base(page, graph) { }
public DataObjectFactory(Page page, IOwlGraph graph) : base(page, graph) { }
/// <summary> /// Parses the OWL at the given URI, into an existing graph /// </summary> /// <param name="uri">The Uri of the document to parse</param> /// <param name="graph">An object that implements the IOwlGraph interface that will be used as the destination graph</param> /// <returns>An object that implements the IOwlGraph interface</returns> public IOwlGraph ParseOwl(Uri uri, IOwlGraph graph) { if(uri == null) throw(new ArgumentNullException("The specified URI is a null reference")); //parses from a Uri. XmlDocument doc = new XmlDocument(); try { doc.Load(uri.ToString()); } catch(XmlException xe) { OnError(xe); return null; } catch(Exception e) { OnError(e); return null; } return ParseOwl(doc, graph); }
public SubProcessFactory(Page page, IOwlGraph graph) : base(page, graph) { }
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 FlowFactory(Page page, IOwlGraph graph) : base(page, graph) { }
public BaseFactory(Page page, IOwlGraph graph) { this._page = page; this._graph = graph; }
public GatewayFactory(Page page, IOwlGraph graph) : base(page, graph) { }
/// <summary> /// Parses the OWL from the given XmlDocument, into an existing graph using the given xml:base uri /// </summary> /// <param name="doc">The XmlDocument to use as the source of the XML data</param> /// <param name="graph">An object that implements the IOwlGraph interface</param> /// <param name="xmlbaseUri">The xml:base Uri to use incase one is not found in the XML data or the graph</param> /// <returns>An object that implements the IOwlGraph interface</returns> public IOwlGraph ParseOwl(XmlDocument doc, IOwlGraph graph, string xmlbaseUri) { //parses from the xml document //if doc is null throws an ArgumentNullException //looks for xml:base in doc //if xml:base is not found in doc then uses the xmlbaseUri //if xmlbaseUri is not a valid Uri it defaults to http://unknown.org/ if(doc == null) throw(new ArgumentNullException("The specified XmlDocument object is a null reference")); Warnings.Clear(); Errors.Clear(); //Start with the root XmlElement root = doc.DocumentElement; if(root.Name != "rdf:RDF") { if(root.Name.ToLower() == "rdf") OnWarning("Unqualified use of rdf as the root element name."); else OnWarning("Root element of an OWL document must be rdf:RDF"); } string oldXmlbaseUri = null; if(graph == null) { //Now create the OwlGraph _owlGraph = new OwlGraph(); } else { oldXmlbaseUri = graph.NameSpaces["xml:base"]; graph.NameSpaces.Remove("xml:base"); _owlGraph = graph; } //its an OWL Document so now get the namespace info int count = root.Attributes.Count; for(int i=0;i<count;i++) { try { string nsName = root.Attributes[i].Name; if(_owlGraph.NameSpaces[nsName] != null) OnWarning("Redefinition of namespace "+nsName); _owlGraph.NameSpaces[nsName] = root.Attributes[i].Value; } catch(ArgumentException ine) { OnWarning(ine.Message); } } string xbUri = _owlGraph.NameSpaces["xml:base"]; if(xbUri == null) { xbUri = doc.BaseURI; if(!IsValidUri(xbUri)) { xbUri = xmlbaseUri; if(!IsValidUri(xbUri)) { if(oldXmlbaseUri != null) xbUri = oldXmlbaseUri; else { OnWarning("Valid xml:base URI not found. Using http://unknown.org/"); xbUri = "http://unknown.org/"; } } } } //ignore and discard everything after the first # character int pos = xbUri.IndexOf('#'); if(pos != -1) { xbUri = xbUri.Remove(pos,xbUri.Length-pos); } //Now finally set the value of the xml:base Uri _owlGraph.NameSpaces["xml:base"] = xbUri; if(root.HasChildNodes) { count = root.ChildNodes.Count; for(int i=0;i<count;i++) { ProcessNode(root.ChildNodes[i], null); } } return _owlGraph; }
/// <summary> /// Parses the OWL from the given stream, into an existing graph using the given xml:base uri /// </summary> /// <param name="inStream">The Stream to use as the source of the XML data</param> /// <param name="graph">An object that implements the IOwlGraph interface</param> /// <param name="xmlbaseUri">The xml:base Uri to use incase one is not found in the XML data or the graph</param> /// <returns>An object that implements the IOwlGraph interface</returns> public IOwlGraph ParseOwl(Stream inStream, IOwlGraph graph, string xmlbaseUri) { //looks for xml:base in owl doc. //if not found, then uses xmlbaseUri //if xmlbaseUri is not a valid Uri it defaults to http://unknown.org/ if(inStream == null) throw(new ArgumentNullException("The specified input stream is a null reference")); XmlDocument doc = new XmlDocument(); try { doc.Load(inStream); } catch(XmlException xe) { OnError(xe); return null; } catch(Exception e) { OnError(e); return null; } return ParseOwl(doc, graph, xmlbaseUri); }
public SequenceFlowFactory(Page page, IOwlGraph graph) : base(page, graph) { }
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 LaneFactory(Page page, IOwlGraph graph) : base(page, graph) { }
/// <summary> /// Generate the OWL graph into a file represented by the object of type Uri /// </summary> /// <param name="graph">The graph which needs to be generated</param> /// <param name="uri">The Uri object representing the file to which the graph needs to be generated</param> public void GenerateOwl(IOwlGraph graph, Uri uri) { if(uri == null) throw(new ArgumentNullException("The specified URI is a null reference")); _owlDocument = new XmlDocument(); GenerateOwl(graph, _owlDocument); // Save the file to the correct uri // This is not supported at the moment }
/// <summary> /// Merges the srcGraph into this graph object /// </summary> /// <param name="srcGraph">An object that implements the IOwlGraph interace</param> /// <param name="skipDuplicateEdges">A flag that indicates whether duplicate edges present in both graphs should be skipped during the merge process.</param> public void Merge(IOwlGraph srcGraph, bool skipDuplicateEdges) { if(srcGraph == null) return; Hashtable literalsAdded = new Hashtable(); //go through all the nodes in the source graph IDictionaryEnumerator enumerator = (IDictionaryEnumerator)srcGraph.Nodes.GetEnumerator(); while(enumerator.MoveNext()) { //Console.WriteLine(((IOwlNode)(enumerator.Value)).ID); //add this node to the graph IOwlNode srcParentNode = (IOwlNode)enumerator.Value; IOwlNode destParentNode = AddNode(srcParentNode.ID); //go through all of the src node's child edges foreach(IOwlEdge srcChildEdge in srcParentNode.ChildEdges) { //for each of the src node's child edges do... IOwlNode destChildNode; if(srcChildEdge.ChildNode is IOwlLiteral) { IOwlLiteral srcChildLiteral = srcChildEdge.ChildNode as IOwlLiteral; literalsAdded[srcChildLiteral] = srcChildLiteral; destChildNode = AddLiteral(srcChildLiteral.Value, srcChildLiteral.LangID, srcChildLiteral.Datatype); } else { destChildNode = AddNode(srcChildEdge.ChildNode.ID); } //Now we have the parent and the child nodes added to the graph.. bool edgeExists = false; if(skipDuplicateEdges) { //does the new parent node and the new child node have an edge with the same ID as srcChildEdge? //go through all the child edges of destParentNode foreach(OwlEdge tempEdge in destParentNode.ChildEdges) { if((tempEdge.ChildNode == destChildNode) && (tempEdge.ID == srcChildEdge.ID)) { edgeExists = true; break; } } } if(!skipDuplicateEdges || (skipDuplicateEdges && !edgeExists)) { OwlEdge destChildEdge = new OwlEdge(srcChildEdge.ID); destParentNode.AttachChildEdge(destChildEdge); destChildEdge.AttachChildNode(destChildNode); //add the edge to the graph AddEdge(destChildEdge); } } } }
/// <summary> /// Generates the OWL graph into an XmlDocument object /// </summary> /// <param name="graph">The graph which needs to be generated</param> /// <param name="doc">The XmlDocument object used as a destination for the graph</param> public void GenerateOwl(IOwlGraph graph, XmlDocument doc) { if(doc == null) throw(new ArgumentNullException("The specified XmlDocument object is a null reference")); Warnings.Clear(); Errors.Clear(); XmlElement root = _owlDocument.CreateElement("rdf:RDF", OwlNamespaceCollection.RdfNamespace); _owlDocument.AppendChild(root); //Added by HM // Create an XML declaration. XmlDeclaration xmldecl = _owlDocument.CreateXmlDeclaration("1.0",null,null); xmldecl.Encoding="UTF-8"; xmldecl.Standalone="yes"; // Add the new node to the document. _owlDocument.InsertBefore(xmldecl, root); //End of HM addition _baseUri = graph.NameSpaces["xml:base"]; IDictionaryEnumerator nsEnumerator = (IDictionaryEnumerator)graph.NameSpaces.GetEnumerator(); while(nsEnumerator.MoveNext()) { // Write all the namespaces to the document XmlAttribute nsAttribute = _owlDocument.CreateAttribute((nsEnumerator.Key).ToString()); nsAttribute.Value = (nsEnumerator.Value).ToString(); root.Attributes.Append(nsAttribute); // Also insert the reversed namespaces into the a local variable _namespaces[nsEnumerator.Value.ToString()] = nsEnumerator.Key.ToString(); } IDictionaryEnumerator nEnumerator = (IDictionaryEnumerator)graph.Nodes.GetEnumerator(); while(nEnumerator.MoveNext()) { OwlNode node = (OwlNode)graph.Nodes[(nEnumerator.Key).ToString()]; if(!node.IsAnonymous()) node.Accept(this, root); } XmlComment comment = _owlDocument.CreateComment("This file has been generated by the OwlDotNetApi."); _owlDocument.AppendChild(comment); doc = _owlDocument; }
/// <summary> /// Parses the OWL from the given XmlDocument, into an existing graph /// </summary> /// <param name="doc">The XmlDocument to use as the source of the XML data</param> /// <param name="graph">An object that implements the IOwlGraph interface</param> /// <returns>An object that implements the IOwlGraph interface</returns> public IOwlGraph ParseOwl(XmlDocument doc, IOwlGraph graph) { return ParseOwl(doc,graph,null); }
/// <summary> /// Generate the OWL graph into a file represented by the uri /// </summary> /// <param name="graph">The graph which needs to be generated</param> /// <param name="filename">The name of the file to which the graph needs to be generated</param> public void GenerateOwl(IOwlGraph graph, string filename) { if(filename == null) throw(new ArgumentNullException("The specified filename is a null reference")); _owlDocument = new XmlDocument(); GenerateOwl(graph, _owlDocument); try { _owlDocument.Save(filename); } catch(XmlException xe) { OnError(xe); return; } catch(Exception e) { OnError(e); return; } }
/// <summary> /// Parses the OWL from a stream into an existing Graph /// </summary> /// <param name="inStream">The input stream for data</param> /// <param name="graph">An object that implements the IOwlGraph interface that will be used as the destination graph</param> /// <returns>An object that implements the IOwlGraph interface</returns> public IOwlGraph ParseOwl(Stream inStream, IOwlGraph graph) { return ParseOwl(inStream,graph, null); }
public void OWLtoPIM() { Dictionary <string, Assoc> Assocs = new Dictionary <string, Assoc>(); Dictionary <string, Attr> Attrs = new Dictionary <string, Attr>(); Dictionary <string, PIMClass> Classes = new Dictionary <string, PIMClass>(); Dictionary <string, Property> Attributes = new Dictionary <string, Property>(); Dictionary <string, Association> Associations = new Dictionary <string, Association>(); List <Generalization> Generalizations = new List <Generalization>(); List <Comment> Comments = new List <Comment>(); OpenFileDialog D = new OpenFileDialog(); D.Filter = "OWL File|*.owl|All files|*.*"; D.Title = "Select OWL file to import"; D.CheckFileExists = true; if (D.ShowDialog() != true) { return; } IOwlParser parser = new OwlXmlParser(); IOwlGraph graph = parser.ParseOwl(D.FileName); ArrayList errors = ((OwlParser)parser).Errors; ArrayList warnings = ((OwlParser)parser).Warnings; ArrayList messages = ((OwlParser)parser).Messages; /*IDictionaryEnumerator nEnumerator = (IDictionaryEnumerator)graph.Nodes.GetEnumerator(); * while (nEnumerator.MoveNext()) * { * OwlNode node = (OwlNode)graph.Nodes[(nEnumerator.Key).ToString()]; * IOwlClass C = node as IOwlClass; * if (C == null || C is IOwlRestriction) continue; * PIMClass pimClass = controller.ModelController.Model.AddClass() as PIMClass; * //TODO: Catch duplicit IDs * Classes.Add(C.ID, pimClass); * pimClass.Name = CutID(C.ID); * pimClass.OntologyEquivalent = C.ID; * }*/ OwlEdgeList TypeEdges = (OwlEdgeList)graph.Edges["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]; foreach (OwlEdge E in TypeEdges) { if (E.ChildNode.ID == "http://www.w3.org/2002/07/owl#ObjectProperty" && !Assocs.ContainsKey(E.ParentNode.ID)) { Assocs.Add(E.ParentNode.ID, new Assoc() { id = E.ParentNode.ID }); } else if (E.ChildNode.ID == "http://www.w3.org/2002/07/owl#DatatypeProperty" && !Attrs.ContainsKey(E.ParentNode.ID)) { Attrs.Add(E.ParentNode.ID, new Attr() { id = E.ParentNode.ID }); } else if (E.ChildNode.ID == "http://www.w3.org/2002/07/owl#Class") { if (!Classes.ContainsKey(E.ParentNode.ID)) { PIMClass pimClass = controller.ModelController.Model.AddClass() as PIMClass; Classes.Add(E.ParentNode.ID, pimClass); pimClass.Name = CutID(E.ParentNode.ID); pimClass.OntologyEquivalent = E.ParentNode.ID; if (E.ParentNode.ID.IndexOf('#') != -1) { controller.Project.Schema.XMLNamespace = E.ParentNode.ID.Substring(0, E.ParentNode.ID.IndexOf('#')); } } } } OwlEdgeList DomainEdges = (OwlEdgeList)graph.Edges["http://www.w3.org/2000/01/rdf-schema#domain"]; foreach (OwlEdge E in DomainEdges) { if (Assocs.ContainsKey(E.ParentNode.ID)) { Assocs[E.ParentNode.ID].from = E.ChildNode.ID; } if (Attrs.ContainsKey(E.ParentNode.ID)) { Attrs[E.ParentNode.ID].owner = E.ChildNode.ID; } } OwlEdgeList RangeEdges = (OwlEdgeList)graph.Edges["http://www.w3.org/2000/01/rdf-schema#range"]; foreach (OwlEdge E in RangeEdges) { if (Assocs.ContainsKey(E.ParentNode.ID)) { Assocs[E.ParentNode.ID].to = E.ChildNode.ID; } if (Attrs.ContainsKey(E.ParentNode.ID)) { Attrs[E.ParentNode.ID].type = E.ChildNode.ID; } } Report R = new Report(); foreach (Attr A in Attrs.Values) { if (A.owner == null) { R.lb1.Items.Add("Attribute " + A.id + " doesn't have an owner."); continue; } if (!Classes.ContainsKey(A.owner)) { R.lb1.Items.Add("Attribute " + A.id + ": Owner " + A.owner + " not found."); continue; } Property P = Classes[A.owner].AddAttribute(); P.OntologyEquivalent = A.id; Attributes.Add(A.id, P); P.Name = CutID(A.id); P.Default = CutID(A.type); } foreach (Assoc A in Assocs.Values) { if (A.from == null || A.to == null) { R.lb2.Items.Add("Association " + A.id + ": doesn't have from or to."); continue; } List <PIMClass> L = new List <PIMClass>(); if (Classes.ContainsKey(A.from)) { L.Add(Classes[A.from]); } else { R.lb2.Items.Add("Association " + A.id + ": From: " + A.from + " doesn't exist."); continue; } if (Classes.ContainsKey(A.to)) { L.Add(Classes[A.to]); } else { R.lb2.Items.Add("Association " + A.id + ": To: " + A.to + " doesn't exist."); continue; } Association Assoc = controller.ModelController.Model.Schema.AssociateClasses(L); Assoc.OntologyEquivalent = A.id; Assoc.Name = CutID(A.id); Associations.Add(A.id, Assoc); } OwlEdgeList SubClassEdges = (OwlEdgeList)graph.Edges["http://www.w3.org/2000/01/rdf-schema#subClassOf"]; foreach (OwlEdge E in SubClassEdges) { if (Classes.ContainsKey(E.ParentNode.ID) && Classes.ContainsKey(E.ChildNode.ID)) { Generalizations.Add(controller.ModelController.Model.Schema.SetGeneralization(Classes[E.ParentNode.ID], Classes[E.ChildNode.ID])); } else if (!Classes.ContainsKey(E.ChildNode.ID)) { R.lb2.Items.Add(E.ParentNode.ID + " subclassOf " + E.ChildNode.ID + ": Child doesn't exist."); continue; } else if (!Classes.ContainsKey(E.ParentNode.ID)) { R.lb2.Items.Add(E.ParentNode.ID + " subclassOf " + E.ChildNode.ID + ": Parent doesn't exist."); continue; } } OwlEdgeList CommentEdges = (OwlEdgeList)graph.Edges["http://www.w3.org/2000/01/rdf-schema#comment"]; if (CommentEdges != null) { foreach (OwlEdge E in CommentEdges) { if (Classes.ContainsKey(E.ParentNode.ID)) { Comments.Add(Classes[E.ParentNode.ID].AddComment(E.ChildNode.ID)); } else if (Associations.ContainsKey(E.ParentNode.ID)) { Comments.Add(Associations[E.ParentNode.ID].AddComment(E.ChildNode.ID)); } else if (Attributes.ContainsKey(E.ParentNode.ID)) { R.lb2.Items.Add("Comment of " + E.ParentNode.ID + ": XCase doesn't support attribute comments."); } else { R.lb2.Items.Add("Comment of " + E.ParentNode.ID + ": Class/Association doesn't exist."); continue; } } } int i = 0; foreach (PIMClass pimClass in Classes.Values) { ClassViewHelper VH = new ClassViewHelper(controller.Diagram); double rows = Math.Abs(Math.Sqrt(Classes.Count)) + 1; VH.X = (i * 200 + 10) % ((int)rows * 200 + 10); VH.Y = (i / (int)rows) * 200 + 10; controller.Diagram.AddModelElement(pimClass, VH); i++; } foreach (Association A in Associations.Values) { AssociationViewHelper VH = new AssociationViewHelper(controller.Diagram); controller.Diagram.AddModelElement(A, VH); } foreach (Generalization G in Generalizations) { GeneralizationViewHelper VH = new GeneralizationViewHelper(controller.Diagram); controller.Diagram.AddModelElement(G, VH); } foreach (Comment C in Comments) { CommentViewHelper VH = new CommentViewHelper(controller.Diagram); controller.Diagram.AddModelElement(C, VH); } R.Show(); }
/// <summary> /// Parses the OWL at the given URI, into an existing graph /// </summary> /// <param name="uri">The Uri of the document to parse</param> /// <param name="graph">An object that implements the IOwlGraph interface that will be used as the destination graph</param> /// <returns>An object that implements the IOwlGraph interface</returns> public IOwlGraph ParseOwl(string uri, IOwlGraph graph) { Uri srcUri = null; try { srcUri = new Uri(uri); } catch(UriFormatException) { srcUri = new Uri(Path.GetFullPath(uri)); } return ParseOwl(srcUri,graph); }
public void LoadOwlGraph(string path) { IOwlParser p = new OwlXmlParser(); _graph = p.ParseOwl(path); }