Skip to content

Commit

Permalink
Merge pull request #1718 from aml-org/jsonld-schema-fix
Browse files Browse the repository at this point in the history
(fix): properties with same semantics but different sub tree weren't being merged
  • Loading branch information
tomsfernandez authored Feb 1, 2023
2 parents 7344d13 + 567a4b0 commit b29dae1
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 6 deletions.
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"
}
}
}
}
}

0 comments on commit b29dae1

Please sign in to comment.