-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated to use SourceDocumentDataRead when necessary
- Loading branch information
Showing
16 changed files
with
161 additions
and
101 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
26 changes: 16 additions & 10 deletions
26
frontend/src/components/SourceDocument/SdocSentenceRenderer.tsx
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 |
---|---|---|
@@ -1,32 +1,38 @@ | ||
import { SourceDocumentDataRead } from "../../api/openapi/models/SourceDocumentDataRead.ts"; | ||
import SdocHooks from "../../api/SdocHooks.ts"; | ||
import { SourceDocumentWithDataRead } from "../../api/openapi/models/SourceDocumentWithDataRead.ts"; | ||
|
||
interface SdocSentenceRendererProps { | ||
sdoc: number | SourceDocumentWithDataRead; | ||
sdoc: number | SourceDocumentDataRead; | ||
sentenceId: number; | ||
} | ||
|
||
function SdocSentenceRenderer({ sdoc, sentenceId }: SdocSentenceRendererProps) { | ||
if (typeof sdoc === "number") { | ||
return <SdocSentenceRendererWithoutData sdocId={sdoc} sentenceId={sentenceId} />; | ||
} | ||
return <SdocSentenceRendererWithData sdoc={sdoc} sentenceId={sentenceId} />; | ||
return <SdocSentenceRendererWithData sdocData={sdoc} sentenceId={sentenceId} />; | ||
} | ||
|
||
function SdocSentenceRendererWithoutData({ sdocId, sentenceId }: { sdocId: number; sentenceId: number }) { | ||
const sdoc = SdocHooks.useGetDocument(sdocId); | ||
const sdocData = SdocHooks.useGetDocumentData(sdocId); | ||
|
||
if (sdoc.isSuccess) { | ||
return <SdocSentenceRendererWithData sdoc={sdoc.data} sentenceId={sentenceId} />; | ||
} else if (sdoc.isError) { | ||
return <div>{sdoc.error.message}</div>; | ||
if (sdocData.isSuccess) { | ||
return <SdocSentenceRendererWithData sdocData={sdocData.data} sentenceId={sentenceId} />; | ||
} else if (sdocData.isError) { | ||
return <div>{sdocData.error.message}</div>; | ||
} else { | ||
return <div>Loading...</div>; | ||
} | ||
} | ||
|
||
function SdocSentenceRendererWithData({ sdoc, sentenceId }: { sdoc: SourceDocumentWithDataRead; sentenceId: number }) { | ||
return <>{sdoc.sentences[sentenceId]}</>; | ||
function SdocSentenceRendererWithData({ | ||
sdocData, | ||
sentenceId, | ||
}: { | ||
sdocData: SourceDocumentDataRead; | ||
sentenceId: number; | ||
}) { | ||
return <>{sdocData.sentences[sentenceId]}</>; | ||
} | ||
|
||
export default SdocSentenceRenderer; |
26 changes: 26 additions & 0 deletions
26
frontend/src/views/analysis/AnnotatedSegments/HighlightTokenRenderer.tsx
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,26 @@ | ||
import { useMemo } from "react"; | ||
import { SourceDocumentDataRead } from "../../../api/openapi/models/SourceDocumentDataRead.ts"; | ||
|
||
interface HighlightTokenRendererProps { | ||
beginToken: number; | ||
endToken: number; | ||
contextSize: number; | ||
sdocData: SourceDocumentDataRead; | ||
} | ||
|
||
function HighlightTokenRenderer({ beginToken, endToken, contextSize, sdocData }: HighlightTokenRendererProps) { | ||
const tokens = sdocData.tokens; | ||
const { textBefore, textHighlight, textAfter } = useMemo(() => { | ||
const textBefore = tokens.slice(beginToken - contextSize, beginToken).join(" "); | ||
const textHighlight = tokens.slice(beginToken, endToken).join(" "); | ||
const textAfter = tokens.slice(endToken, endToken + contextSize).join(" "); | ||
return { textBefore, textHighlight, textAfter }; | ||
}, [tokens, beginToken, endToken, contextSize]); | ||
return ( | ||
<> | ||
{textBefore} <strong>{textHighlight}</strong> {textAfter} | ||
</> | ||
); | ||
} | ||
|
||
export default HighlightTokenRenderer; |
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
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
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
Oops, something went wrong.