Skip to content

Commit

Permalink
Merge pull request #1057 from AI4Bharat/noise-tags-master
Browse files Browse the repository at this point in the history
  • Loading branch information
ishvindersethi22 authored Jun 27, 2024
2 parents 4d211f6 + bcbb1b9 commit fd304e1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 33 deletions.
72 changes: 52 additions & 20 deletions src/ui/pages/container/CL-Transcription/TranscriptionRightPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ const TranscriptionRightPanel = ({
const textRefs = useRef([]);
const [currentTextRefIdx, setCurrentTextRefIdx] = useState(null);
const [currentSelection, setCurrentSelection] = useState(null);
const langDictSet = new Set(langDict[targetlang]);

useEffect(() => {
currentPageData?.length && (textRefs.current = textRefs.current.slice(0, (showAcousticText ? 2 : 1) * currentPageData.length));
Expand Down Expand Up @@ -204,6 +205,57 @@ const TranscriptionRightPanel = ({
.querySelector(`#sub_${currentIndex}`)
?.scrollIntoView(true, { block: "start" });
}

if (currentIndex > startIndex) {
const copySub = [...subtitles];
let sub = copySub[currentIndex - 1]
let replacedValue = sub.text.replace(/\[[a-zA-Z]\]/g, '');
let splitText = replacedValue.split(" ");
let invalidCharFlag = 0;
splitText.slice(0, -1).forEach((e) => {
if (RegExp("\<[a-zA-Z\s,_]+\>").test(e)) {
if (e.length > 2) {
if (!TabsSuggestionData.includes(e.slice(1, -1))) {
invalidCharFlag = 1;
}
} else {
invalidCharFlag = 1;
}
}else{
let wordSet = new Set(e);
if (([...wordSet].every(char => langDictSet.has(char))) === false) {
invalidCharFlag = 1;
}
}
});
if(sub.acoustic_normalised_text.length > 0){
let replacedANValue = sub.acoustic_normalised_text.replace(/\[[a-zA-Z]\]/g, '');
let splitANText = replacedANValue.split(" ");
splitANText.slice(0, -1).forEach((e) => {
if (RegExp("\<[a-zA-Z\s,_]+\>").test(e)) {
if (e.length > 2) {
if (!TabsSuggestionData.includes(e.slice(1, -1))) {
invalidCharFlag = 1;
}
} else {
invalidCharFlag = 1;
}
} else {
let wordSet = new Set(e);
if (([...wordSet].every(char => langDictSet.has(char))) === false) {
invalidCharFlag = 1;
}
}
});
}
if (invalidCharFlag) {
setSnackbarInfo({
open: true,
message: "Characters belonging to other language are used",
variant: "error",
});
}
}
}, [currentIndex]);

useEffect(() => {
Expand Down Expand Up @@ -313,26 +365,6 @@ const TranscriptionRightPanel = ({
currentTarget,
} = event;

let langDictSet = new Set(langDict[targetlang]);
let langDictSetEn = new Set(langDict["en"]);

let splitText = value.split(" ");
let invalidCharFlag = 0;
splitText.forEach((e, i) => {
// splitText[i] = [...e].map(char => (langDictSet.has(char) || langDictSetEn.has(char)) ? char : '').join('');
if(([...e].map(char => (langDictSet.has(char) || langDictSetEn.has(char)) ? 1 : 0).join('')).search(0) !== -1){
invalidCharFlag = 1;
}
});

if(invalidCharFlag){
setSnackbarInfo({
open: true,
message: "Characters belonging to other language are used",
variant: "error",
});
}

const containsTripleDollar = value.includes("$$$");

// setEnableTransliterationSuggestion(true);
Expand Down
26 changes: 13 additions & 13 deletions src/ui/pages/container/CL-Transcription/langDict.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fd304e1

Please sign in to comment.