-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from parabible/task/denormalize-text
Denormalize matchingText in text and termSearch endpoints
- Loading branch information
Showing
4 changed files
with
96 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export const mapTextResult = ( | ||
parallelTextQueryResultRow: ParallelTextQueryResultRow, | ||
): DisambiguatedTextResult => { | ||
const { parallelId, moduleId, rid, text } = parallelTextQueryResultRow; | ||
try { | ||
const maybeWordArray = JSON.parse(text); | ||
if (Array.isArray(maybeWordArray)) { | ||
return { | ||
parallelId, | ||
moduleId, | ||
rid, | ||
type: "wordArray", | ||
wordArray: maybeWordArray, | ||
html: "", | ||
}; | ||
} | ||
} catch (e) { | ||
// Ignore this path. | ||
|
||
// We can't return here because we need to handle the text being | ||
// HTML but JSON.parse also succeeding (so the output is not the | ||
// expected array), e.g. if the text is surrounded in quotes. | ||
} | ||
return { parallelId, moduleId, rid, type: "html", wordArray: [], html: text }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters