Package com.hp.hpl.jena.datatypes

Examples of com.hp.hpl.jena.datatypes.RDFDatatype


    Node p = env.getGroundVersion(args[1]);
    ExtendedIterator i = graph.find(s,p,null);
    int n = i.toSet().size();
   
    TypeMapper tm = TypeMapper.getInstance();
    RDFDatatype type = tm.getTypeByName(XSD.xint.getURI());
    Node count = Node.createLiteral(Integer.toString(n),null,type);
    env.bind(args[2],count);
    return true;
  }
View Full Code Here


   */
  public boolean bodyCall(Node[] args, int length, RuleContext context) {
    BindingEnvironment env = context.getEnv();
    Node value = env.getGroundVersion(args[0]);
    TypeMapper tm = TypeMapper.getInstance();
    RDFDatatype type = tm.getTypeByName(PrintUtil.expandQname(args[2].toString()));
    Node cast = Node.createLiteral(value.getLiteral().getValue().toString(),null,type);
    env.bind(args[1],cast);
    return type.isValid(value.getLiteral().getValue().toString());
  }
View Full Code Here

  public boolean toRDF(Node node, Resource subject, Property prop, String value, String type, Seq seq, Set<restriction> restrictions, Context ctx)
  throws Exception {
   
    if (type!=null && type.equals(XSD_URI+"#anySimpleType")) type = RDFS.Literal.getURI();
     
    RDFDatatype dt = getDatatype(type);
    Model m = ctx.getModel();
    Statement stmt = null;
    RDFNode object = null;
    if (value==null) return true;

    // are all restrictions observed
    if (restrictions!=null)
      for (restriction r: restrictions)
        if (!r.isValid(value,type,ctx)) return false;
   
    simpleType s = ctx.getSimpleType(type);
    if (s!=null) return s.toRDF(subject,prop,node,value,seq,restrictions,ctx);
   
    // this may be an ID embedded in element content
    else if (type!=null && type.equals(XSD_URI+"#ID")) {
      String uri = subject.isAnon()?null:subject.getURI();
      String frag = addFragment(ctx.getBaseMap(), value).toString();
      if (frag.equals(uri)) return true;
      else object = m.createResource(frag)
    }   
    else if (type!=null && type.equals(XSD_URI+"#IDREF"))
      object = m.createResource(addFragment(ctx.getBaseMap(), value).toString());   
   
    else if (type!=null && type.equals(XSD_URI+"#IDREFS"))
      object = toRDFList(node,value,XSD.IDREF.getURI(),null,ctx);   

    else if (type!=null && type.equals(XSD_URI+"#ENTITIES"))
      object = toRDFList(node,value,XSD.ENTITY.getURI(),null,ctx);   

    else if (type!=null && (type.equals(XSD_URI+"#QName") || type.equals(XSD_URI+"#NOTATION")))
      object = m.createResource(expandQName(ctx.getDefaultNS(),value,node,ctx.getModel()));
   
    else if (type!=null && type.equals(XSD_URI+"#anyURI")) {
      URI uri = null;
      if (isValidURI(value)) uri = new URI(value);
      // it may be a relative URI
      // to avoid confusion it should begin with an initial name character
      // ensure it isn't a QName
      else if (value.indexOf(":")<0 && Character.isJavaIdentifierStart(value.charAt(0)))
        uri = resolveBase(node, new URI(value), ctx);   
      if (uri!=null) object = m.createTypedLiteral(uri.toString(),dt);
      else return false;
    }
    else if (type!=null && type.equals(XSD_URI+"#anySimpleType")) {
      object = m.createTypedLiteral(value==null?"":value,dt);
    }
    else if (RDFS.Literal.getURI().equals(type)) {
      object = m.createLiteral(value==null?"":value);
    }
    else if (value!=null && dt!=null && dt.isValid(value)) object = m.createTypedLiteral(value, dt);
    else object = m.createLiteral(value==null?"":value);
   
    if (object==null) return false;
    // if no property is supplied just add the value to the sequence/list
    if (prop==null && seq!=null) seq.add(object);
View Full Code Here

      if (match.find()) value = match.group(1);
      Literal l = m.createTypedLiteral(value,RDF.getURI()+"XMLLiteral");
      stmt = m.createStatement(subject,prop,l);
    }
    else { // schema datatype?
      RDFDatatype dt = getDatatype(type);
      if (dt != null) {
        Literal l = m.createTypedLiteral(processWhitespace(elem,value,type,ctx), dt);
        stmt = m.createStatement(subject,prop,l);
      }
    }
View Full Code Here

 
  /** incrementally add a value to an RDFList */
 
  public static RDFList toRDFList(Node node, String value, String itemType, RDFList list, Set<restriction> restrictions, Context ctx)
  throws Exception {
    RDFDatatype dt = getDatatype(itemType);
    Model m = ctx.getModel();
    RDFNode object = null;
   
    value = processWhitespace(node,value,itemType,ctx);

    if (itemType!=null && itemType.equals(XSD_URI+"#QName")) {
      String name = expandQName(ctx.getDefaultNS(),null,value,node,ctx.getModel());
      if (name==null) return null; // one bad value invalidates the entire list
      else object = m.createResource(name);
    }
    else if (itemType!=null && itemType.equals(XSD.IDREF.getURI())) {
      if (value.indexOf(':')>=0) return null; // avoid confusion with QNames
      object = ctx.getModel().createResource(addFragment(ctx.getBaseMap(), value).toString());
    }
   
    else if (itemType!=null && itemType.equals(XSD_URI+"#anyURI")) {
      URI uri = null;
      if (isValidURI(value)) uri = new URI(value);
      // ensure this isn't a QName
      else if (value.indexOf(":")<0 && Character.isJavaIdentifierStart(value.charAt(0)))
        uri = resolveBase(node, new URI(value), ctx);
      if (uri!=null) object = m.createTypedLiteral(uri.toString(),dt);
      else return null;
    }
    else if (value!=null && dt!=null && dt.isValid(value)) object = m.createTypedLiteral(value, dt);
    else object = m.createLiteral(value==null?"":value);
   
    // add the value to the list
    if (list.isEmpty()) list = ctx.getModel().createList(new RDFNode[] {object});
    else list.add(object);
View Full Code Here

   * @return
   */
  protected static RDFDatatype getDatatype(String type) {
    if (type==null) return null;
    TypeMapper tm = TypeMapper.getInstance();
    RDFDatatype dt = tm.getTypeByName(type);
    if (dt == null) {
      // we've got a new (derived) datatype here
      dt = new BaseDatatype(type);
      tm.registerDatatype(dt);
    }
View Full Code Here

  }
 
  @SuppressWarnings("unchecked")
  public static DataRange toOWL(OntModel ont, String type, enumeration[] en) {
    Vector v = new Vector();
    RDFDatatype dt = type==null?null:getDatatype(type);
    for (int i=0; i<en.length; i++) {
      if (dt!=null) v.add(ont.createTypedLiteral(en[i].getValue(),dt));
      else v.add(ont.createLiteral(en[i].getValue()));
    }
    return ont.createDataRange(ont.createList(v.iterator()));
View Full Code Here

    }
    return ont.createList(v.iterator());   
  }

  public boolean isValid(String value, String type) {
    RDFDatatype dt = getDatatype(type);
    if (dt!=null && dt.isValid(value) && dt.isValid(this.value)) {
      if (type.equals(schema.XSD_URI+"#base64Binary")
       || type.equals(schema.XSD_URI+"#hexBinary")) {
        byte[] b = (byte[]) getDatatype(type).parse(value);
        byte[] b1 = (byte[]) getDatatype(type).parse(this.value);
        return Arrays.equals(b,b1);
      }
      else return dt.parse(value).equals(dt.parse(this.value));
    }
    else return value.equals(this.value);
  }
View Full Code Here

     * If this test passes then if the typed value has a legal lexical form for
     * this type then it is a legal instance.
     */
    public boolean isBaseTypeCompatible(LiteralLabel lit) {
        XSTypeDefinition base = getFoundingType();
        RDFDatatype litDT = lit.getDatatype();
        if (litDT instanceof XSDDatatype) {
            XSTypeDefinition litBase = ((XSDDatatype)litDT).getFoundingType();
            return base.equals(litBase);

        } else if (litDT == null && lit.language().equals("")) {
View Full Code Here

    }

    public static NodeValue substring(NodeValue nvString, NodeValue nvStart, NodeValue nvLength)
    {
        Node n = checkAndGetStringLiteral("substring", nvString) ;
        RDFDatatype dt = n.getLiteralDatatype() ;
        String lang = n.getLiteralLanguage() ;
       
        // A string of some kind.
       
        // XSD F&O:
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.datatypes.RDFDatatype

Copyright © 2018 www.massapicom. 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.