1 10 package com.hp.hpl.jena.reasoner.rulesys.builtins; 11 12 import com.hp.hpl.jena.reasoner.rulesys.*; 13 import com.hp.hpl.jena.graph.*; 14 import java.util.*; 15 16 23 public class CountLiteralValues extends BaseBuiltin { 24 25 29 public String getName() { 30 return "countLiteralValues"; 31 } 32 33 36 public int getArgLength() { 37 return 3; 38 } 39 40 50 public boolean bodyCall(Node[] args, int length, RuleContext context) { 51 ArrayList values = new ArrayList(); 52 Node a0 = getArg(0, args, context); 53 Node a1 = getArg(1, args, context); 54 for (Iterator ni = context.find(a0, a1, null); ni.hasNext(); ) { 55 Node v = ((Triple)ni.next()).getObject(); 56 if (v.isLiteral()) { 57 boolean gotit = false; 60 for (Iterator i = values.iterator(); i.hasNext(); ) { 61 if (v.sameValueAs(i.next())) { 62 gotit = true; 63 break; 64 } 65 } 66 if (!gotit) { 67 values.add(v); 68 } 69 } 70 } 71 return context.getEnv().bind(args[2], Util.makeIntNode(values.size())); 72 } 73 74 } 75 76 | Popular Tags |