Esempio n. 1
0
        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: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#";

            OwlOntology o = new OwlOntology(baseUri + "testOntology");
            ontology.Nodes.Add(o);

            OwlClass a = new OwlClass(baseUri + "ClassA");
            ontology.Nodes.Add(a);

            OwlClass b = new OwlClass(baseUri + "ClassB");
            ontology.Nodes.Add(b);

            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");
        }
Esempio n. 2
0
        /// <summary>
        /// Implementation of the visit function to generate some output, used in the visitor pattern
        /// </summary>
        /// <param name="node">The actual node which needs to be generated</param>
        /// <param name="parent">The parent object of the node</param>
        public override void Visit(OwlClass node, Object parent)
        {
            XmlElement parentElement = parent as XmlElement;

            if (parentElement != null)
            {
                XmlElement classElement = _owlDocument.CreateElement("owl:Class", OwlNamespaceCollection.OwlNamespace);
                // If the node is not a blank one
                if (!node.IsAnonymous())
                {
                    // Add the name as one of its attributes
                    AddNameAttribute(classElement, node);
                }

                // Generate all the edges going out of this node
                if (!_visited.Contains(node))
                {
                    VisitEdges(node, classElement);
                }

                // Attach the node eventually to its parent
                parentElement.AppendChild(classElement);
                _visited.Add(node);
            }
        }
 /// <summary>
 /// Adds an OWL Resource of type owl:Class to the graph</summary>
 /// <param name="nodeUri">The Uri of the resource.</param>
 /// <returns>Returns a reference to the newly added resource.</returns>
 /// <exception cref="UriFormatException">The specified nodeUri is not a well formed Uri.</exception>
 private OwlClass AddClassToGraph(string nodeUri)
 {
     //if the uri is null then create a blank node uri
     if(nodeUri == null)
         nodeUri = GetBlankNodeUri(null);
     OwlNode node = (OwlNode)_owlGraph[nodeUri];
     if((node != null) && (node is OwlClass))
         return (OwlClass)node;
     OwlNode typeNode = (OwlNode)_owlGraph.AddNode(OwlNamespaceCollection.OwlNamespace+"Class");
     if(node == null)
     {
         node = new OwlClass(nodeUri,typeNode);
         _owlGraph.AddEdge(((OwlClass)node).Type);
         _owlGraph.AddNode(node);
         return (OwlClass)node;
     }
     OwlClass newNode = new OwlClass(nodeUri,typeNode);
     _owlGraph.AddEdge(newNode.Type);
     MoveEdges(node, newNode);
     _owlGraph.Nodes.Remove(node);
     _owlGraph.AddNode(newNode);
     return newNode;
 }
        /// <summary>
        /// Implementation of the visit function to generate some output, used in the visitor pattern
        /// </summary>
        /// <param name="node">The actual node which needs to be generated</param>
        /// <param name="parent">The parent object of the node</param>
        public override void Visit(OwlClass node, Object parent)
        {
            XmlElement parentElement = parent as XmlElement;
            if(parentElement != null)
            {
                XmlElement classElement = _owlDocument.CreateElement("owl:Class", OwlNamespaceCollection.OwlNamespace);
                // If the node is not a blank one
                if(!node.IsAnonymous())
                {
                    // Add the name as one of its attributes
                    AddNameAttribute(classElement, node);
                }

                // Generate all the edges going out of this node
                if(!node.Visited)
                    VisitEdges(node, classElement);

                // Attach the node eventually to its parent
                parentElement.AppendChild(classElement);
                node.Visited = true;
            }
        }
 /// <summary>
 /// Implementation of the visit function to generate some output, used in the visitor pattern
 /// </summary>
 /// <param name="node">The actual node which needs to be generated</param>
 /// <param name="parent">The parent object of the node</param>
 public abstract void Visit(OwlClass node, Object parent);
 /// <summary>
 /// Implementation of the visit function to generate some output, used in the visitor pattern
 /// </summary>
 /// <param name="node">The actual node which needs to be generated</param>
 /// <param name="parent">The parent object of the node</param>
 public abstract void Visit(OwlClass node, Object parent);