Пример #1
0
        public void PelletKBList()
        {
            try
            {
                PelletServer server = new PelletServer(PelletTestServer);

                foreach (KnowledgeBase kb in server.KnowledgeBases)
                {
                    Console.WriteLine(kb.Name);
                    Console.WriteLine("Services:");
                    foreach (PelletService svc in kb.Services)
                    {
                        Console.WriteLine("  " + svc.Name);
                        Console.WriteLine("    Uri: " + svc.Endpoint.Uri.ToString());
                        Console.WriteLine("    HTTP Methods: " + String.Join(",", svc.Endpoint.HttpMethods.ToArray()));
                        Console.WriteLine("    Response MIME Types: " + String.Join(",", svc.MimeTypes.ToArray()));
                    }
                    Console.WriteLine();
                }
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Error", ex, true);
            }
        }
Пример #2
0
        public void PelletQuery()
        {
            try
            {
                PelletServer server = new PelletServer(PelletTestServer);
                Type svcType = typeof(QueryService);

                foreach (KnowledgeBase kb in server.KnowledgeBases)
                {
                    if (kb.SupportsService(svcType)) 
                    {
                        Console.WriteLine(kb.Name + " supports SPARQL Query");
                        QueryService q = (QueryService)kb.GetService(svcType);
                        Object results = q.Query("SELECT * WHERE {?s a ?type} LIMIT 10");
                        if (results is SparqlResultSet)
                        {
                            TestTools.ShowResults(results);
                        }
                        else
                        {
                            Console.WriteLine("Unexpected Result type from Query Service");
                        }
                    } 
                    else 
                    {
                        Console.WriteLine(kb.Name + " does not support the Query Service");
                    }
                    Console.WriteLine();
                }
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Error", ex, true);
            }
        }
Пример #3
0
 /// <summary>
 /// Creates a new Pellet Reasoner
 /// </summary>
 /// <param name="server">Pellet Server</param>
 /// <param name="kbName">Knowledge Base name</param>
 public PelletReasoner(PelletServer server, String kbName)
 {
     this._server = server;
     if (this._server.HasKnowledgeBase(kbName))
     {
         this._kb = this._server.GetKnowledgeBase(kbName);
     }
     else
     {
         throw new RdfReasoningException("Cannot create a Pellet Reasoner for the Knowledge Base named '" + kbName + "' as this Server does not have the named Knowledge Base");
     }
 }
Пример #4
0
        /// <summary>
        /// Creates a new Pellet Query Processor
        /// </summary>
        /// <param name="server">Pellet Server</param>
        /// <param name="kbName">Knowledge Base Name</param>
        public PelletQueryProcessor(PelletServer server, String kbName)
        {
            if (server.HasKnowledgeBase(kbName))
            {
                KnowledgeBase kb = server.GetKnowledgeBase(kbName);

                //Check SPARQL Query is supported
                if (kb.SupportsService(this._svcType))
                {
                    this._svc = (QueryService)kb.GetService(this._svcType);
                }
                else
                {
                    throw new NotSupportedException("Cannot create a Pellet Query Processor as the selected Knowledge Base does not support the Query Service");
                }
            }
            else
            {
                throw new NotSupportedException("Cannot create a Pellet Query Processor for the Knowledge Base named '" + kbName + "' as this Server does not have the named Knowledge Base");
            }
        }
Пример #5
0
        public void PelletRealize()
        {
            try
            {
                PelletServer server = new PelletServer(PelletTestServer);
                Type svcType = typeof(RealizeService);

                foreach (KnowledgeBase kb in server.KnowledgeBases)
                {
                    if (kb.SupportsService(svcType))
                    {
                        Console.WriteLine(kb.Name + " supports Realize");
                        RealizeService svc = (RealizeService)kb.GetService(svcType);
                        IGraph g = svc.Realize();
                        TestTools.ShowGraph(g);
                    }
                    else
                    {
                        Console.WriteLine(kb.Name + " does not support the Realize Service");
                    }
                    Console.WriteLine();
                }
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Error", ex, true);
            }
        }
Пример #6
0
        public void PelletPredict2()
        {
            try
            {
                PelletServer server = new PelletServer(PelletTestServer);
                Type svcType = typeof(PredictService);

                foreach (KnowledgeBase kb in server.KnowledgeBases)
                {
                    if (kb.SupportsService(svcType))
                    {
                        Console.WriteLine(kb.Name + " supports Prediction");
                        PredictService svc = (PredictService)kb.GetService(svcType);

                        List<INode> predictions = svc.Predict("wine:DAnjou", "wine:locatedIn");
                        Console.WriteLine(predictions.Count + " Predictions");
                        foreach (INode obj in predictions)
                        {
                            Console.WriteLine(obj.ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine(kb.Name + " does not support the Prediction Service");
                    }
                    Console.WriteLine();
                }
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Error", ex, true);
            }
        }
Пример #7
0
        public void PelletPredict()
        {
            try
            {
                PelletServer server = new PelletServer(PelletTestServer);
                Type svcType = typeof(PredictService);

                foreach (KnowledgeBase kb in server.KnowledgeBases)
                {
                    if (kb.SupportsService(svcType))
                    {
                        Console.WriteLine(kb.Name + " supports Prediction");
                        PredictService svc = (PredictService)kb.GetService(svcType);

                        IGraph g = svc.PredictRaw("wine:DAnjou", "wine:locatedIn");
                        TestTools.ShowGraph(g);
                    }
                    else
                    {
                        Console.WriteLine(kb.Name + " does not support the Prediction Service");
                    }
                    Console.WriteLine();
                }
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Error", ex, true);
            }
        }
Пример #8
0
        public void PelletSimilarity2()
        {
            try
            {
                PelletServer server = new PelletServer(PelletTestServer);
                Type svcType = typeof(SimilarityService);

                foreach (KnowledgeBase kb in server.KnowledgeBases)
                {
                    if (kb.SupportsService(svcType))
                    {
                        Console.WriteLine(kb.Name + " supports Similarity");
                        SimilarityService svc = (SimilarityService)kb.GetService(svcType);

                        List<KeyValuePair<INode, double>> results = svc.Similarity(5, "wine:Red");
                        foreach (KeyValuePair<INode, double> kvp in results)
                        {
                            Console.WriteLine(kvp.Key.ToString() + " (Similarity = " + kvp.Value + ")");
                        }
                    }
                    else
                    {
                        Console.WriteLine(kb.Name + " does not support the Similarity Service");
                    }
                    Console.WriteLine();
                }
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Error", ex, true);
            }
        }
Пример #9
0
        public void PelletClusterWithType()
        {
            try
            {
                PelletServer server = new PelletServer(PelletTestServer);
                Type svcType = typeof(ClusterService);

                foreach (KnowledgeBase kb in server.KnowledgeBases)
                {
                    if (kb.SupportsService(svcType))
                    {
                        Console.WriteLine(kb.Name + " supports Clustering");
                        ClusterService svc = (ClusterService)kb.GetService(svcType);
                        Console.WriteLine("Cluster=3 and Type=wine:WineGrape");
                        List<List<INode>> clusters = svc.Cluster(3, "wine:WineGrape");
                        Console.WriteLine(clusters.Count + " Clusters returned");
                        for (int i = 0; i < clusters.Count; i++)
                        {
                            Console.WriteLine("Cluster " + (i + 1) + " contains " + clusters[i].Count + " Items");
                        }
                    }
                    else
                    {
                        Console.WriteLine(kb.Name + " does not support the Cluster Service");
                    }
                    Console.WriteLine();
                }
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Error", ex, true);
            }
        }
Пример #10
0
        public void PelletIcv()
        {
            try
            {
                PelletServer server = new PelletServer(PelletTestServer);
                Type svcType = typeof(IntegrityConstraintValidationService);

                foreach (KnowledgeBase kb in server.KnowledgeBases)
                {
                    if (kb.SupportsService(svcType))
                    {
                        Console.WriteLine(kb.Name + " supports ICV");
                        IntegrityConstraintValidationService svc = (IntegrityConstraintValidationService)kb.GetService(svcType);

                        ITripleStore store = svc.Validate();
                        Console.WriteLine("ICV returned " + store.Graphs.Count + " with " + store.Graphs.Sum(g => g.Triples.Count) + " Triples");

                        foreach (Graph g in store.Graphs)
                        {
                            TestTools.ShowGraph(g);
                            Console.WriteLine();
                        }
                    }
                    else
                    {
                        Console.WriteLine(kb.Name + " does not support the ICV Service");
                    }
                    Console.WriteLine();
                }
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Error", ex, true);
            }
        }
Пример #11
0
        public void PelletNamespace()
        {
            try
            {
                PelletServer server = new PelletServer(PelletTestServer);
                Type svcType = typeof(NamespaceService);

                foreach (KnowledgeBase kb in server.KnowledgeBases)
                {
                    if (kb.SupportsService(svcType))
                    {
                        Console.WriteLine(kb.Name + " supports Namespaces");
                        NamespaceService svc = (NamespaceService)kb.GetService(svcType);
                        NamespaceMapper nsmap = svc.GetNamespaces();
                        foreach (String prefix in nsmap.Prefixes)
                        {
                            Console.WriteLine(prefix + ": " + nsmap.GetNamespaceUri(prefix).ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine(kb.Name + " does not support the Search Service");
                    }
                    Console.WriteLine();
                }
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Error", ex, true);
            }
        }
Пример #12
0
        public void PelletSearch()
        {
            try
            {
                PelletServer server = new PelletServer(PelletTestServer);
                Type svcType = typeof(SearchService);

                foreach (KnowledgeBase kb in server.KnowledgeBases)
                {
                    if (kb.SupportsService(svcType))
                    {
                        Console.WriteLine(kb.Name + " supports Search");
                        SearchService svc = (SearchService)kb.GetService(svcType);
                        foreach (SearchServiceResult result in svc.Search("cabernet"))
                        {
                            Console.WriteLine(result.ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine(kb.Name + " does not support the Search Service");
                    }
                    Console.WriteLine();
                }
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Error", ex, true);
            }
        }
Пример #13
0
        public void PelletConsistency()
        {
            try
            {
                PelletServer server = new PelletServer(PelletTestServer);
                Type svcType = typeof(ConsistencyService);

                foreach (KnowledgeBase kb in server.KnowledgeBases)
                {
                    if (kb.SupportsService(svcType))
                    {
                        Console.WriteLine(kb.Name + " supports Consistency");
                        ConsistencyService svc = (ConsistencyService)kb.GetService(svcType);
                        Console.WriteLine("Consistency: " + svc.IsConsistent().ToString());
                    }
                    else
                    {
                        Console.WriteLine(kb.Name + " does not support the Consistency Service");
                    }
                    Console.WriteLine();
                }
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Error", ex, true);
            }
        }