Esempio n. 1
0
        /// <summary>
        /// Implementation of an OwlEdge.
        /// </summary>
        /// <param name="edge">The actual edge to be visited</param>
        /// <param name="parent">The parent object (node) of the edge</param>
        public override void Visit(OwlEdge edge, Object parent)
        {
            XmlElement parentElement = parent as XmlElement;

            if (parentElement != null)
            {
                Uri uri = new Uri(edge.ID);
                // Retrieve the local name from the uri
                string localName = uri.Fragment.Substring(1, uri.Fragment.Length - 1);
                // Get the path, up to the local name, from the uri
                string path = uri.GetLeftPart(UriPartial.Path) + "#";
                string prefix;
                // Check for the namespace of the edge in order to get the correct prefix
                if (path == OwlNamespaceCollection.OwlNamespace)
                {
                    prefix = OwlNamespaceCollection.OwlNamespacePrefix;
                }
                else if (path == OwlNamespaceCollection.RdfNamespace)
                {
                    prefix = OwlNamespaceCollection.RdfNamespacePrefix;
                }
                else if (path == OwlNamespaceCollection.RdfSchemaNamespace)
                {
                    prefix = OwlNamespaceCollection.RdfSchemaNamespacePrefix;
                }
                else
                {
                    // If the namespace of the edge is something else, then look for it
                    prefix = "";
                    if (path != _baseUri)
                    {
                        // Search for the prefix of this individual
                        int pos = _namespaces[path].IndexOf(':');
                        if (pos != -1)
                        {
                            prefix = _namespaces[path].Substring(++pos);
                        }
                    }
                }

                string qualifiedName = (prefix.Length != 0) ? (prefix + ":" + localName) : localName;
                // At this point we will not generate the rdf:type edges.
                XmlElement edgeElement = _owlDocument.CreateElement(qualifiedName, path);

                // Check to see if the child node is an anonymous one or not. If it is, then further
                // process that node, otherwise just reference it by name.
                OwlNode node = (OwlNode)edge.ChildNode;
                if (node.IsAnonymous() || node.IsLiteral())
                {
                    node.Accept(this, edgeElement);
                }
                else
                {
                    // Add the name as one of its attributes
                    XmlAttribute nameAttribute = _owlDocument.CreateAttribute("rdf", "resource", OwlNamespaceCollection.RdfNamespace);
                    nameAttribute.Value = GetNodeReference(node);
                    edgeElement.Attributes.Append(nameAttribute);
                }
                parentElement.AppendChild(edgeElement);
            }
        }