Exemplo n.º 1
0
        /**
         * Attempts to cast a given INode into an Aggregation.
         * Resources that have an aggregation type as their rdf:type
         * are recognized as well-formed aggregations.
         * @param resource  the INode to cast
         * @return the Aggregation or null if INode is not a well-formed aggregation
         */
        public static IAggregation asAggregation(IResource resource)
        {
            if (resource == null)
            {
                return(null);
            }
            IEnumerator <IResource> it = resource.getObjects(RDF.PropertyType).GetEnumerator();

            //JenaUtil.setGraphReadOptimization(true);
            try
            {
                while (it.MoveNext())
                {
                    IResource type = it.Current;
                    if (type.isUri())
                    {
                        if (Aggregations.getName((IResource)type) != null)
                        {
                            it.Dispose();
                            return(new AggregationImpl(resource, resource.getModel()));
                        }
                    }
                }
            }
            finally
            {
                //JenaUtil.setGraphReadOptimization(false);
            }
            return(null);
        }
Exemplo n.º 2
0
        override public void Print(ISparqlPrinter p)
        {
            IVariable asVar = getAs();

            if (asVar != null)
            {
                p.print("(");
            }

            INode  aggType = this.getObject(RDF.PropertyType);
            String aggName = Aggregations.getName(aggType);

            p.printKeyword(aggName);
            p.print("(");

            if (isDistinct())
            {
                p.print("DISTINCT ");
            }

            Triple exprS = this.getProperty(SP.PropertyExpression);

            if (exprS != null && !(exprS.Object is ILiteralNode))
            {
                IResource r    = Resource.Get(exprS.Object, getModel());
                IResource expr = SPINFactory.asExpression(r);
                if (expr is IPrintable)
                {
                    ((IPrintable)expr).Print(p);
                }
                else
                {
                    p.printURIResource(r);
                }
            }
            else
            {
                p.print("*");
            }
            String separator = getString(SP.PropertySeparator);

            if (separator != null)
            {
                p.print("; ");
                p.printKeyword("SEPARATOR");
                p.print("=''"); //"='" + DatasetUtil.escapeString(separator) + "'");
            }
            if (asVar != null)
            {
                p.print(") ");
                p.printKeyword("AS");
                p.print(" ");
                p.print(asVar.ToString());
            }
            p.print(")");
        }