예제 #1
0
        public void TestSort()
        {
            ResourceQuery b = new ResourceQuery(nco.PersonContact);

            b.Where(nco.birthDate).LessThan(new DateTime(1990, 1, 1)).SortAscending();

            ResourceQuery a = new ResourceQuery(nco.PersonContact);

            a.Where(nco.gender);
            a.Where(nie.relatedTo, b);

            IResourceQueryResult result = Model.ExecuteQuery(b);

            List <Resource> resources = result.GetResources().ToList();

            Assert.AreEqual(18, resources.Count);

            DateTime?l = null;

            foreach (Resource r in resources)
            {
                DateTime t = (DateTime)r.GetValue(nco.birthDate);
                if (l.HasValue)
                {
                    Assert.IsTrue(t > l);
                }
                l = t;
            }


            a = new ResourceQuery(nco.PersonContact);
            a.Where(nco.gender);
            a.Where(nie.relatedTo, b);

            result = Model.ExecuteQuery(b, true);

            resources = result.GetResources().ToList();
            Assert.AreEqual(18, resources.Count);

            l = null;
            foreach (Resource r in resources)
            {
                DateTime t = (DateTime)r.GetValue(nco.birthDate);
                if (l.HasValue)
                {
                    Assert.IsTrue(t > l);
                }
                l = t;
            }
        }
예제 #2
0
        public void TestClone()
        {
            ResourceQuery b = new ResourceQuery(nco.PersonContact);

            b.Where(nco.birthDate).LessThan(new DateTime(1990, 1, 1)).SortAscending();

            ResourceQuery a = new ResourceQuery(nco.PersonContact);

            a.Where(nco.gender);
            a.Where(nie.relatedTo, b);

            ResourceQuery c = b.Clone();

            string q = SparqlSerializer.Serialize(Model, c);

            IResourceQueryResult result = Model.ExecuteQuery(c);

            int i = 0;

            foreach (Resource r in result.GetResources())
            {
                i++;
            }

            Assert.AreEqual(18, i);
        }
예제 #3
0
        private string GetOntologyTitle(IModel model)
        {
            try
            {
                ResourceQuery query = new ResourceQuery();
                query.Where(rdf.type, owl.Ontology);

                IResourceQueryResult result = model.ExecuteQuery(query);

                if (result.Count() == 0)
                {
                    return("");
                }

                IResource ontology = result.GetResources().First();

                return(ontology.ListValues(dces.Title).OfType <string>().FirstOrDefault());
            }
            catch
            {
                string msg = "Could not retrieve title of ontology <{0}>";
                Logger.LogWarning(string.Format(msg, model.Uri.ToString()));

                return("");
            }
        }
예제 #4
0
        public void ConnectTest()
        {
            Assert.NotNull(Model);
            Assert.NotNull(Model2);
            IModel model = Model;

            ResourceQuery contact = new ResourceQuery(nco.PersonContact);

            contact.Where(nco.birthDate).LessThan(new DateTime(1990, 1, 1));

            ResourceQuery group = new ResourceQuery(nco.ContactGroup);

            group.Where(nco.contactGroupName, "Family");

            contact.Where(nco.belongsToGroup, group);

            IResourceQueryResult result = model.ExecuteQuery(contact);

            foreach (Resource r in result.GetResources())
            {
                Console.WriteLine(r.Uri);
            }

            Contact c = model.CreateResource <Contact>(); // create new resource with GUID

            c.Birthday = new DateTime(1980, 6, 14);
            c.Fullname = "John Doe";
            c.Commit();
        }
        public void TestWhere()
        {
            ResourceQuery b      = new ResourceQuery(nco.PersonContact);
            var           filter = new DateTime(1990, 1, 1);

            b.Where(nco.birthDate).LessThan(filter);

            ResourceQuery a = new ResourceQuery(nco.PersonContact);

            a.Where(nco.gender);
            a.Where(nie.relatedTo, b);

            IResourceQueryResult result = Model.ExecuteQuery(b);

            List <Resource> resources = result.GetResources().ToList();

            Assert.AreEqual(18, resources.Count);

            foreach (Resource r in resources)
            {
                DateTime t = (DateTime)r.GetValue(nco.birthDate);
                Assert.IsTrue(t < filter);
            }

            resources = result.GetResources(0, 10).ToList();

            Assert.AreEqual(10, resources.Count);

            a = new ResourceQuery(nco.PersonContact);
            a.Where(nie.relatedTo, _resource);

            result = Model.ExecuteQuery(a);

            resources = result.GetResources().ToList();

            Assert.AreEqual(1, resources.Count);
        }
예제 #6
0
 public IEnumerable <T> GetItems(int offset, int limit)
 {
     return(_queryResult.GetResources <T>(offset, limit));
 }