コード例 #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
			             	};
    		}
		}
コード例 #3
0
        private OntologyClass GetClass(string classUri)
        {
            var    u         = new Uri(classUri);
            string className = GetNameFromUri(classUri);

            Console.WriteLine("Processing Class " + className);

            string         supertype  = "OwlClassSupertype";
            MetadataSource source     = new MetadataSource(opts);
            var            properties = new ClassQuerySink(opts.IgnoreBlankNodes, null, new[] { "p", "r" });

            string sparqlQuery = string.Format(sqGetSupertype, classUri);

            //try
            //{
            //    SparqlResultSet results = source.QueryWithResultSet(sparqlQuery);
            //    if (results.Count == 1)
            //    {
            //        if (results[0]["c"].NodeType == NodeType.Uri)
            //        {
            //            supertype = results[0]["c"].ToString();
            //            if (!supertype.Equals("http://www.w3.org/2002/07/owl#Class"))
            //            {
            //                supertype = GetNameFromUri(supertype);
            //            }
            //            else
            //            {
            //                supertype = "OwlClassSupertype";
            //            }
            //        }
            //    }
            //}
            //catch
            //{
            //    //Ignore the errors
            //}

            sparqlQuery = string.Format(sqGetProperty, classUri);
            try
            {
                SparqlResultSet results = source.QueryWithResultSet(sparqlQuery);
                properties.Fill(results);
            }
            catch
            {
                //Ignore the errors
            }
            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);
            try
            {
                SparqlResultSet results = source.QueryWithResultSet(sparqlQuery);
                properties.Fill(results);
            }
            catch
            {
                //Ignore the errors
            }

            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,
                Supertype  = supertype,
                Properties = d.Values.Where(p => NamespaceMatches(p)).ToArray()
            };

            return(result);
        }
コード例 #4
0
        private OntologyClass GetClass(string classUri)
        {
            var u = new Uri(classUri);
            string className = GetNameFromUri(classUri); 
            
            Console.WriteLine("Processing Class " + className);

            string supertype = "OwlClassSupertype";
            MetadataSource source = new MetadataSource(opts);
            var properties = new ClassQuerySink(opts.IgnoreBlankNodes, null, new[] { "p", "r" });

            string sparqlQuery = string.Format(sqGetSupertype, classUri);
            //try
            //{
            //    SparqlResultSet results = source.QueryWithResultSet(sparqlQuery);
            //    if (results.Count == 1)
            //    {
            //        if (results[0]["c"].NodeType == NodeType.Uri)
            //        {
            //            supertype = results[0]["c"].ToString();
            //            if (!supertype.Equals("http://www.w3.org/2002/07/owl#Class"))
            //            {
            //                supertype = GetNameFromUri(supertype);
            //            }
            //            else
            //            {
            //                supertype = "OwlClassSupertype";
            //            }
            //        }
            //    }
            //}
            //catch
            //{
            //    //Ignore the errors
            //}
                
            sparqlQuery = string.Format(sqGetProperty, classUri);
            try
            {
                SparqlResultSet results = source.QueryWithResultSet(sparqlQuery);
                properties.Fill(results);
            }
            catch
            {
                //Ignore the errors
            }
            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);
            try
            {
                SparqlResultSet results = source.QueryWithResultSet(sparqlQuery);
                properties.Fill(results);
            }
            catch
            {
                //Ignore the errors
            }

            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,
                                 Supertype = supertype,
                                 Properties = d.Values.Where(p => NamespaceMatches(p)).ToArray()
                             };

            return result;
        }