Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix): properties with same semantics but different sub tree weren't being merged #1718

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ case class JsonLDObjectElementParser(
override def foldLeft(
current: JsonLDObjectElementBuilder,
other: JsonLDObjectElementBuilder
): JsonLDObjectElementBuilder = current.merge(other)(ctx)
): JsonLDObjectElementBuilder = {
val result = current.merge(other)(ctx)
result
}

override def findClassTerm(ctx: SemanticContext): Seq[String] = {
val terms = super.findClassTerm(ctx).map(ctx.expand)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class JsonLDObjectElementBuilder(location: SourceLocation, key: String, base: St

addClassTerms(other)
other.properties.foreach { case (_, builder) =>
if (!hasBeenParsedWithSameSemantics(builder) && isSubSchemaSemanticDefinition(builder)) {
// TODO: this logic needs revisiting and renaming, hard to understand
if (isSubSchemaSemanticDefinition(builder)) {
val current = properties(builder.key)
val merged = mergeProperties(current, builder)
remove(current)
Expand All @@ -61,10 +62,6 @@ class JsonLDObjectElementBuilder(location: SourceLocation, key: String, base: St
properties.contains(builder.key) && !builder.hasTermWithDefaultBase
}

private def hasBeenParsedWithSameSemantics(property: JsonLDPropertyBuilder) = {
termIndex.getOrElse(property.term, List.empty).contains(property)
}

private def addClassTerms(other: JsonLDObjectElementBuilder): Unit = {
other.classTerms.foreach { t => if (!classTerms.contains(t)) classTerms.prepend(t) }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"@graph": [
{
"@id": "file://amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json#/BaseUnitProcessingData",
"@type": [
"http://a.ml/vocabularies/document#BaseUnitProcessingData"
],
"http://a.ml/vocabularies/document#transformed": false
},
{
"@id": "file://amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json#/encodes/",
"@type": [
"http://a.ml/vocabularies/core#encodes",
"http://a.ml/vocabularies/document#JsonLDObject"
],
"http://prefix.com#d": [
{
"@id": "file://amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json#/encodes/d/0"
}
]
},
{
"@id": "file://amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json#/encodes/d/0",
"@type": [
"http://prefix.com#D",
"http://a.ml/vocabularies/core#d/0",
"http://a.ml/vocabularies/document#JsonLDObject"
],
"http://prefix.com#e": "something"
},
{
"@id": "file://amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json",
"@type": [
"http://a.ml/vocabularies/document#JsonLDInstanceDocument",
"http://a.ml/vocabularies/document#Document",
"http://a.ml/vocabularies/document#Fragment",
"http://a.ml/vocabularies/document#Module",
"http://a.ml/vocabularies/document#Unit"
],
"http://a.ml/vocabularies/document#encodes": [
{
"@id": "file://amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json#/encodes/"
}
],
"http://a.ml/vocabularies/document#root": true,
"http://a.ml/vocabularies/document#processingData": {
"@id": "file://amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json#/BaseUnitProcessingData"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"d": [
{
"e": "something"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "https://json-schema.org/draft-07/schema",
"@context": {
"prefix": "http://prefix.com#",
"d": "prefix:d"
},
"properties": {},
"if": {},
"then": {
"properties": {
"d": {
"type": "array",
"items": {
"$ref": "#/definitions/D"
}
}
}
},
"definitions": {
"D": {
"@context": {
"prefix": "http://prefix.com#",
"@type": "prefix:D",
"e": "prefix:e"
},
"properties": {
"e": {
"type": "string"
}
}
}
}
}