Models { public static Model stripContexts(Model model, Resource... contexts) { final List<Resource> contextList = Arrays.asList(contexts); return model.stream().map(st -> { if (contextList.isEmpty() || contextList.contains(st.getContext())) { return Statements.stripContext(st); } else { return st; } }).collect(ModelCollector.toModel()); } 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 testStripContextsCompletely() { IRI graph1 = VF.createIRI("urn:g1"); IRI graph2 = VF.createIRI("urn:g2"); Literal lit1 = VF.createLiteral(1.0); model1.add(foo, bar, lit1, graph1); model1.add(foo, bar, bar); model1.add(foo, bar, foo, graph2); Model allStripped = Models.stripContexts(model1); assertThat(allStripped.contexts()).containsOnly((Resource) null); assertThat(allStripped.contains(foo, bar, lit1, (Resource) null)).isTrue(); assertThat(allStripped.contains(foo, bar, lit1, graph1)).isFalse(); assertThat(allStripped.contains(foo, bar, bar, (Resource) null)).isTrue(); assertThat(allStripped.contains(foo, bar, foo, (Resource) null)).isTrue(); assertThat(allStripped.contains(foo, bar, foo, graph2)).isFalse(); assertThat(allStripped.size()).isEqualTo(model1.size()); }
@Test public void testStripContextsSpecificContext() { IRI graph1 = VF.createIRI("urn:g1"); IRI graph2 = VF.createIRI("urn:g2"); Literal lit1 = VF.createLiteral(1.0); model1.add(foo, bar, lit1, graph1); model1.add(foo, bar, bar); model1.add(foo, bar, foo, graph2); Model graph2Stripped = Models.stripContexts(model1, graph2); assertThat(graph2Stripped.contexts()).containsExactly(graph1, null); assertThat(graph2Stripped.contains(foo, bar, lit1, graph1)).isTrue(); assertThat(graph2Stripped.contains(foo, bar, foo, (Resource) null)).isTrue(); assertThat(graph2Stripped.contains(foo, bar, bar, (Resource) null)).isTrue(); assertThat(graph2Stripped.contains(foo, bar, bar, graph2)).isFalse(); assertThat(graph2Stripped.size()).isEqualTo(model1.size()); }