Skip to content

Commit

Permalink
split and merge steps
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec committed Jun 24, 2024
1 parent 90e84d5 commit e1d44be
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions database/util/twoAnalysisSenseCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
},
},
{
// Preserve the original document for later stages to use
$addFields: {
// Preserve the original document for later stages to use
originalDocument: "$$ROOT",

// Identify and extract 'to' and 'from' senses for merging based on gloss languages
},
},
{
// Identify and extract 'to' and 'from' senses for merging based on gloss languages
$addFields: {
toSense: {
$arrayElemAt: [
{
Expand Down Expand Up @@ -55,14 +58,17 @@
0,
],
},

// Add fields to extract semantic domain GUIDs from both 'to' and 'from' senses
},
},
{
// Add fields to extract semantic domain GUIDs from both 'to' and 'from' senses
$addFields: {
toSemDomGuids: "$toSense.SemanticDomains.guid",
fromSemDomGuids: "$fromSense.SemanticDomains.guid",
},
},
{
// Match documents where the semantic domains of 'to' sense are a subset of 'from' sense or 'to' sense has no semantic domains
// Match documents where the semantic domains of 'to' sense are a subset of 'from' sense or vice-versa
$match: {
$expr: {
$or: [
Expand All @@ -77,41 +83,32 @@
},
},
{
// Add fields to extract semantic domain GUIDs from both 'to' and 'from' senses
$addFields: {
semDoms: {
$cond: {
if: {
$gte: [{ $size: "$toSemDomGuids" }, { $size: "$fromSemDomGuids" }],
},
then: "$toSense.SemanticDomains",
else: "$fromSense.SemanticDomains",
},
},
},
},
{
// Merge the senses into one by combining glosses
// Update the original document's senses with a merge of the "to" and "from" senses
$addFields: {
mergedSenses: {
"originalDocument.senses": {
$mergeObjects: [
"$toSense",
{
Glosses: {
$concatArrays: ["$toSense.Glosses", "$fromSense.Glosses"],
},
SemanticDomains: "$semDoms",
SemanticDomains: {
$cond: {
if: {
$gte: [
{ $size: "$toSemDomGuids" },
{ $size: "$fromSemDomGuids" },
],
},
then: "$toSense.SemanticDomains",
else: "$fromSense.SemanticDomains",
},
},
},
],
},
},
},
{
// Update the original document's senses with the merged senses
$addFields: {
"originalDocument.senses": ["$mergedSenses"],
},
},
{
// Replace the root of the document with the updated original document
$replaceRoot: {
Expand Down

0 comments on commit e1d44be

Please sign in to comment.