/// <summary>
        /// Parses the OWL syntax on an edge.
        /// </summary>
        /// <param name="node">The XML Node representing the OWL edge</param>
        /// <param name="rEdge">The edge</param>
        /// <param name="parentNode">The parent OWL node</param>
        /// <returns>True if the edge was given an ID and attached to the parent node</returns>
        private bool ParseEdgeSyntax(XmlNode node, OwlEdge rEdge, OwlNode parentNode)
        {
            //first get the NameSpace URI, NameSpace prefix and the LocalName for the node
            String nameSpaceURI = node.NamespaceURI;
            String nameSpacePrefix = node.Prefix;
            String localName = node.LocalName;
            if(IsNonSyntacticElement(node))
            {
                rEdge.ID = nameSpaceURI + localName;

                if(rEdge.ID == (OwlNamespaceCollection.RdfNamespace + "type"))
                {
                    OwlNode typeNode;
                    if(rEdge.ChildNode.ID == (OwlNamespaceCollection.OwlNamespace + "DatatypeProperty"))
                    {
                        typeNode = (OwlNode)_owlGraph.AddNode(OwlNamespaceCollection.OwlNamespace+"DatatypeProperty");
                        OwlDatatypeProperty newNode = new OwlDatatypeProperty(parentNode.ID,typeNode);
                        _owlGraph.AddEdge(newNode.Type);
                        MoveEdges(parentNode, newNode);
                        _owlGraph.Nodes.Remove(parentNode);
                        _owlGraph.AddNode(newNode);
                        rEdge.AttachParentNode(newNode);
                        return true;
                    }
                    if(rEdge.ChildNode.ID == (OwlNamespaceCollection.OwlNamespace + "ObjectProperty"))
                    {
                        typeNode = (OwlNode)_owlGraph.AddNode(OwlNamespaceCollection.OwlNamespace+"ObjectProperty");
                        OwlObjectProperty newNode = new OwlObjectProperty(parentNode.ID,typeNode);
                        _owlGraph.AddEdge(newNode.Type);
                        MoveEdges(parentNode, newNode);
                        _owlGraph.Nodes.Remove(parentNode);
                        _owlGraph.AddNode(newNode);
                        rEdge.AttachParentNode(newNode);
                        return true;
                    }

                }

                rEdge.AttachParentNode(parentNode);
                return true;
            }

            if(IsSyntacticElement(node))
            {
                OnError("Cannot use " + node.Name + " as a property element");
                return false;
            }

            // It is an instance of a property
            rEdge.ID = nameSpaceURI + localName;
            rEdge.AttachParentNode(parentNode);
            return true;

            //			OnWarning("Unknown property element "+ node.Name);
            //			return false;
        }
        /// <summary>
        /// Processes an edge in the XML document. 
        /// </summary>
        /// <param name="node">The XmlNode to process.</param>
        /// <param name="parent">The parent of the current node.</param>
        /// <returns>Returns a reference to the new edge created</returns>
        private Object ProcessEdge(XmlNode node,  Object parent)
        {
            //if the node is a comment or anything else then totally ignore
            if((node.NodeType == XmlNodeType.Comment) || (node.NodeType == XmlNodeType.None) || (node.NodeType == XmlNodeType.Whitespace) || (node.NodeType == XmlNodeType.SignificantWhitespace))
                return true;
            OwlEdge rEdge = null;

            if(node.NodeType == XmlNodeType.Element)
            {
                //get the xml:base attribute...
                XmlAttribute xmlBaseAttr = node.Attributes["xml:base"];
                if((xmlBaseAttr == null) && (parent != null))
                {
                    //ok the child does not have an xml:base... and the parent is not null i.e. this node is not a child of the rdf:RDF root
                    xmlBaseAttr = node.ParentNode.Attributes["xml:base"];
                    if(xmlBaseAttr != null)
                        node.Attributes.Append(xmlBaseAttr);
                }
            }

            rEdge = new OwlEdge();

            OwlNode parentOwlNode = (OwlNode)parent;
            //process the xml:lang attribute if applicable
            //rEdge.LangID = parentOwlNode.LangID;

            if(ParseEdgeRdfAttributes(node,rEdge)) //if the process attributes method returns true then process the children of this node
            {
                if(node.HasChildNodes)
                {
                    int count = node.ChildNodes.Count;
                    for(int i=0;i<count;i++)
                        ProcessNode(node.ChildNodes[i], rEdge);
                }
            }

            if(!ParseEdgeSyntax(node,rEdge, parentOwlNode))
            {
                rEdge.ID = node.NamespaceURI+node.LocalName;
                rEdge.AttachParentNode(parentOwlNode);

            }

            //coming back up the tree
            ParseEdgeAttributes(node,rEdge);

            //if the edge is dangling then put an empty Literal on it.
            if(rEdge.ChildNode == null)
                rEdge.AttachChildNode(_owlGraph.AddLiteral("",null,null));

            //add the edge to the Graph
            _owlGraph.AddEdge(rEdge);

            return rEdge;
        }
Esempio n. 3
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");
        }