Models { @Experimental public static void convertReificationToRDFStar(ValueFactory vf, Model model, Consumer<Statement> consumer) { Map<Resource, Triple> convertedStatements = new HashMap<>(); model.filter(null, RDF.TYPE, RDF.STATEMENT).forEach((s) -> { Value subject = object(model.filter(s.getSubject(), RDF.SUBJECT, null)).orElse(null); if (!(subject instanceof IRI) && !(subject instanceof BNode)) { return; } Value predicate = object(model.filter(s.getSubject(), RDF.PREDICATE, null)).orElse(null); if (!(predicate instanceof IRI)) { return; } Value object = object(model.filter(s.getSubject(), RDF.OBJECT, null)).orElse(null); if (!(object instanceof Value)) { return; } Triple t = vf.createTriple((Resource) subject, (IRI) predicate, object); convertedStatements.put(s.getSubject(), t); }); for (Map.Entry<Resource, Triple> e : convertedStatements.entrySet()) { Triple t = e.getValue(); Resource subject = convertedStatements.get(t.getSubject()); Resource object = convertedStatements.get(t.getObject()); if (subject != null || object != null) { Triple nt = vf.createTriple(subject != null ? subject : t.getSubject(), t.getPredicate(), object != null ? object : t.getObject()); e.setValue(nt); } } model.forEach((s) -> { Resource subject = s.getSubject(); IRI predicate = s.getPredicate(); Value object = s.getObject(); Triple subjectTriple = convertedStatements.get(subject); Triple objectTriple = convertedStatements.get(object); if (subjectTriple == null && objectTriple == null) { consumer.accept(s); } else if (subjectTriple == null || ((!RDF.TYPE.equals(predicate) || !RDF.STATEMENT.equals(object)) && !RDF.SUBJECT.equals(predicate) && !RDF.PREDICATE.equals(predicate) && !RDF.OBJECT.equals(predicate))) { Statement ns = vf.createStatement(subjectTriple != null ? subjectTriple : s.getSubject(), s.getPredicate(), objectTriple != null ? objectTriple : s.getObject(), s.getContext()); consumer.accept(ns); } }); } protected  Models(); static Optional<Value> object(Iterable<Statement> statements); static Optional<Value> object(Model m); static Optional<Literal> objectLiteral(Iterable<Statement> statements); static Optional<Literal> objectLiteral(Model m); static Set<Literal> objectLiterals(Iterable<Statement> statements); static Set<Literal> objectLiterals(Model m); static Optional<Resource> objectResource(Iterable<Statement> statements); static Optional<Resource> objectResource(Model m); static Set<Resource> objectResources(Iterable<Statement> statements); static Set<Resource> objectResources(Model m); static Optional<IRI> objectIRI(Iterable<Statement> statements); static Optional<IRI> objectIRI(Model m); static Set<IRI> objectIRIs(Iterable<Statement> statements); static Set<IRI> objectIRIs(Model m); static Optional<String> objectString(Iterable<Statement> statements); static Optional<String> objectString(Model m); static Set<String> objectStrings(Iterable<Statement> statements); static Set<String> objectStrings(Model m); static Optional<Resource> subject(Iterable<Statement> statements); static Optional<Resource> subject(Model m); static Optional<IRI> subjectIRI(Iterable<Statement> statements); static Optional<IRI> subjectIRI(Model m); static Set<IRI> subjectIRIs(Iterable<Statement> statements); static Set<IRI> subjectIRIs(Model m); static Optional<BNode> subjectBNode(Iterable<Statement> statements); static Optional<BNode> subjectBNode(Model m); static Set<BNode> subjectBNodes(Iterable<Statement> statements); static Set<BNode> subjectBNodes(Model m); static Optional<IRI> predicate(Iterable<Statement> statements); static Optional<IRI> predicate(Model m); static Model setProperty(Model m, Resource subject, IRI property, Value value, Resource... contexts); static Optional<Value> getProperty(Model m, Resource subject, IRI property, Resource... contexts); static Set<Value> getProperties(Model m, Resource subject, IRI property, Resource... contexts); static Optional<Resource> getPropertyResource(Model m, Resource subject, IRI property,
			Resource... contexts); static Set<Resource> getPropertyResources(Model m, Resource subject, IRI property, Resource... contexts); static Optional<IRI> getPropertyIRI(Model m, Resource subject, IRI property, Resource... contexts); static Set<IRI> getPropertyIRIs(Model m, Resource subject, IRI property, Resource... contexts); static Optional<Literal> getPropertyLiteral(Model m, Resource subject, IRI property, Resource... contexts); static Set<Literal> getPropertyLiterals(Model m, Resource subject, IRI property, Resource... contexts); static Optional<String> getPropertyString(Model m, Resource subject, IRI property, Resource... contexts); static Set<String> getPropertyStrings(Model m, Resource subject, IRI property, Resource... contexts); static boolean isomorphic(Iterable<? extends Statement> model1, Iterable<? extends Statement> model2); static boolean isSubset(Iterable<? extends Statement> model1, Iterable<? extends Statement> model2); static boolean isSubset(Set<? extends Statement> model1, Set<? extends Statement> model2); static Model stripContexts(Model model, Resource... contexts); static Supplier<ModelException> modelException(String message); static Model synchronizedModel(Model toSynchronize); @Experimental static void convertRDFStarToReification(ValueFactory vf, Model model, Consumer<Statement> consumer); @Experimental static void convertRDFStarToReification(Model model, Consumer<Statement> consumer); @Experimental static Model convertRDFStarToReification(ValueFactory vf, Model model); @Experimental static Model convertRDFStarToReification(ValueFactory vf, Model model, ModelFactory modelFactory); @Experimental static Model convertRDFStarToReification(Model model); @Experimental static void convertReificationToRDFStar(ValueFactory vf, Model model, Consumer<Statement> consumer); @Experimental static void convertReificationToRDFStar(Model model, Consumer<Statement> consumer); @Experimental static Model convertReificationToRDFStar(ValueFactory vf, Model model, ModelFactory modelFactory); @Experimental static Model convertReificationToRDFStar(ValueFactory vf, Model model); @Experimental static Model convertReificationToRDFStar(Model model);  }
@Test public void testConvertReificationToRDFStar() { Model reificationModel = RDFStarTestHelper.createRDFReificationModel(); Model referenceRDFStarModel = RDFStarTestHelper.createRDFStarModel(); Model rdfStarModel1 = Models.convertReificationToRDFStar(VF, reificationModel); assertTrue("RDF reification conversion to RDF* with explicit VF, model-to-model", Models.isomorphic(rdfStarModel1, referenceRDFStarModel)); Model rdfStarModel2 = Models.convertReificationToRDFStar(reificationModel); assertTrue("RDF reification conversion to RDF* with implicit VF, model-to-model", Models.isomorphic(rdfStarModel2, referenceRDFStarModel)); Model rdfStarModel3 = new TreeModel(); Models.convertReificationToRDFStar(VF, reificationModel, (Consumer<Statement>) rdfStarModel3::add); assertTrue("RDF reification conversion to RDF* with explicit VF, model-to-consumer", Models.isomorphic(rdfStarModel3, referenceRDFStarModel)); Model rdfStarModel4 = new TreeModel(); Models.convertReificationToRDFStar(reificationModel, rdfStarModel4::add); assertTrue("RDF reification conversion to RDF* with implicit VF, model-to-consumer", Models.isomorphic(rdfStarModel4, referenceRDFStarModel)); }