/**
         * Collects all queries or template calls at a given class.
         * @param cls  the class to get the queries at
         * @param predicate  the predicate such as <code>spin:rule</code>
         * @param results  the List to add the results to
         */
        public static void addQueryOrTemplateCalls(IResource cls, INode predicate, List <QueryOrTemplateCall> results)
        {
            IEnumerable <Triple> ss = cls.listProperties(predicate);

            // Special case: we might have an instance of a template call like spl:Attribute
            //               Then try to find the Template in the registry
            if (!ss.Any() && cls != null && cls.isUri())
            {
                ITemplate template = SPINModuleRegistry.getTemplate(cls.Uri(), null);
                if (template != null)
                {
                    ss = template.listProperties(predicate);
                }
            }

            foreach (Triple s in ss)
            {
                if (!(s.Object is ILiteralNode))
                {
                    ITemplateCall templateCall = SPINFactory.asTemplateCall(Resource.Get(s.Object, cls.getModel()));
                    if (templateCall != null)
                    {
                        results.Add(new QueryOrTemplateCall(cls, templateCall));
                    }
                    else
                    {
                        IQuery query = SPINFactory.asQuery(Resource.Get(s.Object, cls.getModel()));
                        if (query != null)
                        {
                            results.Add(new QueryOrTemplateCall(cls, query));
                        }
                    }
                }
            }
        }
Exemple #2
0
        internal IQuery BuildQuery(String sparqlQuery)
        {
            IQuery spinQuery = null;

            if (queryCache.ContainsKey(sparqlQuery))
            {
                spinQuery = (IQuery)queryCache[sparqlQuery];
            }
            else
            {
                _currentSparqlGraph         = new Graph();
                _currentSparqlGraph.BaseUri = UriFactory.Create("sparql-query:" + sparqlQuery);
                INode q = new SparqlQueryParser().ParseFromString(sparqlQuery).ToSpinRdf(_currentSparqlGraph);
                if (!_currentSparqlGraph.IsEmpty)
                {
                    _spinConfiguration.AddGraph(_currentSparqlGraph);
                    spinQuery = SPINFactory.asQuery(Resource.Get(q, this));
                    queryCache[sparqlQuery] = spinQuery;
                }
            }
            return(spinQuery);
        }
        public void PrintEnhancedSPARQL(IResource resource)
        {
            if (resource == null)
            {
                return;
            }
            IEnumerable <IResource> elements = resource.AsList();

            foreach (Resource element in elements)
            {
                if (element.canAs(SP.ClassQuery))
                {
                    SPINFactory.asQuery(element).PrintEnhancedSPARQL(this);
                    continue;
                }
                else if (element.canAs(SP.ClassCommand))
                {
                    SPINFactory.asUpdate(element).PrintEnhancedSPARQL(this);
                    continue;
                }
                else if (element.canAs(SP.ClassVariable))
                {
                    SPINFactory.asVariable(element).PrintEnhancedSPARQL(this);
                    continue;
                }
                else if (element.isUri())
                {
                    printURIResource(element);
                    continue;
                }
                IElement asElement = SPINFactory.asElement(element);
                if (asElement != null)
                {
                    asElement.PrintEnhancedSPARQL(this);
                }
            }
        }