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.vocabulary.RDFS; 14 import com.hp.hpl.jena.datatypes.RDFDatatype; 15 import com.hp.hpl.jena.datatypes.TypeMapper; 16 import com.hp.hpl.jena.graph.*; 17 import com.hp.hpl.jena.graph.impl.LiteralLabel; 18 19 26 public class IsDType extends BaseBuiltin { 27 28 32 public String getName() { 33 return "isDType"; 34 } 35 36 39 public int getArgLength() { 40 return 2; 41 } 42 43 53 public boolean bodyCall(Node[] args, int length, RuleContext context) { 54 checkArgs(length, context); 55 Node val = getArg(0, args, context); 56 Node dt = getArg(1, args, context); 57 return isTypeOK(val, dt); 58 } 59 60 65 public static boolean isTypeOK(Node val, Node dt) { 66 if (!dt.isURI()) return false; 67 if (val.isBlank()) return true; 68 if (val.isLiteral()) { 69 LiteralLabel ll = val.getLiteral(); 70 if (ll.getDatatype() != null && (! ll.isWellFormed())) return false; 71 if (dt.equals(RDFS.Nodes.Literal)) { 72 return true; 73 } else { 74 RDFDatatype dtype = TypeMapper.getInstance().getSafeTypeByName(dt.getURI()); 75 return dtype.isValidLiteral(val.getLiteral()); 76 } 77 } 78 return false; 79 } 80 81 } 82 83 84 | Popular Tags |