Пример #1
0
 private IEnumerable<OntologyClass> GetTestData()
 {
     var ontologyClass = new OntologyClass
                	{
                		Name = "Class1",
                		IncomingRelationships = null,
                		Uri = "http://purl.aabs.org/ont/2008/09/ont#class1"
                	};
     var ontologyProperties = GetProperties(ontologyClass).ToArray();
     ontologyClass.Properties = ontologyProperties;
     yield return ontologyClass;
 }
Пример #2
0
 private IEnumerable<OntologyProperty> GetProperties(OntologyClass ontologyClass)
 {
     for (int i = 0; i < 5; i++)
     {
     yield return new OntologyProperty
                  	{
                  		HostClass = ontologyClass,
                         IsObjectProp = true,
                         Name = "Prop" + i,
                         Range = "Range" + i,
                         RangeUri = "range" + i,
                         Uri = "prop" + i
                  	};
     }
 }
        private OntologyClass GetClass(string classUri)
        {
            var u = new Uri(classUri);
            string className = GetNameFromUri(classUri); Console.WriteLine(className);
            var source = new SparqlHttpSource(opts.endpoint);
            var properties = new ClassQuerySink(opts.ignoreBlankNodes, null, new[] { "p", "r" });

            string sparqlQuery = string.Format(sqGetProperty, classUri);
            source.RunSparqlQuery(sparqlQuery, properties);
            IEnumerable<Tuple<string, string>> q1 = properties.bindings
                .Map(nvc => new Tuple<string, string>(nvc["p"], nvc["r"]))
                .Where(t => (!(string.IsNullOrEmpty(t.First) || string.IsNullOrEmpty(t.Second))));

            sparqlQuery = string.Format(sqGetObjectProperty, classUri);
            source.RunSparqlQuery(sparqlQuery, properties);
            IEnumerable<Tuple<string, string>> q2 = properties.bindings
                .Map(nvc => new Tuple<string, string>(nvc["p"], nvc["r"]))
                .Where(t => (!(string.IsNullOrEmpty(t.First) || string.IsNullOrEmpty(t.Second))));
            IEnumerable<OntologyProperty> ops = q2.Map(t => new OntologyProperty
                                                       {
                                                           Uri = t.First.Trim(),
                                                           IsObjectProp = true,
                                                           Name = GetNameFromUri(t.First),
                                                           Range = GetNameFromUri(t.Second),
                                                           RangeUri = t.Second
                                                       });
            IEnumerable<OntologyProperty> dps = q1.Map(t => new OntologyProperty
                                                       {
                                                           Uri = t.First.Trim(),
                                                           IsObjectProp = false,
                                                           Name = GetNameFromUri(t.First),
                                                           Range = GetNameFromUri(t.Second),
                                                           RangeUri = t.Second
                                                       });
            var d = new Dictionary<string, OntologyProperty>();
            IEnumerable<OntologyProperty> props = ops.Union(dps).Map(p => TranslateType(p));
            foreach (OntologyProperty prop in props)
            {
                d[prop.Uri] = prop;
            }
            var result = new OntologyClass
                             {
                                 Name = className,
                                 Uri = classUri,
                                 Properties = d.Values.Where(p => NamespaceMatches(p)).ToArray()
                             };

            return result;
        }