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

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


  }

  /** return a reified statement as a statement */
 
  protected static Statement asStatement(Resource r) {
    Statement stmt;
    if (r==null) return null;
    try {   
      stmt = ((ReifiedStatement) r.as(ReifiedStatement.class)).getStatement();
    } catch (Exception e1) {
      Gloze.logger.warn("ill-formed reification");
View Full Code Here


  }

  protected static int produceMixed(Seq seq, int index, Element elem) {
    Document doc = elem.getOwnerDocument();
    while (seq!=null && index<seq.size()) {
      Statement stmt = (Statement) asStatement((Resource) seq.getObject(index+1));
      if (stmt.getPredicate().equals(RDF.value)) {
        elem.appendChild(doc.createTextNode(stmt.getString()));
        index++;
      } else break;
    }
    return index;
  }
View Full Code Here

  /** check validity of simple content */
 
  public boolean isValid(Resource resource, Context ctx) {
    Model model = ctx.getModel();
    Property prop = model.createProperty(createURI(model,ctx));
    Statement stmt = resource.getProperty(prop);
    String value = stmt!=null?stmt.getString():null;
    attribute def = getDefinition(model,ctx);
    XMLBean t = def.get_type(ctx);
    if (t instanceof simpleType) return ((simpleType)t).isValid(value, ctx);
    return true;
  }
View Full Code Here

  /* drop XML element sequencing and mixing */

  public int toXML(Element element, Resource rdf, int index, Set<Statement> pending, Context ctx) {
    Document doc = element.getOwnerDocument();
    Seq seq = rdf.getModel().getSeq(rdf);
    Statement stmt = null;
    boolean qualify = !namespace.equals("##local");

    int max = maxOccurs.equals("unbounded")? Integer.MAX_VALUE : Integer.parseInt(maxOccurs);  
    int occurs = 0;
    for (; occurs<max ; occurs++, index++) {
      // consume mixed values
      index = produceMixed(seq,index,element);
      if (index<seq.size()) {
        stmt = (Statement) asStatement((Resource) seq.getObject(index+1));
        if (!toXML(element, stmt.getPredicate(), stmt.getObject(), qualify, ctx)) break;
      } else break;
    }
    // do any pending properties match?
    Set<Statement> done = new HashSet<Statement>();
    for (Iterator ui = pending.iterator(); occurs<max && ui.hasNext(); ) {
      Statement s = (Statement) ui.next();
//      element.appendChild(doc.createTextNode(s.getString()));
      if (toXML(element, s.getPredicate(), s.getObject(), qualify, ctx)) done.add(s);
    }
    pending.removeAll(done);
    return index;
  }
View Full Code Here

  protected complexType extension(Set<Statement> pending, Context ctx) {
    complexType complex = null;
    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;
View Full Code Here

  private int textToXML(Element e, Resource rdf, int index, Set<Statement>pending, Context ctx) {
    Document doc = e.getOwnerDocument();
    // consume ordinal (indexed) statements
    Seq seq = rdf.getModel().getSeq(rdf);
    while (index<seq.size()) {
      Statement s = (Statement) asStatement((Resource) seq.getObject(index+1));
      if (s.getPredicate().equals(RDF.value))
        e.appendChild(doc.createTextNode(s.getLiteral().getString()));
      else return index;
      index++;
    }
    // consume non-ordinal (pending) statements
    Set<Statement> done = new HashSet<Statement>();
    for (Statement s: pending) {
      if (s.getPredicate().equals(RDF.value)) {
        e.appendChild(doc.createTextNode(s.getLiteral().getString()));
        done.add(s);
      }
    }
    pending.removeAll(done);
    return index;
View Full Code Here

            if (!seen.contains( r )) {
                seen.add( r );

                // add the statements to the output model, and queue any new resources
                for (StmtIterator i = r.listProperties(); i.hasNext(); ) {
                    Statement s = i.nextStatement();

                    // don't do the occurs check now in case of reflexive statements
                    m.add( s );

                    if (s.getObject() instanceof Resource) {
                        queue.add( s.getObject() );
                    }
                }
            }
        }
View Full Code Here

    // TODO: This should re-use the logic from ResourceDescription and ResourceProperty to decide where to create these links
    // Add links to RDF documents with descriptions of the blank nodes
    Resource r = model.getResource(controller.getAbsoluteIRI());
    StmtIterator it = r.listProperties();
    while (it.hasNext()) {
      Statement stmt = it.nextStatement();
      if (!stmt.getObject().isAnon()) continue;
      String pathDataURL = controller.getValuesDataURL(stmt.getPredicate());
      if (pathDataURL == null) continue;
      ((Resource) stmt.getResource()).addProperty(RDFS.seeAlso,
          model.createResource(pathDataURL));
    }
    it = model.listStatements(null, null, r);
    while (it.hasNext()) {
      Statement stmt = it.nextStatement();
      if (!stmt.getSubject().isAnon()) continue;
      String pathDataURL = controller.getInverseValuesDataURL(stmt.getPredicate());
      if (pathDataURL == null) continue;
      ((Resource) stmt.getSubject().as(Resource.class)).addProperty(RDFS.seeAlso,
          model.createResource(pathDataURL));
    }
  }
View Full Code Here

 
  public Set<Resource> getResources(Property p) {
    Set<Resource> result = new HashSet<Resource>();
    StmtIterator it = resource.listProperties(p);
    while (it.hasNext()) {
      Statement stmt = it.next();
      assertResourceValue(stmt);
      result.add(stmt.getResource());
    }
    return result;
  }
View Full Code Here

 
  public Set<String> getIRIs(Property p) {
    Set<String> result = new HashSet<String>();
    StmtIterator it = resource.listProperties(p);
    while (it.hasNext()) {
      Statement stmt = it.next();
      assertIRIValue(stmt);
      result.add(stmt.getResource().getURI());
    }
    return result;
  }
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.