Package com.hp.jena.rules.functions.jena2

Source Code of com.hp.jena.rules.functions.jena2.CountLiteralValues

package com.hp.jena.rules.functions.jena2;

import java.util.List;

import com.hp.jena.datatypes.xsd.XSDDatatype;
import com.hp.jena.graph.Node;
import com.hp.jena.graph.NodeFactory;
import com.hp.jena.rules.functions.ApplyableBase;
import com.hp.jena.rules.retelike.impl.Bindings;
import com.hp.jena.rules.retelike.impl.ExecContext;

/**
     CountLiteralValues(X, P, C) sets C to be the number of semantically
     distinct values for P on resource X. This is expensive.
*/
public class CountLiteralValues extends ApplyableBase
    {
    protected final Node X, P, C;
   
    public CountLiteralValues( List<Node> nargs )
        {
        X = nargs.get( 0 );
        P = nargs.get( 1 );
        C = nargs.get( 2 );
        }

    @Override public boolean evalBool( ExecContext c, Bindings<Node, Node> item )
        {
        Node xv = eval( item, X ), pv = eval( item, P );
        int n = c.countDistinctValues( xv, pv );
        return ApplyableBase.bind( item, C, integerNode( n ) );
        }

    private Node integerNode( int n )
        { return NodeFactory.createTypedLiteral( "" + n, XSDDatatype.XSDint.getURI() ); }
    }
TOP

Related Classes of com.hp.jena.rules.functions.jena2.CountLiteralValues

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.