public Resource build() { resource = ResourceUtils.renameResource(getResource(), getUriBuilder().build().toString()); return resource; }
ResourceUtils.removeEquiv( s, orderRel, this ); boolean withheld = s.remove( this ); List<List<T>> partition = ResourceUtils.partition( s, orderRel ); Map<Resource, List<T>> equivSets = new HashMap<>(); s = ResourceUtils.maximalLowerElements( s, orderRel, inverse );
@Override public Object open( Assembler a, Resource root, Mode irrelevant ) { checkType( root, JA.LocationMapper ); return new LocationMapper( ResourceUtils.reachableClosure( root ) ); } }
/** * <p> * Answer the maximal lower elements of the given collection, given the partial * ordering <code>rel</code>. See {@link #maximalLowerElements( Iterator, Property, boolean )} * for details. * </p> * * @param resources A collection of resources * @param rel A property defining a partial-ordering on <code>resources</code> * @param inverse If true, we invert the given property (by reversing the order * of the arguments), which allows us to use eg subClassOf as a partial order * operator for both sub-class and super-class relationships * @return The collection that contains only those <code>resources</code> are not * greater than another resource under the partial order. */ public static <T extends Resource> List<T> maximalLowerElements( Collection<T> resources, Property rel, boolean inverse ) { return maximalLowerElements( resources.iterator(), rel, inverse ); }
/** * <p>Answer a list of lists, which is a partition of the given * input list of resources. The equivalence relation is the predicate p. * So, two resources <code>a</code> and <code>b</code> * will be in the same partition iff * {@code (a p b) && (b p a)}.</p> * @param <T> * @param l A list of resources * @param p An equivalence predicate * @return A list of lists which are the partitions of <code>l</code> * under <code>p</code> */ public static <T extends Resource> List<List<T>> partition( List<T> l, Property p ) { // first copy the input so we can mess with it List<T> source = new ArrayList<>(); source.addAll( l ); List<List<T>> parts = new ArrayList<>(); while (!source.isEmpty()) { // each step through the loop we pick a random element, and // create a list of that element and all its equivalent values T seed = source.remove( 0 ); List<T> part = removeEquiv( source, p, seed ); part.add( seed ); // add to the partition list parts.add( part ); } return parts; }
public void testPartition() { Model m = ModelFactory.createDefaultModel(); Resource a = m.createResource( NS + "a" ); Resource b = m.createResource( NS + "b" ); Resource c = m.createResource( NS + "c" ); Resource d = m.createResource( NS + "d" ); Resource e = m.createResource( NS + "e" ); b.addProperty( RDFS.subClassOf, a ); a.addProperty( RDFS.subClassOf, b ); // a,b are equivalent d.addProperty( RDFS.subClassOf, e ); e.addProperty( RDFS.subClassOf, d ); // d,e are equivalent // reflexive relations - would be inferred by inf engine a.addProperty( RDFS.subClassOf, a ); b.addProperty( RDFS.subClassOf, b ); c.addProperty( RDFS.subClassOf, c ); d.addProperty( RDFS.subClassOf, d ); e.addProperty( RDFS.subClassOf, e ); List<Resource> abcde = Arrays.asList( new Resource[] {a,b,c,d,e} ); List<Resource> ab = Arrays.asList( new Resource[] {b,a} ); List<Resource> cc = Arrays.asList( new Resource[] {c} ); List<Resource> de = Arrays.asList( new Resource[] {e,d} ); List<List<Resource>> partition = ResourceUtils.partition( abcde, RDFS.subClassOf ); assertEquals( "Should be 3 partitions", 3, partition.size() ); assertEquals( "First parition should be (a,b)", ab, partition.get(0) ); assertEquals( "First parition should be (c)", cc, partition.get(1) ); assertEquals( "First parition should be (d,e)", de, partition.get(2) ); }
/** * <p> * Answer the maximal lower elements of the given collection, given the partial * ordering <code>rel</code>. See {@link #maximalLowerElements( Iterator, Property, boolean )} * for details. * </p> * * @param resources A collection of resources * @param rel A property defining a partial-ordering on <code>resources</code> * @param inverse If true, we invert the given property (by reversing the order * of the arguments), which allows us to use eg subClassOf as a partial order * operator for both sub-class and super-class relationships * @return The collection that contains only those <code>resources</code> are not * greater than another resource under the partial order. */ public static <T extends Resource> List<T> maximalLowerElements( Collection<T> resources, Property rel, boolean inverse ) { return maximalLowerElements( resources.iterator(), rel, inverse ); }
/** * <p>Answer a list of lists, which is a partition of the given * input list of resources. The equivalence relation is the predicate p. * So, two resources <code>a</code> and <code>b</code> * will be in the same partition iff * {@code (a p b) && (b p a)}.</p> * @param <T> * @param l A list of resources * @param p An equivalence predicate * @return A list of lists which are the partitions of <code>l</code> * under <code>p</code> */ public static <T extends Resource> List<List<T>> partition( List<T> l, Property p ) { // first copy the input so we can mess with it List<T> source = new ArrayList<>(); source.addAll( l ); List<List<T>> parts = new ArrayList<>(); while (!source.isEmpty()) { // each step through the loop we pick a random element, and // create a list of that element and all its equivalent values T seed = source.remove( 0 ); List<T> part = removeEquiv( source, p, seed ); part.add( seed ); // add to the partition list parts.add( part ); } return parts; }
public void testPartition() { Model m = ModelFactory.createDefaultModel(); Resource a = m.createResource( NS + "a" ); Resource b = m.createResource( NS + "b" ); Resource c = m.createResource( NS + "c" ); Resource d = m.createResource( NS + "d" ); Resource e = m.createResource( NS + "e" ); b.addProperty( RDFS.subClassOf, a ); a.addProperty( RDFS.subClassOf, b ); // a,b are equivalent d.addProperty( RDFS.subClassOf, e ); e.addProperty( RDFS.subClassOf, d ); // d,e are equivalent // reflexive relations - would be inferred by inf engine a.addProperty( RDFS.subClassOf, a ); b.addProperty( RDFS.subClassOf, b ); c.addProperty( RDFS.subClassOf, c ); d.addProperty( RDFS.subClassOf, d ); e.addProperty( RDFS.subClassOf, e ); List<Resource> abcde = Arrays.asList( new Resource[] {a,b,c,d,e} ); List<Resource> ab = Arrays.asList( new Resource[] {b,a} ); List<Resource> cc = Arrays.asList( new Resource[] {c} ); List<Resource> de = Arrays.asList( new Resource[] {e,d} ); List<List<Resource>> partition = ResourceUtils.partition( abcde, RDFS.subClassOf ); assertEquals( "Should be 3 partitions", 3, partition.size() ); assertEquals( "First parition should be (a,b)", ab, partition.get(0) ); assertEquals( "First parition should be (c)", cc, partition.get(1) ); assertEquals( "First parition should be (d,e)", de, partition.get(2) ); }
private Model reanonimisePathBlankNodes(Resource resource, RDFNode rdfNode) { Model pathModel = ModelFactory.createDefaultModel(); pathModel.add(rdfNode.getModel()); pathModel.add(resource, SHACL.resultPath, rdfNode); ImmutableSet<Resource> resources = ImmutableSet.copyOf(pathModel.listSubjects()); resources.stream() .filter(Resource::isAnon) .filter(r -> r != resource) .forEach(r -> ResourceUtils.renameResource(r, null)); return pathModel; } }
ResourceUtils.removeEquiv( s, orderRel, this ); boolean withheld = s.remove( this ); List<List<T>> partition = ResourceUtils.partition( s, orderRel ); Map<Resource, List<T>> equivSets = new HashMap<>(); s = ResourceUtils.maximalLowerElements( s, orderRel, inverse );
@Override public Object open( Assembler a, Resource root, Mode irrelevant ) { checkType( root, JA.LocationMapper ); return new LocationMapper( ResourceUtils.reachableClosure( root ) ); } }
public void testMaximalLowerElements() { Model m = ModelFactory.createDefaultModel(); Resource a = m.createResource( NS + "a" ); Resource b = m.createResource( NS + "b" ); Resource c = m.createResource( NS + "c" ); Resource d = m.createResource( NS + "d" ); b.addProperty( RDFS.subClassOf, a ); c.addProperty( RDFS.subClassOf, a ); d.addProperty( RDFS.subClassOf, c ); d.addProperty( RDFS.subClassOf, a ); List<Resource> abcd = Arrays.asList( a,b,c,d ); List<Resource> bcd = Arrays.asList( b,c,d ); List<Resource> cd = Arrays.asList( c,d ); assertEquals( "Wrong number of remaining resources", 1, ResourceUtils.maximalLowerElements( abcd, RDFS.subClassOf, true ).size() ); assertEquals( "Result should be a", a, ResourceUtils.maximalLowerElements( abcd, RDFS.subClassOf, true ).iterator().next() ); assertEquals( "Wrong number of remaining resources", 2, ResourceUtils.maximalLowerElements( bcd, RDFS.subClassOf, true ).size() ); assertEquals( "Wrong number of remaining resources", 1, ResourceUtils.maximalLowerElements( cd, RDFS.subClassOf, true ).size() ); assertEquals( "Result should be a", c, ResourceUtils.maximalLowerElements( cd, RDFS.subClassOf, true ).iterator().next() ); }
assertNull( out ); out = ResourceUtils.removeEquiv( in, RDFS.subClassOf, a ); assertEquals( out, ab ); out = ResourceUtils.removeEquiv( in, RDFS.subClassOf, e );
private Model reanonimisePathBlankNodes(Resource resource, RDFNode rdfNode) { Model pathModel = ModelFactory.createDefaultModel(); pathModel.add(rdfNode.getModel()); pathModel.add(resource, SHACL.resultPath, rdfNode); ImmutableSet<Resource> resources = ImmutableSet.copyOf(pathModel.listSubjects()); resources.stream() .filter(Resource::isAnon) .filter(r -> r != resource) .forEach(r -> ResourceUtils.renameResource(r, null)); return pathModel; } }
private static void addQuotedContent( List<Content> contents, Resource root ) { StmtIterator it = root.listProperties( JA.quotedContent ); while (it.hasNext()) { Resource q = getResource( it.nextStatement() ); Model m = ResourceUtils.reachableClosure( q ); contents.add( newModelContent( m ) ); } }
public void testMaximalLowerElements() { Model m = ModelFactory.createDefaultModel(); Resource a = m.createResource( NS + "a" ); Resource b = m.createResource( NS + "b" ); Resource c = m.createResource( NS + "c" ); Resource d = m.createResource( NS + "d" ); b.addProperty( RDFS.subClassOf, a ); c.addProperty( RDFS.subClassOf, a ); d.addProperty( RDFS.subClassOf, c ); d.addProperty( RDFS.subClassOf, a ); List<Resource> abcd = Arrays.asList( a,b,c,d ); List<Resource> bcd = Arrays.asList( b,c,d ); List<Resource> cd = Arrays.asList( c,d ); assertEquals( "Wrong number of remaining resources", 1, ResourceUtils.maximalLowerElements( abcd, RDFS.subClassOf, true ).size() ); assertEquals( "Result should be a", a, ResourceUtils.maximalLowerElements( abcd, RDFS.subClassOf, true ).iterator().next() ); assertEquals( "Wrong number of remaining resources", 2, ResourceUtils.maximalLowerElements( bcd, RDFS.subClassOf, true ).size() ); assertEquals( "Wrong number of remaining resources", 1, ResourceUtils.maximalLowerElements( cd, RDFS.subClassOf, true ).size() ); assertEquals( "Result should be a", c, ResourceUtils.maximalLowerElements( cd, RDFS.subClassOf, true ).iterator().next() ); }
assertNull( out ); out = ResourceUtils.removeEquiv( in, RDFS.subClassOf, a ); assertEquals( out, ab ); out = ResourceUtils.removeEquiv( in, RDFS.subClassOf, e );
private void renamePortal(Resource portal, String namespace, Model model) { model.enterCriticalSection(Lock.WRITE); try { ResourceUtils.renameResource(portal, namespace + portal.getLocalName()); } finally { model.leaveCriticalSection(); } }
private static void addQuotedContent( List<Content> contents, Resource root ) { StmtIterator it = root.listProperties( JA.quotedContent ); while (it.hasNext()) { Resource q = getResource( it.nextStatement() ); Model m = ResourceUtils.reachableClosure( q ); contents.add( newModelContent( m ) ); } }