Package cross.reputation.model

Examples of cross.reputation.model.Metric


        riNamespace + "Metric");
    ResIterator iters = model.listSubjectsWithProperty(
        RDF.type,metric);
    while (iters.hasNext()) {
      Resource resource = iters.nextResource();
      Metric metricIns = getMetric(model, resource);
      if(!validate || ValidateModel.validateMetric(metricIns)) {
        metrics.add(metricIns);
      } else {
        ModelException.sendMessage(ModelException.WARNING,"entity(" +
            "resource:"+metricIns.getResource()+") dicarted");
      }     
    }
    return metrics;
  }
View Full Code Here


    }
    return metrics;
  }
 
  public Metric getMetric(Model model, Resource resource) throws Exception {
    Metric metric = (Metric) getResourceFromCache(resource, Metric.class);
    if(metric != null) {     
      return metric;
    }
    metric = new Metric();
    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")) {
          return null;
        }
      } else {
        Dimension dimension = (Dimension) getResourceFromCache(
            statement.getObject().asResource(),Dimension.class);
        if(dimension == null) {
          dimension = getDimension(model,
              statement.getObject().asResource());         
        }
        metric.setDimension(dimension);
      }
    }
    return metric;
  }
View Full Code Here

        System.out.println("The database contains subjects" +
            " of type metric:");
        while (iters.hasNext()) {
            Resource resource = iters.nextResource();
            System.out.println("  " + resource.getLocalName());
            Metric metricInstance =
              getMetric(model,resource);
            System.out.println(metricInstance.toString("     "));           
        }
    } else {
        System.out.println("No simple String riNamespace+" +
            "metric were found in the database");
    }
View Full Code Here

            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);         
View Full Code Here

      }
    }
    Property sourceMetric = ResourceFactory.
        createProperty(riNamespace + "sourceMetric");
    /* sourceMetric */
    Metric sourceInstance = null;   
    stmtI1 = model.listStatements(resource, sourceMetric, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      /* validate sourceMetric property */
      if(!statement.getObject().isResource()) {         
        if(!ModelException.throwException(ModelException.METRICTRANSFORMER,
            "sourceMetric property of MetricTransformer resource:"+
            resource.getURI()+" is not a resource")) {
          return null;
        }
      } else {
        sourceInstance = (Metric) getResourceFromCache(
          statement.getObject().asResource(),Metric.class);
        if(sourceInstance == null) {
          sourceInstance = getMetric(model, statement.getObject().asResource());         
        }                       
      }
    }
    Property destinationMetric = ResourceFactory.
        createProperty(riNamespace + "destinationMetric");
    /* destinationMetric */
    Metric destinationInstance = null;
    stmtI1 = model.listStatements(resource,
        destinationMetric, (RDFNode)null);
    while(stmtI1.hasNext()) {
      Statement statement = stmtI1.nextStatement();
      /* validate destinationMetric property */
 
View Full Code Here

    Category securityWebAppCategory = GlobalModel.addCategory("SecurityWebApp");
    Category projectConnCategory = GlobalModel.addCategory("ProjectConnection");
   
   
    GlobalModel.addScale(new NumericScale("stackOverflowScale",200000.0,0.0,1.0));
    GlobalModel.addMetric(new Metric("stackOverflowMetric", reputationInQandA,
        GlobalModel.getScales().get("stackOverflowScale")));
    Category stackOverflowCategories[] = {qandACategory};
    GlobalModel.addCommunity(new Community("stackoverflow.com","stackoverflow.com",
        stackOverflowCategories,GlobalModel.getMetrics().get("stackOverflowMetric")));   
   
    GlobalModel.addScale(new NumericScale("serverFaultScale",20000.0,0.0,1.0));
    GlobalModel.addMetric(new Metric("serverFaultMetric", reputationInQandA,
        GlobalModel.getScales().get("serverFaultScale")));
    Category serverFaultCategories[] = {qandACategory};
    GlobalModel.addCommunity(new Community("serverfault.com","serverfault.com",
        serverFaultCategories,GlobalModel.getMetrics().get("serverFaultMetric")));
       
    GlobalModel.addScale(new NumericScale("webAppsStackExchangeScale",20000.0,0.0,1.0));
    GlobalModel.addMetric(new Metric("webAppsStackExchangeMetric", reputationInQandA,
        GlobalModel.getScales().get("webAppsStackExchangeScale")));
    Category webAppsStackExchangeCategories[] = {qandACategory};
    GlobalModel.addCommunity(new Community("webapps.stackexchange.com","webapps.stackexchange.com",
        webAppsStackExchangeCategories,GlobalModel.getMetrics().get("webAppsStackExchangeMetric")));
       
    GlobalModel.addScale(new NumericScale("questionsSecuritytubeScale",20000.0,0.0,1.0));
    GlobalModel.addMetric(new Metric("questionsSecuritytubeMetric", reputationInQandA,
        GlobalModel.getScales().get("questionsSecuritytubeScale")));
    Category questionsSecuritytubeCategories[] = {qandACategory};
    GlobalModel.addCommunity(new Community("questions.securitytube.net","questions.securitytube.net",
        questionsSecuritytubeCategories,GlobalModel.getMetrics().get("questionsSecuritytubeMetric")));
       
    GlobalModel.addScale(new NumericScale("security.StackexchangeScale",2000.0,0.0,1.0));
    GlobalModel.addMetric(new Metric("security.StackexchangeMetric", reputationInQandA,
        GlobalModel.getScales().get("security.StackexchangeScale")));
    Category securityStackexchangeCategories[] = {qandACategory};
    GlobalModel.addCommunity(new Community("security.stackexchange.com","security.stackexchange.com",
        securityStackexchangeCategories,GlobalModel.getMetrics().get("security.StackexchangeMetric")));
   
    GlobalModel.addScale(new NumericScale("semanticWikiScale",10.0,0.0,1.0));
    GlobalModel.addMetric(new Metric("semanticWikiMetric", reputationInQandA,
        GlobalModel.getScales().get("semanticWikiScale")){
      public Object aggregateValues(Map<CommunityMetricToImport,Object> values) {
        Object total = null;
        int sum = 0;
        for(CommunityMetricToImport comMetToImp: values.keySet()) {
          if(comMetToImp.getCommunity() ==
              GlobalModel.getCommunities().get("ohloh.net")) {
            if(total != null) {
              total = getScale().mulValues(total,values.get(comMetToImp),0.1/0.9);
            } else {
              total = values.get(comMetToImp);
            }
            if(sum == 0) {
              sum = 1;
            }
            //System.out.println("new total in mul:"+total);
          }                   
        }
        for(CommunityMetricToImport comMetToImp: values.keySet()) {
          if(comMetToImp.getCommunity() ==
            GlobalModel.getCommunities().get("ohloh.net")) {
            continue;
          }
          //System.out.println("total:"+total+" next value to sum:"+values.get(comMetToImp));         
          total = getScale().sumValues(total, values.get(comMetToImp));
          sum++;
        }       
        //return doAverage(total,sum);
        return total;
      }
    });   
    Category semanticWikiCategories[] = {securityWebAppCategory};
    Community wiki = new Community("semanticWiki","lab.gsi.dit.upm.es/semanticwiki",
        semanticWikiCategories,GlobalModel.getMetrics().get("semanticWikiMetric"));
   
    Category ohlohCategories[] = {projectConnCategory};   
    Set<Metric> ohlohMetrics = new HashSet<Metric>();
    GlobalModel.addScale(new NumericScale("ohlohKudoScale",10.0,0.0,1.0));
    Metric ohlohKudoMetric = GlobalModel.addMetric(new Metric("ohlohKudoMetric",
        projectsReputation,GlobalModel.getScales().get("ohlohKudoScale")));
    ohlohMetrics.add(ohlohKudoMetric)
    GlobalModel.addScale(new NumericScale("ohlohRankScale",450000.0,0.0,1.0));
    Metric ohlohRankMetric = GlobalModel.addMetric(new Metric("ohlohRankMetric", rankReputation,
        GlobalModel.getScales().get("ohlohRankScale")));
    ohlohMetrics.add(ohlohRankMetric);   
    GlobalModel.addCommunity(new Community("ohloh.net","ohloh.net",
        ohlohCategories,ohlohMetrics));
   
    GlobalModel.addScale(new NumericScale("slackersScale",10.0,0.0,1.0));
    GlobalModel.addMetric(new Metric("slackersMetric", reputationInQandA,
        GlobalModel.getScales().get("slackersScale")));
    Category slackersCategories[] = {GlobalModel.addCategory("QandA")};
    GlobalModel.addCommunity(new Community("sla.ckers.org","sla.ckers.org",
        slackersCategories,GlobalModel.getMetrics().get("slackersMetric")));
   
View Full Code Here

      }     
          if(opalSum != null) {
            reputations = new HashMap<Metric,List<Object>>();
            List<Object> reputationValue = new ArrayList<Object>();
            reputationValue.add(opalSum);
            Metric metric = findExportedMetric(system, importationUnit, repImp);
        if(metric == null) {
          return reputations;
        }
            reputations.put(metric,reputationValue);
              ModelException.sendMessage(ModelException.INFO,
View Full Code Here

              return reputation;
            }
      }
      ModelException.sendMessage(ModelException.INFO," Reputation:"+ reputationString);
      //Adapt value to usesMetric/sourceMetric
      Metric metric = findExportedMetric(system, impUnit, repImp);
      if(metric == null) {
        return reputation;
      }
      Object reputationValue = defaultAddaptToMetric(metric, reputationString);
      if(reputationValue != null) {
View Full Code Here

          Map<Metric,Object> reputationMap = Scrapper.ExtractReputation(urlDomain)
          if(reputationMap == null || reputationMap.isEmpty()) {
            continue;
          }
          if(reputationMap.size() == 1 && community.getMetrics().size() == 1) {
            Metric metric = (Metric)community.getMetrics().toArray()[0];
            for(Object value : reputationMap.values()) {
              GlobalModel.addEvaluation(new Evaluation(community, entity,
                  metric,value));
              System.out.println("Ent:"+entity.getUniqueIdentificator()+" Com: "
              +community.getName()+ " url:"+communityEntity.get(community).getUrl()
              +" met:"+metric.getIdentifier()+" rep:"+value);
            }
          } else {
            for(Metric metric : reputationMap.keySet()) {
              Metric sourceMetric = null;             
              for(Metric comMetric : community.getMetrics()) {
                if(metric == null || !metric.getIdentifier().equalsIgnoreCase(
                    comMetric.getIdentifier())) {
                  continue;                 
                }
                sourceMetric = comMetric;
                break;
              }
              if(sourceMetric == null) {             
                System.out.println("ERROR: metric parsed("+(metric==null?null:metric.getIdentifier())
                  +") does not correspond to any metric of the community("+community.getName()+
                  "):"+community.getMetrics()+". Its score is ignored");
                continue;
             
              GlobalModel.addEvaluation(new Evaluation(community,
                  entity,sourceMetric,reputationMap.get(metric)));
              System.out.println("Ent:"+entity.getUniqueIdentificator()+" Com: "
              +community.getName()+ " url:"+communityEntity.get(community).getUrl()
              +" met:"+sourceMetric.getIdentifier()+" rep:"+reputationMap.get(metric));
             
            }             
          }
        } catch (IOException e) {
          System.out.println("INFO: extract reputation on user:" +
View Full Code Here

TOP

Related Classes of cross.reputation.model.Metric

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.