Skip to content

Commit

Permalink
fix: Take language into account when checking for duplicate TextValues (
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone authored Oct 21, 2024
1 parent fc86f5b commit 7eeb9a2
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,8 @@ case class TextValueContentV2(
mapping: Option[MappingXMLtoStandoff] = None,
xslt: Option[String] = None,
comment: Option[String] = None,
) extends ValueContentV2 {
) extends ValueContentV2 { self =>

override def valueType: SmartIri = {
implicit val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance
OntologyConstants.KnoraBase.TextValue.toSmartIri.toOntologySchema(ontologySchema)
Expand Down Expand Up @@ -1624,7 +1625,9 @@ case class TextValueContentV2(
// It doesn't make sense for a resource to have two different text values associated with the same property,
// containing the same text but different markup.
that match {
case thatTextValue: TextValueContentV2 => valueHasString == thatTextValue.valueHasString
case other: TextValueContentV2 =>
self.valueHasString == other.valueHasString &&
self.valueHasLanguage == other.valueHasLanguage

case _ => throw AssertionException(s"Can't compare a <$valueType> to a <${that.valueType}>")
}
Expand All @@ -1633,16 +1636,15 @@ case class TextValueContentV2(
// It's OK to add a new version of a text value as long as something has been changed in it, even if it's only the markup
// or the comment.
currentVersion match {
case thatTextValue: TextValueContentV2 =>
val valueHasStringIdentical: Boolean = valueHasString == thatTextValue.valueHasString

val mappingIdentitcal = mappingIri == thatTextValue.mappingIri

case other: TextValueContentV2 =>
// compare standoff nodes (sort them first by index) and the XML-to-standoff mapping IRI
val standoffIdentical = StandoffTagUtilV2.makeComparableStandoffCollection(standoff) == StandoffTagUtilV2
.makeComparableStandoffCollection(thatTextValue.standoff)
.makeComparableStandoffCollection(other.standoff)

valueHasStringIdentical && standoffIdentical && mappingIdentitcal && comment == thatTextValue.comment
wouldDuplicateOtherValue(currentVersion) &&
self.mappingIri == other.mappingIri &&
self.comment == other.comment &&
standoffIdentical

case _ => throw AssertionException(s"Can't compare a <$valueType> to a <${currentVersion.valueType}>")
}
Expand Down

0 comments on commit 7eeb9a2

Please sign in to comment.