private static void addTemplateCallResults(List <ConstraintViolation> results, QueryOrTemplateCall qot,
                                                   SpinWrapperDataset model, INode resource, bool matchValue, IProgressMonitor monitor)
        {
            ITemplateCall templateCall = qot.getTemplateCall();
            ITemplate     template     = templateCall.getTemplate();

            if (template != null && template.getBody() is IQuery)
            {
                IQuery spinQuery = (IQuery)template.getBody();
                if (spinQuery is IAsk || spinQuery is IConstruct)
                {
                    SparqlParameterizedString arq = DatasetUtil.createQuery(spinQuery);
                    setInitialBindings(resource, templateCall, arq);

                    if (spinQuery is IAsk)
                    {
                        if (((SparqlResultSet)model.Query(DatasetUtil.prepare(arq, model, null).ToString())).Result != matchValue)
                        {
                            List <SimplePropertyPath> paths = getPropertyPaths(resource, spinQuery.getWhere(), templateCall.getArgumentsMapByProperties());
                            String message = SPINLabels.getLabel(templateCall);
                            message += "\n(SPIN constraint at " + SPINLabels.getLabel(qot.getCls()) + ")";
                            results.Add(createConstraintViolation(paths, NO_FIXES, model, resource, message, templateCall));
                        }
                    }
                    else if (spinQuery is IConstruct)
                    {
                        IGraph cm     = model.MonitorConstruct(DatasetUtil.prepare(DatasetUtil.convertConstructToInsert(arq, spinQuery, model._transactionUri), model, null), spinQuery, null);
                        INode  source = getSource(qot);
                        String label  = SPINLabels.getLabel(templateCall);
                        addConstructedProblemReports(cm, results, model, qot.getCls(), resource, label, source);
                    }
                }
            }
        }
        private static void runQueryOnClass(List <ConstraintViolation> results, SparqlParameterizedString arq, IQuery spinQuery, String label, SpinWrapperDataset model, IResource cls, Dictionary <String, IResource> initialBindings, bool thisUnbound, bool thisDeep, INode source, List <SPINStatistics> stats, IProgressMonitor monitor)
        {
            SpinProcessor spinModel = cls.getModel();

            // let the underlying engine handle this.
            if (true || thisUnbound || SPINUtil.isRootClass(Resource.Get(cls, spinModel)) /*|| model.contains(null, RDF.type, cls)*/)
            {
                QuerySolutionMap arqBindings = new QuerySolutionMap();
                if (!thisUnbound)
                {
                    arqBindings.Add(SPINUtil.TYPE_CLASS_VAR_NAME, cls);
                }
                if (initialBindings != null)
                {
                    foreach (String varName in initialBindings.Keys)
                    {
                        INode value = initialBindings[varName];
                        arqBindings.Add(varName, value);
                    }
                }

                if (monitor != null)
                {
                    monitor.subTask("Checking SPIN constraint on " + SPINLabels.getLabel(cls) + (label != null ? ": " + label : ""));
                }

                DateTime startTime = DateTime.Now;
                if (thisDeep && !thisUnbound)
                {
                    arq.CommandText = SPINUtil.addThisTypeClause(arq.CommandText);
                    arqBindings[SPINUtil.TYPE_CLASS_VAR_NAME] = cls;
                }
                //TODO replace this with the real query rewriting
                IGraph cm = model.MonitorConstruct(arq, spinQuery, arqBindings);
                model.DeleteGraphInternal(cm.BaseUri.ToString());
                DateTime endTime = DateTime.Now;
                if (stats != null)
                {
                    TimeSpan duration  = endTime - startTime;
                    String   queryText = SPINLabels.getLabel(spinQuery);
                    if (label == null)
                    {
                        label = queryText;
                    }
                    stats.Add(new SPINStatistics(label, queryText, duration, startTime, cls));
                }
                model.UpdateGraph(model._transactionUri.ToString(), cm.Triples, null);
                addConstructedProblemReports(cm, results, model, cls, null, label, source);
            }
        }