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

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


 
  public Set<String> getStrings(Property p) {
    Set<String> result = new HashSet<String>();
    StmtIterator it = resource.listProperties(p);
    while (it.hasNext()) {
      Statement stmt = it.next();
      assertString(stmt);
      result.add(stmt.getString());
    }
    return result;
  }
View Full Code Here


      String uri = original.getNsPrefixURI(prefix);
      result.setNsPrefix(prefix, rewrite(uri));
    }
    StmtIterator it = original.listStatements();
    while (it.hasNext()) {
      Statement stmt = it.nextStatement();
      Resource s = stmt.getSubject();
      if (s.isURIResource()) {
        s = result.createResource(rewrite(s.getURI()));
      }
      Property p = result.createProperty(
          rewrite(stmt.getPredicate().getURI()));
      RDFNode o = stmt.getObject();
      if (o.isURIResource()) {
        o = result.createResource(rewrite(o.asResource().getURI()));
      }
      result.add(s, p, o);
    }
View Full Code Here

 
  public void addCustomMetadata(Model document, Resource documentResource) {
    if (customTemplate == null) return;
    StmtIterator it = customTemplate.listProperties();
    while (it.hasNext()) {
      Statement stmt = it.nextStatement();
      document.add(documentResource, stmt.getPredicate(), stmt.getObject());
    }
    it = customTemplate.getModel().listStatements(null, null, customTemplate);
    while (it.hasNext()) {
      Statement stmt = it.nextStatement();
      if (stmt.getPredicate().equals(CONF.rdfDocumentMetadata)) {
        continue;
      }
      document.add(stmt.getSubject(), stmt.getPredicate(), documentResource);
    }
  }
View Full Code Here

    // iterate over template statements to replace placeholders
    Model metadata = ModelFactory.createDefaultModel();
    currentDocRepr = metadata.createResource();
    StmtIterator it = tplModel.listStatements();
    while (it.hasNext()) {
      Statement stmt = it.nextStatement();
      Resource subj = stmt.getSubject();
      Property pred = stmt.getPredicate();
      RDFNode  obj  = stmt.getObject();
     
      try {
        if (subj.toString().contains(metadataPlaceholderURIPrefix)){
          subj = (Resource) parsePlaceholder(subj, controller, currentTime, currentDocRepr);
          if (subj == null) {
            // create a unique blank node with a fixed id.
            subj = getModel().createResource(new AnonId(String.valueOf(stmt.getSubject().hashCode())));
          }
        }
       
        if (obj.toString().contains(metadataPlaceholderURIPrefix)){
          obj = parsePlaceholder(obj, controller, currentTime, currentDocRepr);
        }
       
        // only add statements with some objects
        if (obj != null) {
          stmt = metadata.createStatement(subj,pred,obj);
          metadata.add(stmt);
        }
      } catch (Exception e) {
        // something went wrong, oops - lets better remove the offending statement
        metadata.remove(stmt);
        e.printStackTrace();
      }
    }
   
    // remove blank nodes that don't have any properties
    boolean changes = true;
    while ( changes ) {
      changes = false;
      StmtIterator stmtIt = metadata.listStatements();
      List<Statement> remList = new ArrayList<Statement>();
      while (stmtIt.hasNext()) {
        Statement s = stmtIt.nextStatement();
        if (    s.getObject().isAnon()
             && ! ((Resource) s.getObject().as(Resource.class)).listProperties().hasNext() ) {
          remList.add(s);
          changes = true;
        }
      }
      metadata.remove(remList);
View Full Code Here

      if (dataset.hasProperty(p))
        return dataset.getProperty(p).getObject();
     
      // find pointer to the global configuration set...
      StmtIterator it = dataset.getModel().listStatements(null, CONF.dataset, dataset);
      Statement ptrStmt = it.nextStatement();
      if (ptrStmt == null) return null;
     
      // look in global config if nothing found so far
      Resource globalConfig = ptrStmt.getSubject();
      if (globalConfig.hasProperty(p))
        return globalConfig.getProperty(p).getObject();
    }
   
    // <about:metadata:metadata:*> - The metadata provided by users
    if (phPackage.equals("metadata")) {
      // look for requested property in the dataset config
      Property p  = getModel().createProperty(META.NS + phName);
      if (dataset.hasProperty(p))
        return dataset.getProperty(p).getObject();
     
      // find pointer to the global configuration set...
      StmtIterator it = dataset.getModel().listStatements(null, CONF.dataset, dataset);
      Statement ptrStmt = it.nextStatement();
      if (ptrStmt == null) return null;
     
      // look in global config if nothing found so far
      Resource globalConfig = ptrStmt.getSubject();
      if (globalConfig.hasProperty(p))
        return globalConfig.getProperty(p).getObject();
    }

    return getModel().createResource(new AnonId(String.valueOf(phRes.hashCode())));
View Full Code Here

  private List<ResourceProperty> buildProperties() {
    Map<String,PropertyBuilder> propertyBuilders =
        new HashMap<String,PropertyBuilder>();
    StmtIterator it = resource.listProperties();
    while (it.hasNext()) {
      Statement stmt = it.nextStatement();
      if (isEmptyLiteral(stmt.getObject())) continue;
      Property predicate = stmt.getPredicate();
      String key = "=>" + predicate;
      if (!propertyBuilders.containsKey(key)) {
        propertyBuilders.put(key, new PropertyBuilder(
            predicate, false, config.getVocabularyStore()));
      }
      // TODO: Should distinguish clearly here between adding a
      //       simple value, adding a complex (inlined) value, and
      //       omitting a value. But how to decide whether blank nodes
      //       are omitted or included as complex value? The decision has
      //       already been made earlier when the model was built.
      propertyBuilders.get(key).addValue(stmt.getObject());
    }
    it = model.listStatements(null, null, resource);
    while (it.hasNext()) {
      Statement stmt = it.nextStatement();
      Property predicate = stmt.getPredicate();
      String key = "<=" + predicate;
      if (!propertyBuilders.containsKey(key)) {
        propertyBuilders.put(key, new PropertyBuilder(
            predicate, true, config.getVocabularyStore()));
      }
      // TODO: See TODO above
      propertyBuilders.get(key).addValue(stmt.getSubject());
    }
    for (Property p: highIndegreeProperties.keySet()) {
      String key = "<=" + p;
      if (!propertyBuilders.containsKey(key)) {
        propertyBuilders.put(key, new PropertyBuilder(
View Full Code Here

    // new statements to be added:
    List<Statement> n_stmts = new ArrayList<Statement>();
   
    StmtIterator existingStmts = model.listStatements();
    while ( existingStmts.hasNext() ) {
      Statement o_stmt = existingStmts.nextStatement();
      Resource sbj = o_stmt.getSubject();
      Property prd = o_stmt.getPredicate();
      RDFNode obj = o_stmt.getObject();
     
      boolean any_change = false;
      Resource n_sbj = sbj;
      Property n_prd = prd;
      RDFNode  n_obj = obj;

//      if ( oldNameSpace.equals(sbj.getNameSpace()) ) {
      if ( _inNamespace(sbj, oldNameSpace) ) {
        n_sbj = model.createResource(newNameSpace + sbj.getLocalName());
        any_change = true;
      }
//      if ( oldNameSpace.equals(prd.getNameSpace()) ) {
      if ( _inNamespace(prd, oldNameSpace) ) {
        n_prd = model.createProperty(newNameSpace + prd.getLocalName());
        any_change = true;
      }
      if ( (obj instanceof Resource) ) {
        Resource objr = (Resource) obj;
//        if ( oldNameSpace.equals(objr.getNameSpace()) ) {
        if ( _inNamespace(objr, oldNameSpace) ) {
          n_obj = model.createResource(newNameSpace + objr.getLocalName());
          any_change = true;
        }
      }

      if ( any_change ) {
        o_stmts.add(o_stmt);
        Statement n_stmt = model.createStatement(n_sbj, n_prd, n_obj);
        n_stmts.add(n_stmt);
        //log.debug(" #### " +o_stmt);
      }
    }
   
View Full Code Here

   */
  public void newGraph(String graphUri) {
    synchronized (this) {
      Model model = _getGraphsModel();
      Resource subGraphRes = ResourceFactory.createResource(graphUri);
      Statement stmt = ResourceFactory.createStatement(subGraphRes, RDF.type, Rdfg.Graph);
      model.add(stmt);
      log.debug("newGraph: added statement: " +stmt);
      try {
        _updateGraphsFile(model);
      }
View Full Code Here

    if ( ontRes != null ) {
      prexistStatements = new ArrayList<Statement>();
//      log.info("Getting pre-existing properties for OWL.Ontology individual: " +ontRes.getURI());
      StmtIterator iter = ontRes.listProperties();
      while ( iter.hasNext() ) {
        Statement st = iter.nextStatement();
        prexistStatements.add(st);
     
    }

   
    // The new OntModel that will contain the pre-existing attributes (if any),
    // plus the new and updated attributes:
    final OntModel newOntModel = ModelFactory.createOntologyModel(model.getSpecification(), model);
    // Note: previously, newOntModel = new OwlModel(model); but the OwlModel extension was not used
    // in any particular way, so the new call should be equivalent.
    final Ontology ont_ = newOntModel.createOntology(base_);
    if ( log.isDebugEnabled() ) {
      log.debug("New ontology created with namespace " + ns_ + " base " + base_);
    }
    newOntModel.setNsPrefix("", ns_);
   
   
    //////////////////////////////////////////////////////////////////////////
    // set new values for the unversioned version:
    Map<String, String> newValues = new HashMap<String, String>();
   
    // Set internal attributes, which are updated in the newValues map itself
    // so we facilite the processing below:
    newValues.put(Omv.uri.getURI(), base_);
    if ( version != null ) {
      newValues.put(Omv.version.getURI(), version);
    }
   
    newValues.put(Omv.creationDate.getURI(), creationDate);


    //////////////////////////////////////////////////
    // transfer any preexisting attributes, and then remove all properties from
    // pre-existing ontRes so just the new OntModel gets added.
    if ( ontRes != null ) {
      for ( Statement st : prexistStatements ) {
        Property prd = st.getPredicate();

        //
        // Do not tranfer pre-existing/pre-assigned-above attributes
        //
        String newValue = newValues.get(prd.getURI());
        if ( newValue == null || newValue.trim().length() == 0 ) {
          // not assigned above.
         
          if ( ALTERATE_ANNOTATIONS ) {
            // See if it's one of the ones to be modified:
            if ( Omv.description.getURI().equals(prd.getURI()) ) {
              // transfer modified description:
              String description =
                "An unversioned ontology containing the latest terms as of the request time, " +
                "for the ontology containing: " +st.getObject();
//              log.info("  Transferring modified description: " +st.getSubject()+ " :: " +prd+ " :: " +description);
              newOntModel.add(ont_, st.getPredicate(), description);
            }
            else if ( Omv.name.getURI().equals(prd.getURI()) ) {
              // transfer modified title:
              String title =
                "Unversioned form of: " +st.getObject();
//              log.info("  Transferring modified title: " +st.getSubject()+ " :: " +prd+ " :: " +title);
              newOntModel.add(ont_, st.getPredicate(), title);
            }
            else {
              // transfer as it comes:
//              log.info("  Transferring: " +st.getSubject()+ " :: " +prd+ " :: " +st.getObject());
              newOntModel.add(ont_, st.getPredicate(), st.getObject());
            }
          }
          else {
            // just transfer as it comes:
//            log.info("  Transferring: " +st.getSubject()+ " :: " +prd+ " :: " +st.getObject());
            newOntModel.add(ont_, st.getPredicate(), st.getObject());
          }
        }
        else {
//          log.info(" Not Transferring: " +prd+ " from previous version because new value " +newValue);
        }
View Full Code Here

    List<Statement> n_stmts = new ArrayList<Statement>();
   
    // check all statements in the model:
    StmtIterator existingStmts = model.listStatements();
    while ( existingStmts.hasNext() ) {
      Statement o_stmt = existingStmts.nextStatement();
      Resource sbj = o_stmt.getSubject();
      Property prd = o_stmt.getPredicate();
      RDFNode obj = o_stmt.getObject();
     
      // will indicate that o_stmt is affected by the namespace change:
      boolean any_change = false;
     
      // the new triplet, initialized with the existing statement:
      Resource n_sbj = sbj;
      Property n_prd = prd;
      RDFNode  n_obj = obj;

      if ( oldNameSpace.equals(sbj.getNameSpace()) ) {
        // the subject is affected; create new subject
        n_sbj = model.createResource(newNameSpace + sbj.getLocalName());
        any_change = true;
      }
      if ( oldNameSpace.equals(prd.getNameSpace()) ) {
        // the predicate  is affected; create new predicate
        n_prd = model.createProperty(newNameSpace + prd.getLocalName());
        any_change = true;
      }
      if ( (obj instanceof Resource) && oldNameSpace.equals(((Resource) obj).getNameSpace()) ) {
        // the object is affected; create new object
        n_obj = model.createResource(newNameSpace + ((Resource) obj).getLocalName());
        any_change = true;
      }

      if ( any_change ) {
        // create the new statment:
        Statement n_stmt = model.createStatement(n_sbj, n_prd, n_obj);
        // and update the lists for final adjustments below:
        o_stmts.add(o_stmt);
        n_stmts.add(n_stmt);
      }
    }
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.