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

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


    metric.setResource(resource);
    addResourceInstanceToCache(resource, metric);
    // identifier //
    Property identifier = ResourceFactory.createProperty(
        riNamespace + "identifier");   
    StmtIterator stmtI1 = model.listStatements(resource,
        identifier, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      // validate identificator property //
      if(!statement.getObject().isLiteral()) {         
        if(!ModelException.throwException(ModelException.METRIC,
            "identificator property of Metric resource:"+
            resource.getURI()+" is not a literal")) {
          return null;
        }
      } else {
        metric.setIdentifier(statement.getObject().asLiteral().getString());
      }
    }
    Property description = ResourceFactory.createProperty(
        dcNamespace + "description");
    // description //
    stmtI1 = model.listStatements(resource,
        description, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      // validate description property //
      if(!statement.getObject().isLiteral()) {         
        if(!ModelException.throwException(ModelException.METRIC,
            "description property of Metric resource:"+
            resource.getURI()+" is not a literal")) {
          return null;
        }
      } else {
        metric.setDescription(statement.getObject().asLiteral().getString());
      }
    }
    Property hasScale = ResourceFactory.createProperty(
        riNamespace + "hasScale");
    // hasScale //
    stmtI1 = model.listStatements(resource,
        hasScale, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      // validate hasScale property //
      if(!statement.getObject().isResource()) {         
        if(!ModelException.throwException(ModelException.METRIC,
            "hasScale property of Metric resource:"+
            resource.getURI()+" is not a resource")) {
          return null;
        }
      } else {
        Scale scale = (Scale) getResourceFromCache(
            statement.getObject().asResource(),Scale.class);
        if(scale == null) {
          scale = getScale(model,statement.getObject().asResource(),null);         
        }
        metric.setScale(scale);
      }
    }
    Property hasDimension = ResourceFactory.createProperty(
        riNamespace + "hasDimension");
    // hasDimension //
    stmtI1 = model.listStatements(resource,
        hasDimension, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      // validate hasDimension property //
      if(!statement.getObject().isResource()) {         
        if(!ModelException.throwException(ModelException.METRIC,
            "hasDimension property of Metric resource:"+
            resource.getURI()+" is not a resource")) {
View Full Code Here


    }
    categoricScale = (CategoricScale) getScale(model, resource, CategoricScale.class);
    Property allowValue = ResourceFactory.createProperty(
        riNamespace + "allowValue");
    // allowValue //
    StmtIterator stmtI1 = model.listStatements(resource,
        allowValue, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      // validate allowValue property //
      if(!statement.getObject().isLiteral()) {         
        if(!ModelException.throwException(ModelException.SCALE,
            "allowValue property of CategoricScale resource:"+
            resource.getURI()+" is not a literal")) {
View Full Code Here

    }
    numericScale = (NumericScale) getScale(model, resource, NumericScale.class);
    // minimum //
    Property minimum = ResourceFactory.createProperty(
        riNamespace + "minimum");
    StmtIterator stmtI1 = model.listStatements(resource,
        minimum, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      // validate minimum property //
      if(!statement.getObject().isLiteral()) {         
        if(!ModelException.throwException(ModelException.NUMERIC_SCALE,
            "minimum property of NumericScale resource:"+
            resource.getURI()+" is not a literal")) {
          return null;
        }
      } else {
        numericScale.setMinimum(statement.getObject().asLiteral().getDouble());
      }
    }
    Property maximum = ResourceFactory.createProperty(
        riNamespace + "maximum");
    // maximum //
    stmtI1 = model.listStatements(resource,
        maximum, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      /* validate maximum property */
      if(!statement.getObject().isLiteral()) {         
        if(!ModelException.throwException(ModelException.NUMERIC_SCALE,
            "maximum property of NumericScale resource:"+
            resource.getURI()+" is not a literal")) {
          return null;
        }
      } else {
        numericScale.setMaximum(statement.getObject().asLiteral().getDouble());
      }
    }
    Property step = ResourceFactory.createProperty(
        riNamespace + "step");
    // step //
    stmtI1 = model.listStatements(resource,
        step, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      // validate step property //
      if(!statement.getObject().isLiteral()) {         
        if(!ModelException.throwException(ModelException.NUMERIC_SCALE,
            "step property of NumericScale resource:"+
            resource.getURI()+" is not a literal")){
View Full Code Here

  }
 
  public Scale getScale(Model model, Resource resource,
      Class<? extends Scale> type) throws Exception {
    if(type == null) {
      StmtIterator stmtI1 = model.listStatements(resource,
          RDF.type, (RDFNode)null);
      Resource numericScale = ResourceFactory.
          createResource(riNamespace + "NumericScale");
      Resource categoricScale = ResourceFactory.
          createResource(riNamespace + "CategoricScale");
      while(stmtI1.hasNext()) {
        Statement typeStatement = stmtI1.nextStatement();
        if(typeStatement.getObject().asResource().getURI().equals(
            numericScale.getURI())) {
          Scale scale = getNumericScale(model, resource);
          return scale;
        } else if (typeStatement.getObject().asResource().getURI().equals(
            categoricScale.getURI())) {
          Scale scale = getCategoricScale(model, resource);
          return scale;
        }       
      }
      if(type == null) {
        if(!ModelException.throwException(ModelException.SCALE,
            "Impossible to instanciate a generic Scale(resource:"+resource+"" +
            "Please, see the model and assign a specific type.")) {
          return null;
        }
      }
    }   
    Scale scale = (Scale) getResourceFromCache(resource, type);
    if(scale != null) {     
      return scale;
    }   
    scale = type.newInstance();
    scale.setResource(resource);
    addResourceInstanceToCache(resource, scale);   
    // name //
    Property name = ResourceFactory.createProperty(riNamespace + "name");
    StmtIterator stmtI1 = model.listStatements(resource,
        name, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      // validate name property //
      if(!statement.getObject().isLiteral()) {         
        if(!ModelException.throwException(ModelException.SCALE,
            "name property of scale resource:"+
            resource.getURI()+" is not a literal")) {
View Full Code Here

    }   
    entityType = new EntityType();
    addResourceInstanceToCache(resource, entityType);
    // type //
    Property type = ResourceFactory.createProperty(riNamespace + "type");
    StmtIterator stmtI1 = model.listStatements(resource,
        type, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      // validate type property //
      if(!statement.getObject().isLiteral()) {         
        if(!ModelException.throwException(ModelException.ENTITYTYPE,
            "type property of EntityType resource:"+
            resource.getURI()+" is not a literal")) {
View Full Code Here

    }   
    repAlg = new ReputationAlgorithmImplementation();
    repAlg.setResource(resource);
    addResourceInstanceToCache(resource, repAlg);
    if(types == null) {     
      StmtIterator stmtI1 = model.listStatements(resource, RDF.type, (RDFNode)null);           
      while(stmtI1.hasNext()) {
        Statement typeStatement = stmtI1.nextStatement();
        for(Resource resourceType : reputationAlgorithmSubclasses.keySet()) {
          if(typeStatement.getObject().asResource().getURI().equals(
              resourceType.getURI())) {
            addBehaviourToReputationAlgorithm(model, resource,
                reputationAlgorithmSubclasses.get(resourceType),repAlg);
          }
        }               
      }
      for(Property property : reputationSubclassesProperties.keySet()) {
        stmtI1 = model.listStatements((Resource) null, property, resource);
        if(stmtI1.hasNext()) {
          addBehaviourToReputationAlgorithm(model, resource,
              reputationSubclassesProperties.get(property),repAlg);         
        }
      }
      for(Property property : reputationSubclassSubjectProperties.keySet()) {
        stmtI1 = model.listStatements(resource, property, (RDFNode) null);
        if(stmtI1.hasNext()) {
          addBehaviourToReputationAlgorithm(model, resource,
              reputationSubclassSubjectProperties.get(property),repAlg);
        }
      }     
    } else {
View Full Code Here

  void setApiParameters(Model model, Resource resource,
      ReputationAlgorithmImplementation repAlg) throws Exception {
    Property property = ResourceFactory.
        createProperty(riNamespace + "objectClass");
    // objectClass //
    StmtIterator stmtI1 = model.listStatements(resource,
        property, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      /* validate objectClass property */
      if(!statement.getObject().isLiteral()) {         
        if(ModelException.throwException(ModelException.REPUTATIONALGORITHM,
            "objectClass property of ReputationAlgorithm resource:"+
            resource.getURI()+" is not a literal")) {
          repAlg = null;
          return;
        }
      } else {
        repAlg.setObjectClass(statement.getObject().asLiteral().getString());         
      }
    }
    property = ResourceFactory.
        createProperty(riNamespace + "algorithmPath");
    // algorithmPath //
    stmtI1 = model.listStatements(resource,
        property, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      /* validate algorithmPath property */
      if(!statement.getObject().isLiteral()) {         
        if(ModelException.throwException(ModelException.REPUTATIONALGORITHM,
            "algorithmPath property of ReputationAlgorithm resource:"+
            resource.getURI()+" is not a literal")) {
View Full Code Here

  void setAttibutesAndProperties(Model model, Resource resource,
      ReputationAlgorithmImplementation repAlg) throws Exception {
    Property accesibility = ResourceFactory.
        createProperty(riNamespace + "accesibility");
    // accesibility //
    StmtIterator stmtI1 = model.listStatements(resource,
        accesibility, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      // validate accesibility property //
      if(!statement.getObject().isResource()) {         
        throw new Exception("uriFormat property of resource:"+
            resource.getURI()+" is not a resource");
      } else {
        AccessType type = getAccessType(statement.getObject().asResource());
        if(type == null) {
          if(!ModelException.throwException(ModelException.REPUTATIONALGORITHM,
              "accessType(resource:"+statement.getObject().asResource()+
              ") from ReputationAlgorithm(resource"+resource+") is not known")) {
            repAlg = null;
            return;
          }
        } else {
          repAlg.addAccesibility(type);
        }
      }
    }
    Property name = ResourceFactory.
        createProperty(riNamespace + "name");
    // name //
    stmtI1 = model.listStatements(resource,
        name, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      /* validate name property */
      if(!statement.getObject().isLiteral()) {         
        if(ModelException.throwException(ModelException.REPUTATIONALGORITHM,
            "name property of ReputationAlgorithm resource:"+
            resource.getURI()+" is not a literal")) {
          repAlg = null;
          return;
        }
      } else {
        repAlg.setName(statement.getObject().asLiteral().getString());         
      }
    }   
    Property resultCollectionType = ResourceFactory.
        createProperty(riNamespace + "resultCollectionType");
    /* resultCollectionType */
    stmtI1 = model.listStatements(resource,
        resultCollectionType, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      /* validate resultCollectionType property */
      if(!statement.getObject().isResource()) {         
        if(!ModelException.throwException(ModelException.REPUTATIONALGORITHM,
            "resultCollectionType property of ReputationAlgorithm resource:"+
            resource.getURI()+" is not a resource")) {
          repAlg = null;
          return;
        }
      } else {
        CollectionType collectionType = (CollectionType) getResourceFromCache(
            statement.getObject().asResource(),CollectionType.class);
        if(collectionType == null) {
          collectionType = getCollectionType(statement.getObject().asResource());       
        }
        if(collectionType == null) {
          ModelException.throwException(ModelException.REPUTATIONALGORITHM,
              "collectionType(resource:"+statement.getObject().asResource()+
              " from ReputationAlgorithm(resource"+resource+") is not known");
        } else {
          repAlg.setResultCollectionType(collectionType);
        }
      }
    }
    Property description = ResourceFactory.
        createProperty(dcNamespace + "description");
    /* description */
    stmtI1 = model.listStatements(resource,
        description, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      /* description name property */
      if(!statement.getObject().isLiteral()) {         
        if(!ModelException.throwException(ModelException.REPUTATIONALGORITHM,
            "dc:description property of ReputationAlgorithm resource:"+
            resource.getURI()+" is not a literal")) {
          repAlg = null;
          return;
        }
      } else {
        repAlg.setDescription(statement.getObject().asLiteral().getString());         
      }
    }
    Property entityType = ResourceFactory.
        createProperty(riNamespace + "entityType");
    /* entityType */
    stmtI1 = model.listStatements(resource,
        entityType, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      /* validate entityType property */
      if(!statement.getObject().isResource()) {         
        if(!ModelException.throwException(ModelException.REPUTATIONALGORITHM,
            "entityType property of ReputationAlgorithm resource:"+
            resource.getURI()+" is not a resource")) {
          repAlg = null;
          return;
        }
      } else {
        EntityType entityTypeIns = (EntityType) getResourceFromCache(
            statement.getObject().asResource(),EntityType.class);
        if(entityTypeIns == null) {
          entityTypeIns = getEntityType(model,
              statement.getObject().asResource());       
        }
        repAlg.addEntityType(entityTypeIns);         
      }
    }
    Property usesMetric = ResourceFactory.
        createProperty(riNamespace + "usesMetric");
    /* usesMetric */
    stmtI1 = model.listStatements(resource,
        usesMetric, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      /* validate usesMetric property */
      if(!statement.getObject().isResource()) {         
        if(!ModelException.throwException(ModelException.REPUTATIONALGORITHM,
            "usesMetric property of ReputationAlgorithm resource:"+
            resource.getURI()+" is not a resource")) {
          repAlg = null;
          return;
        }
      } else {
        Metric metric = (Metric) getResourceFromCache(
            statement.getObject().asResource(),Metric.class);
        if(metric == null) {
          metric = getMetric(model,statement.getObject().asResource());       
        }
        repAlg.addUsesMetrics(metric);         
      }
    }
    Property reputationSource = ResourceFactory.
        createProperty(riNamespace + "reputationSource");
    /* reputationSource */
    stmtI1 = model.listStatements(resource,
        reputationSource, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      /* validate reputationSource property */
      if(!statement.getObject().isResource()) {         
        if(!ModelException.throwException(ModelException.REPUTATIONALGORITHM,
            "reputationSource property of ReputationAlgorithm resource:"+
            resource.getURI()+" is not a resource")) {
          repAlg = null;
          return;
        }
      } else {
        ReputationValue reputationValue = (ReputationValue) getResourceFromCache(
            statement.getObject().asResource(),ReputationValue.class);
        if(reputationValue == null) {
          reputationValue = getReputationValue(model,
              statement.getObject().asResource());       
        }
        repAlg.addReputationSources(reputationValue);         
      }
    }
    Property reputationResult = ResourceFactory.
        createProperty(riNamespace + "reputationResult");
    /* reputationResult */
    stmtI1 = model.listStatements(resource,
        reputationResult, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      /* validate reputationResult property */
      if(!statement.getObject().isResource()) {         
        if(!ModelException.throwException(ModelException.REPUTATIONALGORITHM,
            "reputationResult property of ReputationAlgorithm resource:"+
            resource.getURI()+" is not a resource")) {
          repAlg = null;
          return;
        }
      } else {
        ReputationValue reputationValue = (ReputationValue) getResourceFromCache(
            statement.getObject().asResource(),ReputationValue.class);
        if(reputationValue == null) {
          reputationValue = getReputationValue(model,
              statement.getObject().asResource());       
        }
        repAlg.addReputationResults(reputationValue);         
      }
    }
    /* definedByReputationModel */
    Property definedByReputationModel = ResourceFactory.createProperty(
        riNamespace + "definedByReputationModel");
    stmtI1 = model.listStatements(resource,
        definedByReputationModel, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      /* validate definedByReputationModel property */
      if(!statement.getObject().isResource()) {         
        if(!ModelException.throwException(ModelException.REPUTATIONALGORITHM,
            "definedByReputationModel property of ReputationAlgorithm resource:"+
            resource.getURI()+" is not a resource")) {
          repAlg = null;
          return;
        }
      } else {
        repAlg.setDefinedByReputationModel(getReputationAlgorithm(
            model,statement.getObject().asResource(),null));         
      }
    }
    // stepIdentifier //
    Property stepIdentificator = ResourceFactory.createProperty(
        riNamespace + "stepIdentifier");   
    stmtI1 = model.listStatements(resource,
        stepIdentificator, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      // validate stepIdentifier property //
      if(!statement.getObject().isLiteral()) {         
        if(!ModelException.throwException(ModelException.REPUTATIONALGORITHM,
            "stepIdentifier property of resource:"+
            resource.getURI()+" is not a literal")) {
View Full Code Here

      while (iters.hasNext()) {
           resourcesCache.add(iters.nextResource());
      }
    }
    for(Property property : reputationSubclassesProperties.keySet()) {
      StmtIterator stmtI1 = model.listStatements((Resource) null, property, (RDFNode) null);
      while (stmtI1.hasNext()) {
        RDFNode object = stmtI1.nextStatement().getObject();
        if(object.isResource()) {
          resourcesCache.add(object.asResource());
        } else {
          if(!ModelException.throwException(ModelException.REPUTATIONALGORITHM,
              "Property "+property.getURI()+" has the object "
View Full Code Here

  public ReputationAlgorithmImplementation getCollectingAlgorithm(Model model,
      Resource resource, Class<? extends ReputationBehaviour> type) throws Exception {
    List<Class<? extends ReputationBehaviour>> types =
      new ArrayList<Class<? extends ReputationBehaviour>>();   
    if(type == null) {
      StmtIterator stmtI1 = model.listStatements(resource, RDF.type, (RDFNode)null);
      Resource reputationalAction = ResourceFactory.
          createResource(riNamespace + "ReputationalAction");
      Resource collectingSystem = ResourceFactory.
          createResource(riNamespace + "CollectingSystem");
      while(stmtI1.hasNext()) {
        Statement typeStatement = stmtI1.nextStatement();
        if(typeStatement.getObject().asResource().getURI().equals(
            reputationalAction.getURI())) {
          return getReputationalAction(model, resource);
        } else if (typeStatement.getObject().asResource().getURI().equals(
            collectingSystem.getURI())) {
View Full Code Here

TOP

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

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.