Exemplo n.º 1
0
 private IEnumerable<string> GetClassUris()
 {
     MetadataSource source = new MetadataSource(opts);
     var properties = new ClassQuerySink(opts.IgnoreBlankNodes, opts.OntologyNamespace, new[] { "u" });
     SparqlResultSet results;
     if (opts.ExtractRdfsClasses)
     {
         results = source.QueryWithResultSet(sqGetRdfsClasses);
     } 
     else 
     {
         results = source.QueryWithResultSet(sqGetClasses);
     }
     Console.WriteLine(results.Count + " possible Classes retrieved");
     properties.Fill(results);
     return properties.bindings.Map(nvc => nvc["u"]);
 }
Exemplo n.º 2
0
        private IEnumerable <string> GetClassUris()
        {
            MetadataSource  source     = new MetadataSource(opts);
            var             properties = new ClassQuerySink(opts.IgnoreBlankNodes, opts.OntologyNamespace, new[] { "u" });
            SparqlResultSet results;

            if (opts.ExtractRdfsClasses)
            {
                results = source.QueryWithResultSet(sqGetRdfsClasses);
            }
            else
            {
                results = source.QueryWithResultSet(sqGetClasses);
            }
            Console.WriteLine(results.Count + " possible Classes retrieved");
            properties.Fill(results);
            return(properties.bindings.Map(nvc => nvc["u"]));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
        }