Package com.hp.hpl.jena.rdf.model

Examples of com.hp.hpl.jena.rdf.model.Resource


  }
 
  public void toOWLComplexContent(Resource cls, Restrictions rest, Context ctx) {   
    schema xs = (schema) this.get_owner();
    // tally restrictions in base type
    Resource range = null;
   
    XMLBean b = get_baseType(xs.ont,ctx);   
    if (b!=null && b instanceof complexType)
      range = ((complexType) b).toOWL(rest,false,ctx);
    else { // schema datatype
      String t = expandQName(ctx.getDefaultNS(),base, xs.ont);
      if (t!=null && rest!=null && schema.isValidDatatype(t)) {
        Resource r = schema.toOWL(xs.ont, t);
        rest.addRange(RDF.value.getURI(),r);
        // complex content is single-valued
        rest.addMin(RDF.value.getURI(),1,true,xs.ont);
        rest.addMax(RDF.value.getURI(),1,xs.ont);
        schema.defineType(xs.ont.createProperty(RDF.value.getURI()),t);
View Full Code Here


  public void toOWLSimpleContent(Resource cls, Restrictions rest, Context ctx) {   
    schema xs = (schema) this.get_owner();
    // tally restrictions in base type
    XMLBean b = get_baseType(xs.ont,ctx); // extension of base type
    Resource range = null;
   
    if (b!=null && b instanceof complexType)
      range = ((complexType) b).toOWL(rest,false,ctx);
   
    // extension of simple type
    else if (b!=null && b instanceof simpleType) ;
    //return ((simpleType)b).toOWL(ctx);
    else {
      // xsd type
      String t = expandQName(ctx.getDefaultNS(),base, xs.ont);
      if (t!=null && rest!=null && schema.isValidDatatype(t)) {
        Resource r = schema.toOWL(xs.ont, t);
        rest.addRange(RDF.value.getURI(),r);
        // complex content is single-valued
        rest.addMin(RDF.value.getURI(),1,true,xs.ont);
        rest.addMax(RDF.value.getURI(),1,xs.ont);
        schema.defineType(xs.ont.createProperty(RDF.value.getURI()),t);
View Full Code Here

   */
 
  public void subClass(Resource c, schema.type type, Context ctx) {
    OntModel ont = (OntModel) c.getModel();
    Resource superclass = null;
    XMLBean b = get_baseType(ont,ctx);
   
    if (b!=null && b instanceof simpleType)
      superclass = ((simpleType) b).toOWL(ctx);
    else if (b!=null && b instanceof complexType)
      superclass = ((complexType) b).toOWL(null,true,ctx);
    else if (base != null) {
      String t = expandQName(ctx.getDefaultNS(),base, ont);
      if (t.startsWith(schema.XSD_URI)) {
        if (type==schema.type.simpleType) superclass = schema.toOWL(ont,t);
     
      // extension as superclass can only be done in a context where classes are defined by intersection
      else superclass = ont.getResource(t);
    }
   
    // this ignores xs:anyType extensions which are null
    if (superclass!=null) c.addProperty(RDFS.subClassOf,superclass);

    // is this consistent
    if (!ctx.checkConsistency(c,ont.getBaseModel())) {
      schema.removeSubClass(ont,c,superclass);
      String subject = c.getLocalName();
      if (subject==null) subject = "anonymous";
      Gloze.logger.warn(subject+" invalid subClassOf "+superclass.getLocalName());
    }
  }
View Full Code Here

      MemberType m = v.elementAt(i);
      simpleType s = m.getSimpleType();
      String t = m.getType();
      // once inside a union the member types may be anonymous
      if (s!=null) {
        Resource rs = s.toOWL(ctx);
        if (rs!=null) r.add(rs);
        else {
          Gloze.logger.warn("Can't define union : "+uri);
          return null;
        }
      }
      else {
        Resource cls = schema.toOWL(ont,t);
        // a null (e.g for a QName) means we can't define the union
        if (cls==null) {
          Gloze.logger.warn("Can't define union : "+uri);
          return null;
        }
View Full Code Here

        return cls;
      } else return RDF.List;
    }
   
    // the type may be null for embedded simpleType
    Resource first = null;
    if (type==null) {
      simpleType t = get_type(ctx);
      first = t.toOWL(ctx);
    }
    else first = schema.toOWL(ont,type);
View Full Code Here

      String t = elem.getAttributeNS(schema.XSI,"type");
      String fullname = expandQName(ctx.getDefaultNS(),t,elem,ctx.getModel());
      complexType c = ctx.getComplexType(fullname);
      if (c!=null) {
        String id = c.getID(elem,ctx);
        Resource o = id==null?m.createResource():m.createResource(addFragment(ctx.getBaseMap(), id).toString());
        stmt = m.createStatement(subject,prop,o);
        // the new resource, o, becomes the subject
       
        if (is_nillable()
         && elem.hasAttributeNS(schema.XSI,"nil")
         && elem.getAttributeNS(schema.XSI,"nil").equals("true"))
          o.addProperty(RDF.value,RDF.nil);
       
        Seq subSeq = null;
        if (ctx.isSequenced() && elem.hasChildNodes() && c.needSeq(new HashSet<String>(), ctx))
          subSeq = m.getSeq(o.addProperty(RDF.type, RDF.Seq));
 
        int index = c.toRDF(o, elem, 0, subSeq,null,true,ctx);
        // mop up remaining values in sequence
        produceMixed(subSeq, index, elem);

        m.add(stmt);
        if (seq != null) seq.add(stmt.createReifiedStatement());
        return true;
      }
      else Gloze.logger.warn("undefined type: "+fullname);
    }
    // predefined schema datatype
    String type = expandQName(ctx.getDefaultNS(),def.getType(),m);
    if (type!=null && type.startsWith(schema.XSD_URI)) {
      if (is_nillable() && elem.hasAttributeNS(schema.XSI,"nil") && elem.getAttributeNS(schema.XSI,"nil").equals("true"))
        stmt = m.createStatement(subject,prop,RDF.nil);
      else {
        if (type.equals(schema.XSD_URI+"#ID") && value!=null && !value.trim().equals("")) {
          Resource o = m.createResource(addFragment(ctx.getBaseMap(), value.trim()).toString());
          stmt = m.createStatement(subject,prop,o);
        }
        else stmt = schema.toRDFStatement(subject, elem, prop, value, type, ctx);
      }
    }

    // user defined simple type
    XMLBean t = def.get_type(ctx);
    if (t instanceof simpleType) {
      // an empty, as opposed to nil, element is null
      if (value==null) value = "";
      if (is_nillable() && elem.hasAttributeNS(schema.XSI,"nil") && elem.getAttributeNS(schema.XSI,"nil").equals("true"))
        stmt = m.createStatement(subject,prop,RDF.nil);
     
      // if a simple type is nil there is no content or attributes
      // initialise restriction set according to level of restriction checking required
      else {
        Boolean b = ((simpleType) t).toRDF(subject, prop, elem, value, seq, null, ctx);
        if (!b) Gloze.logger.warn("cannot map value "+value+" into simpleType "+type);
      }
    }
    else if (t instanceof complexType) {
      // look for a global ID
      String id = ((complexType) t).getID(elem,ctx);
      Resource o = id==null?m.createResource():m.createResource(addFragment(ctx.getBaseMap(), id).toString());
      stmt = m.createStatement(subject,prop,o);
      // the new resource, o, becomes the subject
      if (is_nillable() && elem.hasAttributeNS(schema.XSI,"nil") && elem.getAttributeNS(schema.XSI,"nil").equals("true"))
        o.addProperty(RDF.value,RDF.nil);

      Seq subSeq = null;
      if (ctx.isSequenced() && elem.hasChildNodes() && ((complexType) t).needSeq(new HashSet<String>(),ctx))
        subSeq = m.getSeq(o.addProperty(RDF.type, RDF.Seq));
     
      int index = ((complexType) t).toRDF(o, elem, 0, subSeq, null,true,ctx);
      // mop up remaining values in sequence
      produceMixed(subSeq, index, elem);
    }
View Full Code Here

          e.appendChild(doc.createTextNode(xs.toXMLValue(e, rdf, type, ctx)));
        }
        else if (type.endsWith("#duration") && !rdf.isLiteral()) {
          // sum of all durations
          Duration duration = null;
          Resource r = (Resource) rdf;
          for (StmtIterator si = r.listProperties(RDF.value); si.hasNext(); ) {
            Duration d = schema.getDuration(si.nextStatement().getString());
            duration = duration==null?d:duration.add(d);
          }
          if (duration!=null)
            e.appendChild(doc.createTextNode(duration.toString()));
View Full Code Here

   * @param doc
   */
  public static void addXMLValue(RDFNode rdf, Element e, Document doc) {
    String s = null;
    if (rdf instanceof Resource) {
      Resource r = (Resource) rdf;
      if (r.hasProperty(RDF.value))
        s = r.getProperty(RDF.value).getLiteral().getString();
    } else
      s = ((Literal) rdf).getString();
    e.appendChild(doc.createTextNode(s));
  }
View Full Code Here

   
    // include no more than cardinality restrictions for referenced elements
    if (!this.equals(def)) return;
   
    OntProperty property = null;
    Resource range = null;
    complexType ct = def.complexType;
    if (ct==null) ct = ctx.getComplexType(type);   
    if (ct!=null) {
      property = getModel().createObjectProperty(uri);     
      range = ct.toOWL(null,true, ctx);     
View Full Code Here

    Context ctx = new Context(base,xmlns,model,schemaMap,this);
   
    for (URL u: schemaMap.keySet()) schemaMap.get(u).declareGlobalNS(model,ctx);

    //  create a named or anonymous resource
    Resource rez;
    if (base != null) rez = model.createResource(base.toString());
    else rez = model.createResource();
   
    element e = ctx.getElement(element.createURI(d,ctx));
    if (e!=null) return e.toRDF(rez, d, null,ctx);
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.rdf.model.Resource

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.