|
18 | 18 | import java.util.stream.Collectors; |
19 | 19 | import java.util.stream.Stream; |
20 | 20 |
|
| 21 | +import org.eclipse.rdf4j.common.exception.RDF4JException; |
| 22 | +import org.eclipse.rdf4j.common.iteration.CloseableIteration; |
21 | 23 | import org.eclipse.rdf4j.common.transaction.IsolationLevels; |
22 | 24 | import org.eclipse.rdf4j.model.IRI; |
23 | 25 | import org.eclipse.rdf4j.model.Model; |
@@ -82,48 +84,34 @@ private Rdf4jShaclShapeGraphShapeSource(Repository repository, RepositoryConnect |
82 | 84 |
|
83 | 85 | private SailRepository forwardChain(RepositoryConnection shapesRepoConnection) { |
84 | 86 | try (var statements = shapesRepoConnection.getStatements(null, null, null, false, RDF4J.SHACL_SHAPE_GRAPH)) { |
85 | | - if (!statements.hasNext()) { |
86 | | - return new SailRepository(new MemoryStore()); |
87 | | - } |
88 | | - |
89 | | - SailRepository shapesRepoWithReasoning = new SailRepository( |
90 | | - SchemaCachingRDFSInferencer.fastInstantiateFrom(shaclVocabulary, new MemoryStore(), false)); |
91 | | - |
92 | | - try (var shapesRepoWithReasoningConnection = shapesRepoWithReasoning.getConnection()) { |
93 | | - shapesRepoWithReasoningConnection.begin(IsolationLevels.NONE); |
94 | | - |
95 | | - shapesRepoWithReasoningConnection.add(statements); |
96 | | - enrichShapes(shapesRepoWithReasoningConnection); |
97 | | - |
98 | | - shapesRepoWithReasoningConnection.commit(); |
99 | | - } |
100 | | - |
101 | | - return shapesRepoWithReasoning; |
102 | | - |
| 87 | + return forwardChain(statements); |
103 | 88 | } |
104 | 89 | } |
105 | 90 |
|
106 | 91 | private SailRepository forwardChain(SailConnection shapesSailConnection) { |
107 | 92 | try (var statements = shapesSailConnection.getStatements(null, null, null, false, RDF4J.SHACL_SHAPE_GRAPH)) { |
108 | | - if (!statements.hasNext()) { |
109 | | - return new SailRepository(new MemoryStore()); |
110 | | - } |
111 | | - |
112 | | - SailRepository shapesRepoWithReasoning = new SailRepository( |
113 | | - SchemaCachingRDFSInferencer.fastInstantiateFrom(shaclVocabulary, new MemoryStore(), false)); |
| 93 | + return forwardChain(statements); |
| 94 | + } |
| 95 | + } |
114 | 96 |
|
115 | | - try (var shapesRepoWithReasoningConnection = shapesRepoWithReasoning.getConnection()) { |
116 | | - shapesRepoWithReasoningConnection.begin(IsolationLevels.NONE); |
| 97 | + private SailRepository forwardChain(CloseableIteration<? extends Statement, ? extends RDF4JException> statements) { |
| 98 | + if (!statements.hasNext()) { |
| 99 | + return new SailRepository(new MemoryStore()); |
| 100 | + } |
117 | 101 |
|
118 | | - shapesRepoWithReasoningConnection.add(statements); |
119 | | - enrichShapes(shapesRepoWithReasoningConnection); |
| 102 | + SailRepository shapesRepoWithReasoning = new SailRepository( |
| 103 | + SchemaCachingRDFSInferencer.fastInstantiateFrom(shaclVocabulary, new MemoryStore(), false)); |
120 | 104 |
|
121 | | - shapesRepoWithReasoningConnection.commit(); |
122 | | - } |
| 105 | + try (var shapesRepoWithReasoningConnection = shapesRepoWithReasoning.getConnection()) { |
| 106 | + shapesRepoWithReasoningConnection.begin(IsolationLevels.NONE); |
123 | 107 |
|
124 | | - return shapesRepoWithReasoning; |
| 108 | + shapesRepoWithReasoningConnection.add(statements); |
| 109 | + enrichShapes(shapesRepoWithReasoningConnection); |
125 | 110 |
|
| 111 | + shapesRepoWithReasoningConnection.commit(); |
126 | 112 | } |
| 113 | + |
| 114 | + return shapesRepoWithReasoning; |
127 | 115 | } |
128 | 116 |
|
129 | 117 | private static SchemaCachingRDFSInferencer createShaclVocabulary() { |
|
0 commit comments