Exemplo 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");
        }
Exemplo 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(OwlOntology node, Object parent)
        {
            XmlElement parentElement = parent as XmlElement;

            if (parentElement != null)
            {
                XmlElement ontologyElement = _owlDocument.CreateElement("owl:Ontology", OwlNamespaceCollection.OwlNamespace);
                // Add the name attribute to the node
                XmlAttribute nameAttribute = _owlDocument.CreateAttribute("rdf", "about", OwlNamespaceCollection.RdfNamespace);
                nameAttribute.Value = GetNodeID(node);
                ontologyElement.Attributes.Append(nameAttribute);

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

                // Attach the node eventually to its parent
                parentElement.AppendChild(ontologyElement);
                _visited.Add(node);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Adds an OWL Resource of type owl:Ontology 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 OwlOntology AddOntologyToGraph(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 OwlOntology))
         return (OwlOntology)node;
     OwlNode typeNode = (OwlNode)_owlGraph.AddNode(OwlNamespaceCollection.OwlNamespace+"Ontology");
     if(node == null)
     {
         node = new OwlOntology(nodeUri,typeNode);
         _owlGraph.AddEdge(((OwlOntology)node).Type);
         _owlGraph.AddNode(node);
         return (OwlOntology)node;
     }
     OwlOntology newNode = new OwlOntology(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(OwlOntology node, Object parent)
        {
            XmlElement parentElement = parent as XmlElement;
            if(parentElement != null)
            {
                XmlElement ontologyElement = _owlDocument.CreateElement("owl:Ontology", OwlNamespaceCollection.OwlNamespace);
                // Add the name attribute to the node
                XmlAttribute nameAttribute = _owlDocument.CreateAttribute("rdf", "about", OwlNamespaceCollection.RdfNamespace);
                nameAttribute.Value = GetNodeID(node);
                ontologyElement.Attributes.Append(nameAttribute);

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

                // Attach the node eventually to its parent
                parentElement.AppendChild(ontologyElement);
                node.Visited = true;
            }
        }
Exemplo n.º 5
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 abstract void Visit(OwlOntology node, Object parent);
Exemplo n.º 6
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 abstract void Visit(OwlOntology node, Object parent);