public void WhenTwoPrefixesMapToTheSameUriTheUriToPrefixMapIsExtended()
        {
            var nsmap = new NamespaceMapper();

            nsmap.AddNamespace("foo", new Uri("http://example.org/"));
            nsmap.AddNamespace("bar", new Uri("http://example.org/"));
            nsmap.GetPrefix(new Uri("http://example.org/")).Should().BeOneOf("foo", "bar");
            nsmap.RemoveNamespace("bar");
            nsmap.GetPrefix(new Uri("http://example.org/")).Should().Be("foo");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new Base Graph using the given Triple Collection.
        /// </summary>
        /// <param name="tripleCollection">Triple Collection to use.</param>
        protected BaseGraph(BaseTripleCollection tripleCollection)
        {
            _triples     = tripleCollection;
            _bnodemapper = new BlankNodeMapper();
            _nsmapper    = new NamespaceMapper();

            // Create Event Handlers and attach to the Triple Collection
            TripleAddedHandler   = new TripleEventHandler(OnTripleAsserted);
            TripleRemovedHandler = new TripleEventHandler(OnTripleRetracted);
            AttachEventHandlers(_triples);
        }
Exemplo n.º 3
0
        public void PelletNamespace()
        {
            PelletServer server  = new PelletServer(PelletTestServer);
            Type         svcType = typeof(NamespaceService);

            foreach (KnowledgeBase kb in server.KnowledgeBases)
            {
                if (kb.SupportsService(svcType))
                {
                    Console.WriteLine(kb.Name + " supports Namespaces");
                    NamespaceService svc   = (NamespaceService)kb.GetService(svcType);
                    NamespaceMapper  nsmap = svc.GetNamespaces();
                    foreach (String prefix in nsmap.Prefixes)
                    {
                        Console.WriteLine(prefix + ": " + nsmap.GetNamespaceUri(prefix).AbsoluteUri);
                    }
                }
                else
                {
                    Console.WriteLine(kb.Name + " does not support the Search Service");
                }
                Console.WriteLine();
            }
        }
Exemplo n.º 4
0
        protected BaseGraph(BaseTripleCollection tripleCollection, BaseNodeCollection nodeCollection)
        {
            this._triples = tripleCollection;
            this._nodes = nodeCollection;
            this._bnodemapper = new BlankNodeMapper();
            this._nsmapper = new NamespaceMapper();

            //Create Event Handlers and attach to the Triple Collection
            this.TripleAddedHandler = new TripleEventHandler(this.OnTripleAsserted);
            this.TripleRemovedHandler = new TripleEventHandler(this.OnTripleRetracted);
            this.AttachEventHandlers(this._triples);
        }
        public void NamespaceMapperEvent()
        {
            bool eventRaised = false;

            NamespaceChanged added   = delegate(String prefix, Uri u) { eventRaised = true; };
            NamespaceChanged changed = delegate(String prefix, Uri u) { eventRaised = true; };
            NamespaceChanged removed = delegate(String prefix, Uri u) { eventRaised = true; };

            NamespaceMapper nsmap = new NamespaceMapper();

            nsmap.NamespaceAdded    += added;
            nsmap.NamespaceModified += changed;
            nsmap.NamespaceRemoved  += removed;

            Console.WriteLine("Trying to add the RDF Namespace, this should already be defined");
            nsmap.AddNamespace("rdf", new Uri(NamespaceMapper.RDF));
            Assert.False(eventRaised);
            eventRaised = false;
            Console.WriteLine();

            Console.WriteLine("Trying to add an example Namespace which isn't defined");
            nsmap.AddNamespace("ex", new Uri("http://example.org/"));
            Assert.True(eventRaised);
            eventRaised = false;
            Console.WriteLine(nsmap.GetNamespaceUri("ex").AbsoluteUri);
            Console.WriteLine();

            Console.WriteLine("Trying to modify the example Namespace");
            nsmap.AddNamespace("ex", new Uri("http://example.org/test/"));
            Assert.True(eventRaised);
            eventRaised = false;
            Console.WriteLine(nsmap.GetNamespaceUri("ex").AbsoluteUri);
            Console.WriteLine();

            Console.WriteLine("Trying to remove the example Namespace");
            nsmap.RemoveNamespace("ex");
            Assert.True(eventRaised);
            eventRaised = false;
            Console.WriteLine();

            Console.WriteLine("Trying to remove a non-existent Namespace");
            nsmap.RemoveNamespace("ex");
            Assert.False(eventRaised);
            eventRaised = false;
            Console.WriteLine();

            Console.WriteLine("Adding some example Namespace back in again for an import test");
            nsmap.AddNamespace("ex", new Uri("http://example.org/"));
            nsmap.AddNamespace("ns0", new Uri("http://example.org/clashes/"));

            Console.WriteLine("Creating another Namespace Mapper with the ex prefix mapped to a different URI");
            NamespaceMapper nsmap2 = new NamespaceMapper();

            nsmap2.AddNamespace("ex", new Uri("http://example.org/test/"));

            Console.WriteLine("Importing the new NamespaceMapper into the original");
            nsmap.Import(nsmap2);
            Console.WriteLine("NamespaceMapper now contains the following Namespaces:");
            foreach (String prefix in nsmap.Prefixes)
            {
                Console.WriteLine("\t" + prefix + " <" + nsmap.GetNamespaceUri(prefix).AbsoluteUri + ">");
            }
            Assert.Equal(nsmap.GetNamespaceUri("ex"), new Uri("http://example.org/"));
            Assert.Equal(nsmap.GetNamespaceUri("ns1"), new Uri("http://example.org/test/"));
        }