Skip to content

Commit 618c2cd

Browse files
committed
Remove unnecessary checks when merging models
1 parent d42ccce commit 618c2cd

File tree

1 file changed

+7
-26
lines changed

1 file changed

+7
-26
lines changed

core/sds-aspect-model-resolver/src/main/java/io/openmanufacturing/sds/aspectmodel/resolver/AspectModelResolver.java

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525

2626
import org.apache.jena.rdf.model.Model;
2727
import org.apache.jena.rdf.model.ModelFactory;
28+
import org.apache.jena.rdf.model.Property;
2829
import org.apache.jena.rdf.model.RDFNode;
29-
import org.apache.jena.rdf.model.Statement;
30-
import org.apache.jena.rdf.model.StmtIterator;
3130
import org.apache.jena.vocabulary.RDF;
3231
import org.apache.jena.vocabulary.XSD;
3332

@@ -154,6 +153,7 @@ private Try<Model> resolve( final String urn, final ResolutionStrategy resolutio
154153
return resolvedModel;
155154
}
156155
final Model model = resolvedModel.get();
156+
Property refines = model.createProperty( "urn:bamm:io.openmanufacturing:meta-model:1.0.0#refines" );
157157

158158
// Merge the resolved model into the target if it was not already merged before.
159159
// It could have been merged before when the model contains another model definition that was already resolved
@@ -164,8 +164,7 @@ private Try<Model> resolve( final String urn, final ResolutionStrategy resolutio
164164
for ( final String element : getAllUrnsInModel( model ) ) {
165165
if ( !result.contains( model.createResource( element ), RDF.type, (RDFNode) null )
166166
// Backwards compatibility with BAMM 1.0.0
167-
&& !result.contains( model.createResource( element ), model.createProperty( "urn:bamm:io.openmanufacturing:meta-model:1.0.0#refines" ),
168-
(RDFNode) null )
167+
&& !result.contains( model.createResource( element ), refines, (RDFNode) null )
169168
&& !unresolvedUrns.contains( element ) ) {
170169
unresolvedUrns.push( element );
171170
}
@@ -209,11 +208,9 @@ private Try<Model> getModelForUrn( final String urn, final ResolutionStrategy re
209208
}
210209

211210
/**
212-
* Defensively merge a model into an existing target model. This means:
213-
* <ul>
214-
* <li>Prefixes are only added when they are not already present, i.e., a model won't overwrite the empty prefix of the target model</li>
215-
* <li>Statements that have a blank node (including RDF lists) as their object won't be added</li>
216-
* </ul>
211+
* Merge a model into an existing target model. Prefixes are only added when they are not already present, i.e.,
212+
* a model won't overwrite the empty prefix of the target model.
213+
*
217214
* @param target the model to merge into
218215
* @param other the model to be merged
219216
*/
@@ -224,22 +221,6 @@ private void mergeModels( final Model target, final Model other ) {
224221
}
225222
}
226223

227-
for ( final StmtIterator it = other.listStatements(); it.hasNext(); ) {
228-
final Statement statement = it.next();
229-
230-
if ( target.contains( statement.getSubject(), statement.getPredicate(), (RDFNode) null ) ) {
231-
// If the value is a language string, add the additional assertion
232-
if ( statement.getObject().isLiteral() && !statement.getLiteral().getLanguage().isEmpty() ) {
233-
target.add( statement );
234-
}
235-
// If the value is a named resource, also add the additional assertion. This for example
236-
// is the case with multiple bamm:see assertions
237-
if ( statement.getObject().isResource() && statement.getResource().isURIResource() ) {
238-
target.add( statement );
239-
}
240-
} else {
241-
target.add( statement );
242-
}
243-
}
224+
other.listStatements().forEach( target::add );
244225
}
245226
}

0 commit comments

Comments
 (0)