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

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


     
      else if (o.isAnon() && visited.containsKey(o))
        ir.addProperty(p,visited.get(o));

      else { // recursively merge anonymous objects
        Resource a = infModel.createResource();
        visited.put(o,a);
        ir.addProperty(p,a);
        mergeDescription(a, (Resource)o, false, visited);
      }
    }
View Full Code Here


  public Resource toOWL(Context ctx) {
    schema xs = (schema) this.get_owner();
    String uri = createURI(xs.ont,ctx);
   
    // have we seen this type before
    Resource cls = ctx.getOntClass(uri) ;
    if (cls!=null) return cls; 

    // delegate creation of the class to the children
    if (restriction!=null) cls = restriction.toOWLSimpleType(uri, ctx);
    else if (_list!=null) cls = _list.toOWL(xs.ont, uri, true, ctx);
View Full Code Here

    if (t!=null && t.startsWith(schema.XSD_URI)) {
      // ID is used to name the owning element - don't generate RDF property
      if (t.endsWith("#ID")) return;
      // IDREF to globally named element
      else if (t.endsWith("#IDREF")) {
        Resource rez = model.createResource(addFragment(ctx.getBaseMap(), value).toString());
        subject.addProperty(prop, rez);
      }
      // IDREFS to global entities
      else if (t.endsWith("#IDREFS"))
        subject.addProperty(prop, schema.toRDFList(attribute,value,XSD.IDREF.getURI(),null,ctx));
View Full Code Here

    // include no more than cardinality restrictions for referenced attributes
    if (!this.equals(def)) return;

    OntProperty property = xs.ont.createOntProperty(uri);

    Resource range = null;
    simpleType s = def.simpleType;
    if (s==null) s = ctx.getSimpleType(type);
    if (s!=null) {
      s.defineType(property,ctx);
      range = s.toOWL(ctx);
    }
    else {
      // default attribute type
      if (type==null) type = schema.anySimpleType;
      schema.defineType(property,type);
      range = schema.toOWL(xs.ont,type);
     
      // ecore extensions
      if (ecore!=null) ecore.toOWL(getModel(), uri, rest, get_node(), type, ctx);
    }
   
    // remove all evidence of an ID attribute
    if (range!=null && schema.isID(range)) property.remove();
   
    // Don't bother to add a range restriction only for it to be cleaned up afterwards (noRest)
    if (range!=null && rest!=null && !noRest && !schema.isID(range))
      rest.addRange(uri, range);
   
    // global attribute closure
    if (property.getRange()==null && ctx.isGlobalAttribute(def)
        && ctx.isClosed() && range!=null && !schema.ID.equals(range.getURI())) {
      property.setRange(range);
    }
   
    if (noRest) rest.cleanup(xs.ont,uri);
   
View Full Code Here

 
  /** remove ID property restrictions (xs:ID is mapped to the resource URI) */
 
  boolean removeID(OntModel ont, Set<Resource> range) {
    boolean removed = false;
    Resource id = ont.getResource(schema.ID);
    if (range.contains(id)) removed = range.remove(id);
    for (Resource r: range) {
      if (schema.isID(r)) {
        schema.cleanup(r);
        removed = range.remove(r);
View Full Code Here

      if (s.isEmpty()) removeRange.add(key);
    }
    for (String key: removeRange) range.remove(key);
    for (String key: removeProps) {
      // we can delete the property if it's not being used elsewhere
      Resource r = ont.getResource(key);
      ResIterator i1 = ont.listSubjectsWithProperty(OWL.onProperty,r);
      ResIterator i2 = ont.listSubjectsWithProperty(RDFS.subPropertyOf,r);
      // r should not be used in an existing restriction or subPropertyOf relation
      // ignore case where r is a subPropertyOf itself
      Resource s = null;
      while (i2.hasNext() && (s==null || s.equals(r)))
        s = i2.nextResource();
      if (!i1.hasNext() && (s==null || s.equals(r)))
        r.removeProperties();
    }
  }
View Full Code Here

    Model m = ctx.getModel();
    Set<Statement> done = new HashSet<Statement>();
    done: for (Iterator i = pending.iterator(); i.hasNext(); ) {
      Statement stmt = (Statement) i.next();
      if (stmt.getPredicate().equals(RDF.type)) {
        Resource type = (Resource) stmt.getObject();
        // ignore RDF types, e.g. rdf:Seq, or URI of this type
        if (type.getURI().startsWith(RDF.getURI())
         || type.getURI().equals(createURI(m,ctx))) {
          done.add(stmt);
          continue;
        }
        complexType c = ctx.getComplexType(type.getURI());
        // map direct ONLY descendents of thisclass to XML
        if (c!=null && c.subtype(createURI(m,ctx), m,ctx)) {
          done.add(stmt);
          complex = c;
          break done;
View Full Code Here

  public Resource toOWL(Restrictions rest, boolean createAnon, Context ctx) {
    schema xs = (schema) this.get_owner();
    String uri = createURI(xs.ont,ctx);

    // create class if this is the first time we've seen it
    Resource c = ctx.getOntClass(uri), cls = c ;
    if (c==null) {
      if (uri!=null) ctx.putOntClass(uri, cls = xs.ont.createClass(uri));
    }
    else if (rest==null) return c;
    if (cls==null) cls = xs.ont.createClass(uri);
View Full Code Here

      OntModel ont = rest.getModel(key);
      OntProperty p = ont.getOntProperty(key);
      Set<Resource> s = rest.getRange().get(key);

      if (s.size()==1) {
        Resource t = s.iterator().next();
       
        if (t!=null && ont!=xs.ont) t = copyResource(t);
        // is the range implied by the global property
        if (t!=null && (p.getRange()==null || !p.getRange().equals(t)))
          restrictions.add(xs.ont.createAllValuesFromRestriction(null,p,t));         
View Full Code Here

 
  // copy anonymous resources from different ontology
  Resource copyResource(Resource rez) {
    schema xs = (schema) this.get_owner();
    if (rez.isAnon()) {
      Resource r = xs.ont.createResource();
      for (StmtIterator si = rez.listProperties(); si.hasNext(); ) {
        Statement s = si.nextStatement();
        if (s.getObject().equals(rez)) continue;
        if (s.getObject().equals(RDFS.Resource)) continue;
        if (s.getObject().equals(RDFS.Class)) continue;
        else if (s.getObject().isLiteral())
          r.addProperty(s.getPredicate(),s.getLiteral());
        else
          r.addProperty(s.getPredicate(), copyResource(s.getResource()));
      }
      return r;
    }
    else return rez;
  }
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.