public final Builder addRules(final Model model) { final Set<String> ids = new HashSet<>(); final Map<String, String> heads = new HashMap<>(); final Map<String, String> bodies = new HashMap<>(); for (final Statement stmt : model.filter(null, RR.HEAD, null)) { ids.add(stmt.getSubject().stringValue()); heads.put(stmt.getSubject().stringValue(), stmt.getObject().stringValue()); } for (final Statement stmt : model.filter(null, RR.BODY, null)) { ids.add(stmt.getSubject().stringValue()); bodies.put(stmt.getSubject().stringValue(), stmt.getObject().stringValue()); } final List<String> sortedIDs = new ArrayList<>(ids); Collections.sort(sortedIDs); for (final String id : sortedIDs) { addRule(id, heads.get(id), bodies.get(id), Namespaces.forIterable(model.getNamespaces(), false), null); } return this; }