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

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


  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


  {
    Resource subj = getSubject(LdapMap.property, config
        .asRDFNode(predicate));
    if (subj == null)
      return null;
    Statement s = subj.getProperty(RDF.type);
    if (s == null)
      return null;
    return s.getResource();
  }
View Full Code Here

   
    si.close();
    si = configModel.listStatements(null, DbMap.foreignKey, (RDFNode) null);
    while (si.hasNext())
    {
      Statement s = si.nextStatement();
      Col subj = prop2col.get(s.getSubject());
      Col obj = prop2col.get(s.getObject());
      if (subj == null || obj == null)
        log.warn("Foreign key missed: " + s);
      subj.setForeignKey(obj);
    }
  }
View Full Code Here

        Model model = SDBFactory.connectDefaultModel(store) ;
       
        StmtIterator sIter = model.listStatements() ;
        for ( ; sIter.hasNext() ; )
        {
            Statement stmt = sIter.nextStatement() ;
            System.out.println(stmt) ;
        }
        sIter.close() ;
        store.close() ;
    }
View Full Code Here

  }

  public static boolean noSchemaToRDF(Resource subject, Element elem, Seq seq, Context ctx)
  throws Exception {
    Model m = subject.getModel();
    Statement stmt = null;
   
    String uri = expandQName(elem, ctx.getModel(), ctx);
    Property prop = m.createProperty(uri);

    // anything with no attributes and a single (or no) value is simple
    // anything with attributes is complex
    // anything with children is complex
   
    String simple = getSimpleContent(elem);
    if (elem.hasAttributes() || simple==null) {
      // looks like a complex type
     
      Resource obj = null;
      if (elem.hasAttributeNS(XML,"id")) {
        String id = elem.getAttributeNS(XML,"id");
        obj = m.createResource(addFragment(ctx.getBaseMap(), id).toString());
      }
      else obj = m.createResource();
     
      // explicit xsi:type
      if (elem.hasAttributeNS(schema.XSI,"type")) {
        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
                   
          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);
          return true;
        }
        else Gloze.logger.warn("undefined type: "+fullname);
      }
     
      stmt = m.createStatement(subject,prop,obj);     
      m.add(stmt);
      if (seq != null) seq.add(stmt.createReifiedStatement());     

      // we can't confuse a (single) simple rdf:value with an attribute
      Seq s = null;
      // Added extra condition - we should be able to turn off sequencing, risking confusion between attributes and object properties
      if (simple==null && ctx.isSequenced()) s = m.getSeq(obj.addProperty(RDF.type, RDF.Seq));

      // add attributes (and possibly define xmlns)
      NamedNodeMap nm = elem.getAttributes();
      for (int i=0; i<nm.getLength(); i++)
        noSchemaToRDF(obj, (Attr) nm.item(i),ctx);

      // add elements
      NodeList nl = elem.getChildNodes();
      for (int i=0; i<nl.getLength(); i++) {
        switch (nl.item(i).getNodeType()) {
        case Node.ELEMENT_NODE:
          Element e = (Element) nl.item(i);
          noSchemaToRDF(obj,e,s,ctx);
          break;
        case Node.TEXT_NODE:
          String value = ((Text) nl.item(i)).getNodeValue().trim();
          Literal lit = null;
          if (elem.hasAttributeNS(XML,"lang"))
            lit = m.createLiteral(value, elem.getAttributeNS(XML,"lang"));
          else
            lit = ctx.getModel().createLiteral(value);
         
          stmt = ctx.getModel().createStatement(obj,RDF.value,lit);
          if (!value.equals("")) {
            ctx.getModel().add(stmt);
            if (s!=null) s.add(stmt.createReifiedStatement());
          }
        }
      }
      return true;
    }
    else { // looks like a simple type
      String value = XMLBean.getValue(elem);
      if (value!=null && ctx.isPreserved()) value = value.trim();
      if (value==null) value = "";
     
      Literal l =  m.createLiteral(value);
      stmt = m.createStatement(subject,prop,l);     
      m.add(stmt);
      if (seq != null && stmt!=null) seq.add(stmt.createReifiedStatement());     
      return true;
    }
  }
View Full Code Here

  public static boolean noSchemaToXML(Document doc, RDFNode rdf, Context ctx) {
    boolean qualify = ctx.getDefaultNS()!=null;
    if (rdf instanceof Resource) {
      Resource r = (Resource) rdf;
      for (StmtIterator i = r.listProperties(); i.hasNext(); ) {
        Statement stmt = i.nextStatement();
        Property p = stmt.getPredicate();
        // ignore RDF properties eg. RDF:type
        // take the first (non-rdf) property we find as document element
        if (!p.getURI().startsWith(RDF.getURI())) {
          Element e = noSchemaToElement(doc,p,ctx);
          doc.appendChild(e);
          noSchemaToXML(e,stmt.getObject(),qualify,ctx);
          return true;
        }
      }
    }
    return false;
View Full Code Here

      }     

      // add (sequenced) sub-elements
      NodeIterator ni = ctx.getModel().getSeq(r).iterator();
      while (ni.hasNext()) {
        Statement stmt = element.asStatement((Resource) ni.nextNode());
        if (stmt.getPredicate().equals(RDF.value)) {
          // add literal value
          RDFNode value = stmt.getObject();
          if (value.isLiteral())
            elem.appendChild(doc.createTextNode(value.toString()))
        }
        else {
          Element e = noSchemaToElement(elem,stmt.getPredicate(),ctx);
          if (e!=null) {
            elem.appendChild(e);
            noSchemaToXML(e,stmt.getObject(),qualify,ctx);
         
        }
      }

      // add (unsequenced) properties
      Set pending = element.unsequenced((Resource) rdf);
      for (Iterator ui = pending.iterator(); ui.hasNext(); ) {
        Statement stmt = (Statement) ui.next();
        if (stmt.getPredicate().equals(RDF.value)) {
          RDFNode n = stmt.getObject();
          if (n.isLiteral()) {
            Literal l = (Literal) n;
            elem.appendChild(doc.createTextNode(l.getString()))
            if (l.getLanguage()!=null) elem.setAttributeNS(XML,"lang",l.getLanguage());
          }
        }
        else if (stmt.getPredicate().getNameSpace().equals(RDF.getURI())) ;
        else {
          Attr a = noSchemaToAttribute(doc,stmt.getPredicate(), ctx);
          elem.setAttributeNode(a);
          noSchemaToXML(a,stmt.getObject(),ctx);
         
        }
      }
      // if the resource has a URI this is the node ID
      if (!r.isAnon()) {
View Full Code Here

  }

  public boolean toXML(Document doc, Resource rez) throws Exception {
    StmtIterator i = rez.listProperties();
    while (i.hasNext()) {
      Statement s = i.nextStatement();
      Property p = s.getPredicate();
      element e = getElement(p.getURI());
      if (e!=null && e.toXML(doc, s.getObject(),this)) return true;   
    }
    return false;
  }
View Full Code Here

    }
  }
 
  private void mergeDescription(Resource ir, Resource r, boolean flagOK, Map<RDFNode,RDFNode> visited) {
    for (StmtIterator si = r.listProperties(); si.hasNext(); ) {
      Statement stmt = si.nextStatement();
      Property p = stmt.getPredicate();
      RDFNode o = stmt.getObject();
     
      if (flagOK && r.hasProperty(RDF.type, OWL.Class))
        ir.addProperty(RDF.type, infModel.getResource(Gloze.OK));
     
      if (o.isLiteral())
View Full Code Here

 
  protected static Set<Statement> unsequenced(Resource rdf) {
    Set<Statement> s = new HashSet<Statement>();
    StmtIterator si = rdf.listProperties();
    while (si.hasNext()) {
      Statement stmt = si.nextStatement();
      // don't add ordinals
      if (stmt.getPredicate().getOrdinal()==0) s.add(stmt);
    }
    NodeIterator ni = rdf.getModel().getSeq(rdf).iterator();
    while (ni.hasNext()) {
      Statement stmt = asStatement((Resource) ni.nextNode());
      if (s.contains(stmt)) s.remove(stmt);
    }
    return s;
  }
View Full Code Here

TOP

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

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.