Beispiel #1
0
        /// <summary>
        /// Attaches a parent edge to this node.
        /// </summary>
        /// <param name="edge">An object that implements the IOwlEdge interface.</param>
        /// <exception cref="ArgumentNullException">The specified edge is a null reference.</exception>
        public void AttachParentEdge(IOwlEdge edge)
        {
            if (edge == null)
            {
                throw (new ArgumentNullException());
            }
            bool         exists   = false;
            IOwlEdgeList edgeList = ParentEdges[edge.ID];

            foreach (OwlEdge e in edgeList)
            {
                // First, we will look for an edge which is having the same parent and
                // child as the one we want to add
                if (e.ParentNode == edge.ParentNode)
                {
                    exists = true;
                }
            }

            // If there is none, then we add the edge to this node
            if (!exists)
            {
                ParentEdges.Add(edge);
                edge.ChildNode = this;
            }
            // If not, then do nothing
        }
        /// <summary>
        /// Determines whether this collection contains any edges with the specified edge ID
        /// </summary>
        /// <param name="edgeID">A string containing the edge ID</param>
        /// <returns>True if there are any edges in this collection with the specified ID</returns>
        public bool Contains(string edgeID)
        {
            IOwlEdgeList edges = (IOwlEdgeList)_edgeMap[edgeID];

            if ((edges == null) || (edges.Count == 0))
            {
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// Adds an edge to this collection
        /// </summary>
        /// <param name="edgeID">The ID of the edge</param>
        /// <param name="edge">An object that implements the IOwlEdge interface</param>
        /// <exception cref="ArgumentNullException">The specified edge is a null reference or the specified edgeID is a null reference</exception>
        public void Add(string edgeID, IOwlEdge edge)
        {
            IOwlEdgeList edgeList = (IOwlEdgeList)_edgeMap[edgeID];

            if (edgeList == null)
            {
                edgeList         = new OwlEdgeList();
                _edgeMap[edgeID] = edgeList;
            }
            edgeList.Add(edge);
            _edges.Add(edge);
        }
        /// <summary>
        /// Removes the specified edge object if it exists.
        /// </summary>
        /// <param name="edge">An object that implements the IOwlEdge interface</param>
        /// <remarks>This method uses object.Equals to determine whether the specified edge exists and then removes it if it is present in the collection</remarks>
        public void Remove(IOwlEdge edge)
        {
            if (edge == null)
            {
                throw(new ArgumentNullException());
            }
            IOwlEdgeList edgeList = (IOwlEdgeList)_edgeMap[edge.ID];

            if (edgeList == null)
            {
                return;
            }
            edgeList.Remove(edge);
            _edges.Remove(edge);
        }
 /// <summary>
 /// Returns the edge at the given index from the list of edges with the specified ID
 /// </summary>
 public IOwlEdge this[string edgeID, int index]
 {
     get
     {
         IOwlEdgeList edges = (IOwlEdgeList)_edgeMap[edgeID];
         if (edges == null)
         {
             return(null);
         }
         try
         {
             return(edges[index]);
         }
         catch (ArgumentOutOfRangeException)
         {
             return(null);
         }
     }
 }
Beispiel #6
0
        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");
                            }
                        }
                    }
                }
            }
        }
Beispiel #7
0
        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);
            }
        }
Beispiel #8
0
        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);
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of this collection from an existing one
 /// </summary>
 /// <param name="edges"></param>
 public OwlEdgeList(IOwlEdgeList edges)
 {
     _edges = ((OwlEdgeList)edges).EdgeList;
 }
 /// <summary>
 /// Initializes a new instance of this collection from an existing one
 /// </summary>
 /// <param name="edges"></param>
 public OwlEdgeList(IOwlEdgeList edges)
 {
     _edges = ((OwlEdgeList)edges).EdgeList;
 }