Skip to content

Commit

Permalink
fix textreusecluster label when timedifference is not given
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleguido committed Sep 26, 2024
1 parent 09cb350 commit 052cad0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/components/modules/lists/ItemLabel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default {
? this.$tc('numbers.clusterSize', item.clusterSize, {
n: this.$n(item.clusterSize)
})
: ''
: 'size'
const lexicalOverlapLabel =
item.lexicalOverlap != null
? this.$tc('numbers.lexicalOverlap', item.lexicalOverlap, {
Expand Down Expand Up @@ -134,7 +134,7 @@ export default {
return this.$t('textReuseClusterSummary', {
shortId: item.shortId,
textSampleExcerpt: item.textSampleExcerpt,
clusterSize: clusterSizeLabel,
size: clusterSizeLabel,
lexicalOverlap: lexicalOverlapLabel,
timespan: this.$tc('numbers.days', item.timeDifferenceDay, {
n: item.timeDifferenceDay
Expand Down Expand Up @@ -162,7 +162,7 @@ export default {
"numbers": {
"days": "the same day|over <span class='number'>{n}</span> day|over <span class='number'>{n}</span> days"
},
"textReuseClusterSummary": "cluster <b>{shortId}</b><br/><div>{lexicalOverlap} {timespan} ({dates}).</div><blockquote class='my-1 ml-0 border-left pl-2'>{textSampleExcerpt}</blockquote>"
"textReuseClusterSummary": "cluster <b>{shortId}</b> ({size})<br/><div>{lexicalOverlap} {timespan} ({dates}).</div><blockquote class='my-1 ml-0 border-left pl-2'>{textSampleExcerpt}</blockquote>"
}
}
</i18n>
19 changes: 14 additions & 5 deletions src/models/TextReuseCluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class TextReuseCluster {
minDate = new Date(),
clusterSize = 0,
lexicalOverlap = 0,
connectedClusters = [],
connectedClusters = []
} = {}) {
this.id = String(id)
this.shortId = this.id.split('-').pop()
Expand All @@ -37,9 +37,18 @@ export default class TextReuseCluster {
this.textSampleContent = String(textSampleContent)
this.textSampleExcerpt = String(textSampleExcerpt)
this.textSampleDate = String(textSampleDate)
this.timeDifferenceDay = parseInt(timeDifferenceDay, 10)
this.maxDate = maxDate
this.minDate = minDate
// recalculate timedifferencedya using dates
const computedTimeDifferenceDay = Math.floor(
(this.maxDate - this.minDate) / (24 * 60 * 60 * 1000)
)
if (computedTimeDifferenceDay !== timeDifferenceDay) {
console.warn('recalculating timeDifferenceDay', this.timeDifferenceDay, timeDifferenceDay)
this.timeDifferenceDay = computedTimeDifferenceDay
} else {
this.timeDifferenceDay = timeDifferenceDay
}
this.clusterSize = parseInt(clusterSize, 10)
this.connectedClusters = connectedClusters
this.lexicalOverlap = parseFloat(lexicalOverlap)
Expand All @@ -48,7 +57,7 @@ export default class TextReuseCluster {
static fromSolrResponse(response) {
return response.map(cluster => {
return new TextReuseCluster({
id: cluster.id,
id: cluster.id
})
})
}
Expand All @@ -62,7 +71,7 @@ export default class TextReuseCluster {

const maxDate = new Date(item.date)
const minDate = new Date(
+maxDate - item.textReuseCluster.timeDifferenceDay * 24 * 60 * 60 * 1000,
+maxDate - item.textReuseCluster.timeDifferenceDay * 24 * 60 * 60 * 1000
)
return new TextReuseCluster({
id: item.textReuseCluster.id,
Expand All @@ -77,7 +86,7 @@ export default class TextReuseCluster {
minDate,
clusterSize: item.textReuseCluster.clusterSize,
lexicalOverlap: item.textReuseCluster.lexicalOverlap,
connectedClusters: item.connectedClusters,
connectedClusters: item.connectedClusters
})
}
}

0 comments on commit 052cad0

Please sign in to comment.