public void SetUp()
        {
            string connectionString = SetupClass.ConnectionString;

            Store = StoreFactory.CreateStore(string.Format("{0};rule=urn:semiodesk/test/ruleset", connectionString));
            Model = Store.GetModel(new Uri("http://example.org/TestModel"));

            if (!Model.IsEmpty)
            {
                Model.Clear();
            }

            OntologyDiscovery.AddNamespace("ex", new Uri("http://example.org/"));
            OntologyDiscovery.AddNamespace("dc", new Uri("http://purl.org/dc/elements/1.1/"));
            OntologyDiscovery.AddNamespace("vcard", new Uri("http://www.w3.org/2001/vcard-rdf/3.0#"));
            OntologyDiscovery.AddNamespace("foaf", new Uri("http://xmlns.com/foaf/0.1/"));
            OntologyDiscovery.AddNamespace("dbpedia", new Uri("http://dbpedia.org/ontology/"));
            OntologyDiscovery.AddNamespace("dbpprop", new Uri("http://dbpedia.org/property/"));
            OntologyDiscovery.AddNamespace("schema", new Uri("http://schema.org/"));
            OntologyDiscovery.AddNamespace("nie", new Uri("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#"));
            OntologyDiscovery.AddNamespace("nco", new Uri("http://www.semanticdesktop.org/ontologies/2007/03/22/nco#"));
            OntologyDiscovery.AddNamespace("sfo", sfo.GetNamespace());
            OntologyDiscovery.AddNamespace(nfo.GetPrefix(), nfo.GetNamespace());

            Model.Clear();

            for (int i = 0; i < 100; i++)
            {
                IResource resource0 = Model.CreateResource();
                resource0.AddProperty(rdf.type, nco.PersonContact);
                resource0.AddProperty(nco.fullname, Guid.NewGuid().ToString());
                resource0.Commit();
            }
        }
Пример #2
0
        public void SetUp()
        {
            OntologyDiscovery.AddNamespace("ex", new Uri("http://example.org/"));
            OntologyDiscovery.AddNamespace("dc", new Uri("http://purl.org/dc/elements/1.1/"));
            OntologyDiscovery.AddNamespace("vcard", new Uri("http://www.w3.org/2001/vcard-rdf/3.0#"));
            OntologyDiscovery.AddNamespace("foaf", new Uri("http://xmlns.com/foaf/0.1/"));
            OntologyDiscovery.AddNamespace("dbpedia", new Uri("http://dbpedia.org/ontology/"));
            OntologyDiscovery.AddNamespace("dbpprop", new Uri("http://dbpedia.org/property/"));
            OntologyDiscovery.AddNamespace("schema", new Uri("http://schema.org/"));
            OntologyDiscovery.AddNamespace("nie", new Uri("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#"));
            OntologyDiscovery.AddNamespace("nco", new Uri("http://www.semanticdesktop.org/ontologies/2007/03/22/nco#"));
            OntologyDiscovery.AddNamespace("sfo", sfo.GetNamespace());
            OntologyDiscovery.AddNamespace(nfo.GetPrefix(), nfo.GetNamespace());

            Store = StoreFactory.CreateStore(string.Format("{0};rule=urn:semiodesk/test/ruleset", SetupClass.ConnectionString));
            Store.InitializeFromConfiguration();

            Model = Store.GetModel(new Uri("http://example.org/TestModel"));
            Model.Clear();

            IResource hans = Model.CreateResource(new Uri("http://example.org/Hans"));

            hans.AddProperty(rdf.type, nco.PersonContact);
            hans.AddProperty(nco.fullname, "Hans Wurscht");
            hans.AddProperty(nco.birthDate, DateTime.Now);
            hans.AddProperty(nco.blogUrl, "http://blog.com/Hans");

            IResource pagerNumber0 = Model.CreateResource(new Uri("http://example.org/Hans/pagerNumber#0"));

            pagerNumber0.AddProperty(rdf.type, nco.PagerNumber);
            pagerNumber0.AddProperty(dc.date, DateTime.Today);
            pagerNumber0.AddProperty(nco.creator, hans);
            pagerNumber0.Commit();

            IResource phoneNumber0 = Model.CreateResource(new Uri("http://example.org/Hans/phoneNumber#0"));

            phoneNumber0.AddProperty(rdf.type, nco.PhoneNumber);
            phoneNumber0.AddProperty(dc.date, DateTime.Today.AddDays(1));
            phoneNumber0.AddProperty(nco.creator, hans);
            phoneNumber0.Commit();

            IResource phoneNumber1 = Model.CreateResource(new Uri("http://example.org/Hans/phoneNumber#1"));

            phoneNumber1.AddProperty(rdf.type, nco.PhoneNumber);
            phoneNumber1.AddProperty(dc.date, DateTime.Today.AddDays(2));
            phoneNumber1.AddProperty(nco.creator, hans);
            phoneNumber1.Commit();

            hans.AddProperty(nco.hasContactMedium, pagerNumber0);
            hans.AddProperty(nco.hasPhoneNumber, phoneNumber0);
            hans.AddProperty(nco.hasPhoneNumber, phoneNumber1);
            hans.Commit();

            IResource acme = Model.CreateResource(new Uri("http://example.org/ACME"));

            acme.AddProperty(rdf.type, nco.OrganizationContact);
            acme.AddProperty(nco.fullname, "ACME");
            acme.AddProperty(nco.creator, hans);
            acme.Commit();
        }
Пример #3
0
        public void GetResourceTest()
        {
            Uri resourceUri = new Uri("http://example.com/testResource");

            IModelGroup g = Store.CreateModelGroup(Model.Uri, Model2.Uri);

            Assert.Throws <ResourceNotFoundException>(new TestDelegate(() => g.GetResource(resourceUri)));

            IResource resource = Model.CreateResource(resourceUri);

            resource.AddProperty(rdf.type, nco.Contact);
            resource.Commit();

            IResource res = g.GetResource(resourceUri);

            Assert.IsNotNull(res);
            Assert.IsTrue(res.IsReadOnly);
            Assert.AreEqual(resourceUri, res.Uri);
            Assert.Contains(nco.Contact, res.ListValues(rdf.type).ToList());


            resource = Model2.CreateResource(resourceUri);
            resource.AddProperty(rdf.type, nco.Contact);
            resource.Commit();

            res = g.GetResource(resourceUri);
            Assert.IsNotNull(res);
            Assert.AreEqual(1, res.ListValues(rdf.type).Count());
            Assert.IsTrue(res.IsReadOnly);
            Assert.AreEqual(resourceUri, res.Uri);
            Assert.Contains(nco.Contact, res.ListValues(rdf.type).ToList());
        }
Пример #4
0
        public void UpdateResourceTest()
        {
            Property  property    = new Property(new Uri("http://example.org/MyProperty"));
            Uri       resourceUri = new Uri("http://example.org/MyResource");
            IResource resource    = Model.CreateResource(resourceUri);

            resource.AddProperty(property, 123);
            resource.AddProperty(property, "in the jungle");
            resource.Commit();

            // Try to update resource with different properties then persisted
            Resource r2 = new Resource(resourceUri);

            r2.AddProperty(property, "in the jengle");

            r2.Model = Model;
            r2.Commit();
            var actual = Model.GetResource <Resource>(resourceUri);

            Assert.AreEqual(r2, actual);


            // Try to update resource without properties
            Resource r3 = new Resource(resourceUri);

            r3.Model = Model;
            r3.Commit();
            actual = Model.GetResource <Resource>(resourceUri);
            Assert.AreEqual(r3, actual);
        }
Пример #5
0
        public void ContainsResourceTest()
        {
            Uri uri = new Uri("http://example.com/testResource");

            IModelGroup group = Store.CreateModelGroup(Model.Uri, Model2.Uri);

            Assert.IsFalse(group.ContainsResource(uri));

            IResource resource = Model.CreateResource(uri);

            resource.AddProperty(rdf.type, nco.Contact);
            resource.Commit();

            Assert.IsTrue(group.ContainsResource(uri));

            Model.DeleteResource(resource);

            Assert.IsFalse(group.ContainsResource(uri));

            resource = Model2.CreateResource(uri);
            resource.AddProperty(rdf.type, nco.Contact);
            resource.Commit();

            Assert.IsTrue(group.ContainsResource(uri));
        }
Пример #6
0
        public void SetUp()
        {
            string connectionString = SetupClass.ConnectionString;

            Store = StoreFactory.CreateStore(string.Format("{0};rule=urn:semiodesk/test/ruleset", connectionString));
            Store.InitializeFromConfiguration();

            Model = Store.GetModel(new Uri("http://example.org/TestModel"));

            if (!Model.IsEmpty)
            {
                Model.Clear();
            }

            Model2 = Store.GetModel(new Uri("semiodesk:Trinity:Test"));

            if (!Model2.IsEmpty)
            {
                Model2.Clear();
            }

            IResource model_resource = Model.CreateResource(new Uri("http://example.org/MyResource"));

            Property property = new Property(new Uri("http://example.org/MyProperty"));

            model_resource.AddProperty(property, "in the jungle");
            model_resource.AddProperty(property, 123);
            model_resource.AddProperty(property, DateTime.Now);
            model_resource.Commit();

            IResource model_resource2 = Model.CreateResource(new Uri("ex:Resource"));

            model_resource2.AddProperty(property, "in the jungle");
            model_resource2.AddProperty(property, 123);
            model_resource2.AddProperty(property, DateTime.Now);
            model_resource2.Commit();


            IResource model2_resource = Model2.CreateResource(new Uri("http://example.org/MyResource"));

            model2_resource.AddProperty(property, "in the jungle");
            model2_resource.AddProperty(property, 123);
            model2_resource.AddProperty(property, DateTime.Now);
            model2_resource.Commit();

            IResource model2_resource2 = Model2.CreateResource(new Uri("ex:Resource"));

            model2_resource2.AddProperty(property, "in the jungle");
            model2_resource2.AddProperty(property, 123);
            model2_resource2.AddProperty(property, DateTime.Now);
            model2_resource2.Commit();
        }
Пример #7
0
        public void SetUp()
        {
            _projections.Read(new Uri("file:Models/test-ppo.rdf", UriKind.Relative), RdfSerializationFormat.RdfXml);

            IResource document = _data.CreateResource(new Uri("file:///xyz.doc"));

            document.AddProperty(rdf.type, nfo.Document);
            document.AddProperty(nie.title, "How To Recognise Different Types Of Trees From Quite A Long Way Away");
            document.AddProperty(dc.creator, "Python (Monty) Pictures");
            document.AddProperty(nie.created, new DateTime(1969, 9, 14));
            document.AddProperty(nie.language, "en");
            document.Commit();
        }
Пример #8
0
        public void SetUp()
        {
            IResource model_resource = _localModel.CreateResource(new Uri("http://example.org/MyResource"));

            //TODO: all test all datatypes
            Property property = new Property(new Uri("http://example.org/MyProperty"));

            model_resource.AddProperty(rdf.type, nao.Agent);
            model_resource.AddProperty(property, "in the jungle");
            model_resource.AddProperty(property, 123);
            model_resource.AddProperty(property, DateTime.Now);
            model_resource.Commit();
        }
Пример #9
0
        public void ModifyResourceTest()
        {
            var literal     = "var";
            var resourceUri = new Uri("ex:test:resource");
            var property    = new Property(new Uri("ex:test:property"));
            var res         = Model.CreateResource(resourceUri);

            res.AddProperty(property, literal);
            res.Commit();

            IResource result = Model.GetResource(resourceUri);

            result.RemoveProperty(property, literal);
            literal = "var2";
            result.AddProperty(property, literal);
            result.Commit();

            result = Model.GetResource(resourceUri);

            Assert.AreEqual(resourceUri, result.Uri);
            List <Property> properties = result.ListProperties().ToList();

            Assert.AreEqual(1, properties.Count);
            Assert.AreEqual(property, properties[0]);
            Assert.AreEqual(literal, result.GetValue(property));
        }
Пример #10
0
        public void TestInferencing()
        {
            Assert.Inconclusive("dotnetrdf does not support inferencing.");
            Store = StoreFactory.CreateStore("provider=dotnetrdf;schema=Models/test-vocab.rdf");


            var model = Store.CreateModel(new Uri("http://example.org/TestModel"));

            Class    horse    = new Class(new Uri("http://www.semiodesk.com/ontologies/test#Horse"));
            Class    animal   = new Class(new Uri("http://www.semiodesk.com/ontologies/test#Animal"));
            Property eats     = new Property(new Uri("http://www.semiodesk.com/ontologies/test#eats"));
            Property consumes = new Property(new Uri("http://www.semiodesk.com/ontologies/test#consumes"));

            IResource res = model.CreateResource(new Uri("http://www.example.org/Hans"));

            res.AddProperty(rdf.type, horse);
            res.AddProperty(eats, "Straw");
            res.Commit();


            SparqlQuery        query;
            ISparqlQueryResult result;

            // This fact is not explicitly stated.
            query = new SparqlQuery("ASK WHERE { <http://www.example.org/Hans> a test:Animal . }");

            result = model.ExecuteQuery(query);
            Assert.IsFalse(result.GetAnwser());

            result = model.ExecuteQuery(query, true);
            Assert.IsTrue(result.GetAnwser());

            result = model.ExecuteQuery(query);
            Assert.IsFalse(result.GetAnwser());

            // This fact is not explicitly stated.
            query = new SparqlQuery("SELECT ?food WHERE { ?s test:consumes ?food . }");

            result = model.ExecuteQuery(query);
            Assert.AreEqual(0, result.GetBindings().Count());

            result = model.ExecuteQuery(query, true);
            Assert.AreEqual(1, result.GetBindings().Count());
        }
Пример #11
0
        internal IResource CreateList(IEnumerator <IResource> elements)
        {
            IResource first = CreateResource();
            IResource root  = first;

            if (!elements.MoveNext())
            {
                first.AddProperty(RDF.PropertyFirst, RDF.Nil);
                return(first);
            }
            do
            {
                first.AddProperty(RDF.PropertyFirst, elements.Current);
                IResource rest = CreateResource();
                first.AddProperty(RDF.PropertyRest, rest);
                first = rest;
            } while (elements.MoveNext());
            first.AddProperty(RDF.PropertyRest, RDF.Nil);
            return(root);
        }
Пример #12
0
        public void DeleteResourceTest()
        {
            Uri uri0 = new Uri("http://example.org/MyResource");
            Uri uri1 = new Uri("http://example.org/MyResource1");

            Assert.IsTrue(Model.ContainsResource(uri0));

            Model.DeleteResource(uri0);

            Assert.IsFalse(Model.ContainsResource(uri0));

            Property p0 = new Property(new Uri("http://example.org/MyProperty"));
            Property p1 = new Property(new Uri("http://example.org/MyProperty1"));

            IResource r0 = Model.CreateResource(uri0);

            r0.AddProperty(p0, "in the jungle");
            r0.AddProperty(p0, 123);
            r0.Commit();

            IResource r1 = Model.CreateResource(uri1);

            r1.AddProperty(p0, 123);
            r1.AddProperty(p1, r0);
            r1.Commit();

            Assert.IsTrue(Model.ContainsResource(r0));
            Assert.IsTrue(Model.ContainsResource(r1));

            Model.DeleteResource(r0);

            Assert.IsFalse(Model.ContainsResource(r0));
            Assert.IsTrue(Model.ContainsResource(r1));

            // Update the resource from the model.
            r1 = Model.GetResource(uri1);

            Assert.IsTrue(r1.HasProperty(p0, 123));
            Assert.IsFalse(r1.HasProperty(p1, r0));
        }
        public void SetUp()
        {
            UriRef uri = new UriRef("http://localhost:8899/models/ResourceQueryTest");

            Store = StoreFactory.CreateStore("provider=dotnetrdf");
            Model = Store.GetModel(new Uri("http://example.org/TestModel"));

            if (!Model.IsEmpty)
            {
                Model.Clear();
            }

            if (Model.IsEmpty)
            {
                IResource q           = null;
                string    uriTemplate = "http://example.com/counter/{0}";
                for (int i = 1; i < 51; i++)
                {
                    IResource r = Model.CreateResource <Resource>(new Uri(string.Format(uriTemplate, i)));
                    r.AddProperty(nco.fullname, (char)(i % 26));
                    r.AddProperty(nco.gender, (i % 2 == 1) ? nco.female : nco.male);

                    if (i % 5 != 0)
                    {
                        r.AddProperty(rdf.type, nco.PersonContact);
                    }
                    else
                    {
                        r.AddProperty(rdf.type, nco.OrganizationContact);
                    }

                    if (i <= 30)
                    {
                        r.AddProperty(nco.birthDate, new DateTime(1989, 12, i));
                    }
                    else
                    {
                        r.AddProperty(nco.birthDate, new DateTime(1990, 1, i - 30));
                    }

                    if (q != null)
                    {
                        r.AddProperty(nie.relatedTo, q);
                    }
                    else
                    {
                        _resource = r;
                    }

                    r.Commit();
                    q = r;
                }
            }
        }
Пример #14
0
        public void SetUp()
        {
            string connectionString = SetupClass.ConnectionString;

            Store = StoreFactory.CreateStore(string.Format("{0};rule=urn:semiodesk/test/ruleset", connectionString));

            Model = Store.GetModel(new Uri("http://localhost:8899/models/ResourceQueryTest"));

            if (!Model.IsEmpty)
            {
                Model.Clear();
            }

            IResource q = null;

            for (int i = 1; i < 51; i++)
            {
                IResource r = Model.CreateResource <Resource>();
                r.AddProperty(nco.fullname, (char)(i % 26));
                r.AddProperty(nco.gender, (i % 2 == 1) ? nco.female : nco.male);

                if (i % 5 != 0)
                {
                    r.AddProperty(rdf.type, nco.PersonContact);
                }
                else
                {
                    r.AddProperty(rdf.type, nco.OrganizationContact);
                }

                if (i <= 30)
                {
                    r.AddProperty(nco.birthDate, new DateTime(1989, 12, i));
                }
                else
                {
                    r.AddProperty(nco.birthDate, new DateTime(1990, 1, i - 30));
                }

                if (q != null)
                {
                    r.AddProperty(nie.relatedTo, q);
                }
                else
                {
                    _resource = r;
                }

                r.Commit();
                q = r;
            }
        }
Пример #15
0
        public void DeleteResouceTest2()
        {
            var uri = new Uri("ex:Resource2");

            IResource resource = Model.CreateResource(uri);

            resource.AddProperty(rdf.type, nco.Contact);
            resource.Commit();

            Assert.IsTrue(Model.ContainsResource(uri));

            Model.DeleteResource(resource);

            Assert.IsFalse(Model.ContainsResource(uri));
        }
Пример #16
0
        public void GetModelTest()
        {
            IModel m1 = Store.CreateModel(ModelUri);

            Assert.IsTrue(m1.IsEmpty);

            IResource r = m1.CreateResource(new Uri("ex:test:resource"));

            r.AddProperty(new Property(new Uri("ex:test:property")), "var");
            r.Commit();

            IModel m2 = Store.GetModel(ModelUri);

            Assert.AreEqual(ModelUri, m2.Uri);
            Assert.IsTrue(m2.ContainsResource(r));
        }
Пример #17
0
        public void WriteTest()
        {
            Model.Clear();

            Property property = new Property(new Uri("http://example.org/MyProperty"));

            IResource model2_resource2 = Model.CreateResource(new Uri("ex:Resource"));

            model2_resource2.AddProperty(property, "in the\n jungle");
            model2_resource2.Commit();

            MemoryStream wr = new MemoryStream();

            Model.Write(wr, RdfSerializationFormat.RdfXml);
            var myString = Encoding.UTF8.GetString(wr.ToArray());
        }
Пример #18
0
        public void GetModelTest()
        {
            Uri testModel = new Uri("ex:Test");

            IModel model0 = Store.CreateModel(testModel);

            IResource r = model0.CreateResource(new Uri("ex:test:resource"));

            r.AddProperty(new Property(new Uri("ex:test:property")), "var");
            r.Commit();

            IModel model1 = Store.GetModel(testModel);

            Assert.AreEqual(testModel, model1.Uri);
            Assert.IsTrue(model1.ContainsResource(r));
        }
Пример #19
0
        public void LiteralWithHyphenTest()
        {
            Model.Clear();

            Property property = new Property(new Uri("http://example.org/MyProperty"));

            IResource model2_resource2 = Model.CreateResource(new Uri("ex:Resource"));

            model2_resource2.AddProperty(property, "\"in the jungle\"");
            model2_resource2.Commit();

            IResource r = Model.GetResource(new Uri("ex:Resource"));
            object    o = r.GetValue(property);

            Assert.AreEqual(typeof(string), o.GetType());
            Assert.AreEqual("\"in the jungle\"", o);
        }
Пример #20
0
        public void ContainsModelTest()
        {
            Store.RemoveModel(ModelUri);

            Assert.IsFalse(Store.ContainsModel(ModelUri));

            IModel m1 = Store.CreateModel(ModelUri);

            IResource r = m1.CreateResource(new Uri("ex:test:resource"));

            r.AddProperty(new Property(new Uri("ex:test:property")), "var");
            r.Commit();


            Assert.IsTrue(Store.ContainsModel(ModelUri));

            Assert.IsFalse(Store.ContainsModel(new Uri("ex:NoTest")));
        }
Пример #21
0
        public void LiteralWithNewLineTest()
        {
            Model.Clear();

            Property p0 = new Property(new Uri("http://example.org/MyProperty"));

            IResource r0 = Model.CreateResource(new Uri("ex:Resource"));

            r0.AddProperty(p0, "in the\n jungle");
            r0.Commit();

            r0 = Model.GetResource(new Uri("ex:Resource"));

            object o = r0.GetValue(p0);

            Assert.AreEqual(typeof(string), o.GetType());
            Assert.AreEqual("in the\n jungle", o);
        }
Пример #22
0
        public void TestSelect()
        {
            // Retrieving bound variables using the SELECT query form.
            SparqlQuery        query  = new SparqlQuery("SELECT ?name ?birthday WHERE { ?x nco:fullname ?name. ?x nco:birthDate ?birthday. }");
            ISparqlQueryResult result = Model.ExecuteQuery(query);

            Assert.AreEqual(1, result.GetBindings().Count());

            // Retrieving resoures using the SELECT or DESCRIBE query form.
            query  = new SparqlQuery("SELECT ?s ?p ?o WHERE { ?s ?p ?o. ?s nco:fullname 'Hans Wurscht'. }");
            result = Model.ExecuteQuery(query);

            Assert.AreEqual(1, result.GetResources().Count());

            // Test SELECT with custom defined PREFIXes
            query  = new SparqlQuery("PREFIX nco: <http://www.semanticdesktop.org/ontologies/2007/03/22/nco#> SELECT ?s ?p ?o WHERE { ?s ?p ?o. ?s nco:fullname 'Hans Wurscht'. }");
            result = Model.ExecuteQuery(query);

            Assert.AreEqual(1, result.GetResources().Count());

            // Check if the select statement only works on the given model.
            query  = new SparqlQuery("SELECT * WHERE { ?s ?p ?o. }");
            result = Model.ExecuteQuery(query);

            Assert.AreEqual(5, result.GetResources().Count());

            // Check that resource creation is done correctly for Resources containing dashes.
            IResource r0 = Model.CreateResource(new Uri("http://example.org/Something#0"));

            r0.AddProperty(new Property(new Uri("http://example.org/fullName")), "Something");
            r0.Commit();

            IResource r1 = Model.CreateResource(new Uri("http://example.org/Something#1"));

            r1.AddProperty(new Property(new Uri("http://example.org/fullName")), "Anotherthing");
            r1.Commit();

            query  = new SparqlQuery("SELECT * WHERE { ?s ?p ?o. }");
            result = Model.ExecuteQuery(query);

            Assert.AreEqual(7, result.GetResources().Count());
        }
Пример #23
0
        //[Test]
        // This test does not run, but it needs to.
        public void AddUnmappedType()
        {
            IModel m = GetModel();

            m.Clear();

            Uri t1Uri           = new Uri("semio:test:testInstance1");
            Uri t2Uri           = new Uri("semio:test:testInstance2");
            MappingTestClass t1 = m.CreateResource <MappingTestClass>(t1Uri);

            IResource r = m.CreateResource(t2Uri);

            r.AddProperty(rdf.type, TestOntology.TestClass2);

            t1.AddProperty(TestOntology.uniqueResourceTest, r);
            t1.AddProperty(TestOntology.resourceTest, r);

            Assert.IsNull(t1.uniqueResourceTest);
            Assert.AreEqual(0, t1.resourceTest.Count);

            m.Clear();
        }
Пример #24
0
        public void DateTimeResourceTest()
        {
            Uri       resUri = new Uri("http://example.org/DateTimeTest");
            IResource res    = Model.CreateResource(resUri);

            Property property = new Property(new Uri("http://example.org/MyProperty"));

            DateTime t = new DateTime();

            Assert.IsTrue(DateTime.TryParse("2013-01-21T16:27:23.000Z", out t));

            res.AddProperty(property, t);
            res.Commit();

            IResource actual = Model.GetResource(resUri);
            object    o      = actual.GetValue(property);

            Assert.AreEqual(typeof(DateTime), o.GetType());
            DateTime actualDateTime = (DateTime)actual.GetValue(property);

            Assert.AreEqual(t.ToUniversalTime(), actualDateTime.ToUniversalTime());
        }
Пример #25
0
        public void SetUp()
        {
            string connectionString = SetupClass.ConnectionString;

            Store = StoreFactory.CreateStore(string.Format("{0};rule=urn:semiodesk/test/ruleset", connectionString));
            Model = Store.GetModel(new Uri("http://example.org/TestModel"));

            if (!Model.IsEmpty)
            {
                Model.Clear();
            }

            OntologyDiscovery.AddNamespace("ex", new Uri("http://example.org/"));
            OntologyDiscovery.AddNamespace("dc", new Uri("http://purl.org/dc/elements/1.1/"));
            OntologyDiscovery.AddNamespace("vcard", new Uri("http://www.w3.org/2001/vcard-rdf/3.0#"));
            OntologyDiscovery.AddNamespace("foaf", new Uri("http://xmlns.com/foaf/0.1/"));
            OntologyDiscovery.AddNamespace("dbpedia", new Uri("http://dbpedia.org/ontology/"));
            OntologyDiscovery.AddNamespace("dbpprop", new Uri("http://dbpedia.org/property/"));
            OntologyDiscovery.AddNamespace("schema", new Uri("http://schema.org/"));
            OntologyDiscovery.AddNamespace("nie", new Uri("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#"));
            OntologyDiscovery.AddNamespace("nco", new Uri("http://www.semanticdesktop.org/ontologies/2007/03/22/nco#"));
            OntologyDiscovery.AddNamespace("sfo", sfo.GetNamespace());
            OntologyDiscovery.AddNamespace(nfo.GetPrefix(), nfo.GetNamespace());

            Model.Clear();

            IResource resource0 = Model.CreateResource(new Uri("http://example.org/Hans"));

            resource0.AddProperty(rdf.type, nco.PersonContact);
            resource0.AddProperty(nco.fullname, "Hans Wurscht");
            resource0.AddProperty(nco.birthDate, DateTime.Now);
            resource0.AddProperty(nco.blogUrl, "http://blog.com/Hans");
            resource0.Commit();

            IResource resource1 = Model.CreateResource(new Uri("http://example.org/Task"));

            resource1.AddProperty(rdf.type, tmo.Task);
            resource1.AddProperty(tmo.taskName, "Eine Aufgabe.");
            resource1.AddProperty(nco.creator, resource0);
            resource1.Commit();

            IResource resource2 = Model.CreateResource(new Uri("http://example.org/Doc#1"));

            resource2.AddProperty(rdf.type, nfo.Document);
            resource2.AddProperty(dc.date, DateTime.Today);
            resource2.AddProperty(nco.creator, resource0);
            resource2.Commit();

            // NOTE: The different name influences the ordering of the resource in query results.
            IResource resource3 = Model.CreateResource(new Uri("http://example.org/Boc#2"));

            resource3.AddProperty(rdf.type, nfo.Document);
            resource3.AddProperty(dc.date, DateTime.Today.AddHours(1));
            resource3.AddProperty(nco.creator, resource0);
            resource3.Commit();

            IResource resource4 = Model.CreateResource(new Uri("http://example.org/Doc#3"));

            resource4.AddProperty(rdf.type, nfo.Document);
            resource4.AddProperty(dc.date, DateTime.Today.AddHours(2));
            resource4.AddProperty(nco.creator, resource0);
            resource4.Commit();
        }