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

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


    }
   
    private static Model makeData()
    {
        Model model = ModelFactory.createDefaultModel() ;
        Resource r = model.createResource(NS+"r") ;
        Property p1 = model.createProperty(NS+"p1") ;
        Property p2 = model.createProperty(NS+"p2") ;
        model.add(r, p1, "xyz") ;
        model.add(r, p2, "abc") ;
        return model ;
View Full Code Here


    Statement stmt = null;
    if (type.endsWith("#ID")) ;
    // ID is used to name the owning element - don't generate RDF
    // IDREF to globally named element
    else if (type.endsWith("#IDREF")) {
      Resource r = m.createResource(addFragment(ctx.getBaseMap(), value).toString());
      stmt = m.createStatement(subject,prop,r);
    }
    else if (type.endsWith("#IDREFS")) {
      Resource r = toRDFList(elem,value,XSD.IDREF.getURI(),null,ctx)
      stmt = m.createStatement(subject,prop,r);
    }
    else if (type.endsWith("#NMTOKENS")) {
      Resource r = toRDFList(elem,value,XSD.NMTOKEN.getURI(),null,ctx)
      stmt = m.createStatement(subject,prop,r);
    }
    else if (type.endsWith("#QName")) {
      RDFNode object = null;
      String name = XMLBean.expandQName(ctx.getDefaultNS(),null,value,elem,ctx.getModel());
      if (name!=null) {
        object = m.createResource(name);
        stmt = m.createStatement(subject,prop,object);
      }
    }
    else if (type.endsWith("#duration")) {
      // map duration into separate xs:yearMonthDuration and xs:dayTimeDuration
      // introduce intermediate bnode
      Resource object = m.createResource();
      stmt = m.createStatement(subject,prop,object);
      RDFNode ym = schema.yearMonthDuration(m,value);
      RDFNode dt = schema.dayTimeDuration(m,value);
      if (ym!=null) object.addProperty(RDF.value, ym);
      if (dt!=null) object.addProperty(RDF.value, dt);
    }
    else if (type.endsWith("#ENTITY")) {
      DocumentType doctype = elem.getOwnerDocument().getDoctype();
      Pattern entityPattern = Pattern.compile("<!ENTITY\\s+"+value+"\\s+'(.*)'>");
      Matcher match = entityPattern.matcher(doctype.getInternalSubset());
View Full Code Here

  }

  public String toXMLValue(Element elem, RDFNode rdf, String type, Context ctx) {
    String v = null;
    if (rdf instanceof Resource) {
      Resource r = (Resource) rdf;
     
      if (type!=null && (type.equals(XSD_URI+"#QName") || type.equals(XSD_URI+"#NOTATION")) && !r.isAnon())
        v = r.getURI();
      else if (type!=null && type.equals(XSD_URI+"#ID") && !r.isAnon())
        v = r.getLocalName();
      else if (type!=null && type.equals(XSD.IDREF.getURI()) && !r.isAnon()
          && XMLBean.equalNS(r.getNameSpace(),ctx.getBaseMap().toString()))
        v = r.getLocalName();
      else if (type!=null && type.equals(XSD_URI+"#IDREFS")) {
        v = listToString(r,elem,XSD.IDREF.getURI(),ctx);
      }
      else if (type!=null && type.equals(XSD_URI+"#NMTOKENS")) {
        v = listToString(r,elem,XSD.NMTOKEN.getURI(),ctx);
      }
      else if (r.hasProperty(RDF.value)) {
        Statement stmt = r.getProperty(RDF.value);
        if (type!=null && type.equals(XSD_URI+"#IDREF"))
          v = stmt.getResource().getLocalName();
        else if (stmt.getObject() instanceof Literal) v = stmt.getString();   
      }     
      else if (r.canAs(RDFList.class)) {
        v = listToString(r,elem,null,ctx);
      }
    }
    else if (rdf instanceof Literal) {
      v = ((Literal) rdf).getString();
View Full Code Here

    // removing orphans may create orphans
    while (b) {
      b = false;
      // orphaned classes
      for (ResIterator classes = ont.listSubjectsWithProperty(RDF.type,type); classes.hasNext(); ) {
        Resource c = classes.nextResource();
        if (c.isAnon()) {
          // an orphan is anonymous and has no referee other than itself
          Resource r = null;
          Statement s = null;
          for (StmtIterator si = ont.listStatements(null,null,c); si.hasNext(); ) {
            s = si.nextStatement();
            r = s.getSubject();
            if (!r.equals(c)) break;
          }         
          if (r==null || r.equals(c)) {
            b = true;
            c.removeProperties();
          }
        }
      }
View Full Code Here

  public static void cleanup(Resource type) {
    if (type!=null && !type.isAnon() && type.getURI().startsWith(RDFS.getURI())) return;
    Set<Resource> remove = new HashSet<Resource>();
    for (StmtIterator i = type.listProperties(RDFS.subClassOf); i.hasNext();) {
      Resource r = i.nextStatement().getResource();
      if (r.isAnon()) remove.add(r);
    }     
    for (Resource r: remove) r.removeProperties();
  }
View Full Code Here

  }
 
  public static boolean isID(Resource type) {
    if (!type.isAnon()) return type.getURI().equals(schema.ID);
    for (StmtIterator i = type.listProperties(RDFS.subClassOf); i.hasNext();) {
      Resource r = i.nextStatement().getResource();
      if (!type.equals(r) && isID(r)) return true;
    }
    return false
  }
View Full Code Here

    return false
  }
 
  public static Resource toList(OntModel ont, String type, String itemType) {
    OntClass c = ont.createClass(type);
    Resource i = ont.getResource(itemType);
    c.addSuperClass(RDF.List);     
    c.addSuperClass(ont.createAllValuesFromRestriction(null,RDF.first,i));
    c.addSuperClass(ont.createAllValuesFromRestriction(null,RDF.rest,c));
    return c;   
  }
View Full Code Here

    return xs.toRDF(node,subject,prop,value,null,seq,restrictions,ctx);
  }

  public boolean toXML(Element e, RDFNode rdf, Set<Statement> pending, Context ctx) {
    if (rdf instanceof Resource) {
      Resource r = ((Resource)rdf);
      // add simple content encoded as rdf:value
      Statement s = r.getProperty(RDF.value);
      if (extension!=null) extension.toXML(e,r,pending,ctx);
      else if (restriction!=null) restriction.toXML(e,r,pending,ctx);
      else if (s!=null && s.getObject() instanceof Literal) {
        Literal l = (Literal) s.getObject();
        e.appendChild(e.getOwnerDocument().createTextNode(l.getString()));
View Full Code Here

    model.setNsPrefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
    model.setNsPrefix("owl", "http://www.w3.org/2002/07/owl");
    model.setNsPrefix("db", DbMap.NS);
    model.setNsPrefix("ex", namespace);

    Resource map = model.createResource(namespace + "map");

    map.addProperty(RDF.type, DbMap.Map);

    Resource serverR = model.createResource(server);
    serverR.addProperty(RDF.type, DbMap.Database);
    serverR.addProperty(DbMap.user, user);
    serverR.addProperty(DbMap.pass, pass);
    serverR.addProperty(DbMap.driver, driver);

    ResultSet rs = null;
    if (tables != null) {
      for (int i = 0; i < tables.length; i++)
      {
View Full Code Here

    String ex = model.getNsPrefixURI("ex");

    while (rs.next()) {
      String tableName = rs.getString("TABLE_NAME");
      Resource tableRes = model
          .createResource(ex + tableName, RDFS.Class);
      map.addProperty(DbMap.mapsClass, tableRes);
      tableRes.addProperty(DbMap.database, serverR);
      tableRes.addProperty(DbMap.table, tableName);

      ResultSet cols = md.getColumns(null, null, tableName, null);
      while (cols.next()) {
        String colName = cols.getString("COLUMN_NAME");
        String type = cols.getString("TYPE_NAME");
        Resource col = model.createResource(ex + tableName + "_"
            + colName, RDF.Property);
        col.addProperty(RDFS.domain, tableRes);
        col.addProperty(DbMap.col, colName);
        col.addProperty(DbMap.colType, type);
      }
      cols.close();
     
      ResultSet forkeys = md.getExportedKeys(null, null, tableName);
      while (forkeys.next()) {
        String colName = forkeys.getString("PKCOLUMN_NAME");
        String fColName = forkeys.getString("FKCOLUMN_NAME");
        String fTableName = forkeys.getString("FKTABLE_NAME");
        Resource col = model.createResource(ex + tableName + "_"
            + colName, RDF.Property);
        Resource fcol = model.createResource(ex + fTableName + "_"
            + fColName, RDF.Property);
        col.addProperty(DbMap.foreignKey, fcol);
      }
      forkeys.close();
           
      ResultSet rowIdentifiers = md.getPrimaryKeys(null, null, tableName);
      while (rowIdentifiers.next())
      {
        String colName = rowIdentifiers.getString("COLUMN_NAME");
        Resource col = model.createResource(ex + tableName + "_"
            + colName, RDF.Property);
        tableRes.addProperty(DbMap.primaryKey, col);
      }
    }
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.