private boolean parseExample(BufferedReader reader,
			Collection<RankInput> exampleInputs,
			Collection<RankOutput> exampleOutputs) throws DatasetException,
			NumberFormatException, IOException {
		// List of items of this query. Each item is a list of features.
		LinkedList<LinkedList<Integer>> items = new LinkedList<LinkedList<Integer>>();

		// Relevant and irrelevant items for this query.
		LinkedList<Integer> relevantItems = new LinkedList<Integer>();
		LinkedList<Integer> irrelevantItems = new LinkedList<Integer>();

		// Read next line.
		String line;
		long prevQueryId = Long.MAX_VALUE;
		while ((line = reader.readLine()) != null) {
			// Trim read line.
			line = line.trim();
			if (line.length() == 0)
				// Stop on blank lines.
				break;

			// Split edge in feature values.
			String[] ftrValues = REGEX_SPACE.split(line);

			// Head and dependent tokens indexes.
			long queryId = Long.parseLong(ftrValues[0]);
			if (prevQueryId != Long.MAX_VALUE && prevQueryId != queryId)
				System.err
						.println("Different query IDs within the same example!");
			prevQueryId = queryId;

			// List of feature codes.
			LinkedList<Integer> ftrCodes = new LinkedList<Integer>();
			// Add it already to the list of items.
			items.add(ftrCodes);

			// Encode the edge features and add the codes to the list.
			for (int idxFtr = 0; idxFtr < ftrValues.length - 1; ++idxFtr) {
				String str = ftrValues[idxFtr];
				int code = basicEncoding.put(new String(str));
				ftrCodes.add(code);
			}

			// Index of the current item.
			int item = items.size() - 1;

			// The last value is the relevant feature (1 or -1).
			String isRelevant = ftrValues[ftrValues.length - 1];
			if (isRelevant.equals("1")) {

				/*
				 * Add the index of the current item to the list of relevant
				 * items.
				 */
				relevantItems.add(item);

			} else if (isRelevant.equals("-1")) {

				/*
				 * Add the index of the current item to the list of irrelevant
				 * items.
				 */
				irrelevantItems.add(item);

			} else {
				// Invalid feature value.
				throw new DatasetException(
						"Last feature value must be 1 or -1 to indicate "
								+ "whether the item is relevant or not. "
								+ "However, for item " + item
								+ " this feature value is " + isRelevant);
			}
		}

		if (items.size() == 0)
			return line != null;

		/*
		 * Create a new string to store the input id to avoid memory leaks,
		 * since the id string keeps a reference to the line string.
		 */
		RankInput input = new RankInput(prevQueryId, items);

		// Allocate the output structure.
		RankOutput output = new RankOutput(relevantItems, irrelevantItems);

		exampleInputs.add(input);
		exampleOutputs.add(output);

		// Return true if there are more lines.
		return line != null;
	}