@Override
	public void performAnalysis(PrintStream ps) {
		if (ps == null)
			ps = System.out;
		
		NumTriples nt = new NumTriples();
		nt.processSparqlDataset(ds);
		numTriples = nt.getNumTriples();

		numTriplesConsidered = 0;
		offsetResultSeries = new LinkedHashMap<String, Map<Integer, Object>>();
		long startTime = System.currentTimeMillis();
		
		List<Integer> offsets = new ArrayList<Integer>((int) Math.ceil((double) numTriples/tripleLimit));
		for (int offset = 0; offset < numTriples; offset += tripleLimit) {
			offsets.add(offset);
		}
		
		if (randomSampling)
		        Collections.shuffle(offsets);
//		System.out.println(offsets);
		
		// write header and first line
//		logLine(0, 0L);

		String queryString = "SELECT ?subject ?predicate ?object\n" +
				"WHERE {?subject ?predicate ?object.}\n" +
				"ORDER BY "+ orderByClause +"\n" +
				"LIMIT " + tripleLimit + "\n" +
				"OFFSET ";

		for (Integer offset : offsets) {
			
			// Create a new query
			Query query = QueryFactory.create(queryString + offset);
			logger.debug("query is \n" + queryString + offset);
			
			// execute query and obtain results
			QueryExecution qe = ds.query(query);
			logger.info("TripleStream: limit=" + tripleLimit
					+ ", offset=" + offset + " at " + System.currentTimeMillis()/1000);
			ResultSet results = qe.execSelect();
			
			// process query results
			logger.trace("process query results");			
			while (results.hasNext()) {
				QuerySolution qs = results.next();
				if (qs.contains("?subject") && qs.contains("?predicate") && qs.contains("?object")) { // valid
																					// solution
					Resource s = qs.getResource("?subject");
					Resource pRes = qs.getResource("?predicate");
					Property p = ResourceFactory.createProperty(pRes.getURI());
					RDFNode o = qs.get("?object");
					logger.trace("considering triple (" + s + " " + p + " " + o
							+ ")");
					numTriplesConsidered++;

					for (StatisticalCriterion sc : criteria) {
						sc.considerTriple(s, p, o);
					}

				} else // invalid solution
				logger.debug("invalid solution: " + qs);
			}
			
			// Important - free up resources used running the query
			qe.close();
			
			// log results
			logLine(offset, System.currentTimeMillis() - startTime);
		}

		// finally write Log
		writeResultLog();
	}