Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 | 64x 64x 64x 64x 64x 64x 86x 86x 64x 64x 64x 64x 20x 3x 3x 3x 3x 3x 3x 12x 12x 228x 228x 12x 12x 12x 12x 12x 7x 12x 12x 3x 18x 18x 18x 18x 18x 18x 18x 3x 17x 64x 52x 2x 2x 1x 1x 1x 2x 5x 26x 158x 26x 26x 54x 2x 2x 2x 12x 20x 20x 2x 2x 6x 2x 2x 2x 2x 2x 2x 2x 2x 10x 2x 2x 2x 8x 8x 8x 8x 2x 2x 2x 2x 2x 8x 2x 1x 1x 4x 1x 2x 8x 8x 20x 1458x 1458x 1458x 1458x 28x 10x 10x 8x 20x 28x 20x 6x 6x 6x 6x 6x 2182x 6x 3x 3x 6x 6x 6x 6x 44x 44x 44x 44x 44x 28x 28x 16x 16x 6x 6x 6x 28x 28x 22x 134x 104x 10x 16x 16x 52x 44x 644x 104x 104x 104x 50x 50x 50x 554x 1954x 1954x 2x 8x 8x 8x 8x | import {
Autocomplete,
Box,
Button,
CircularProgress,
IconButton,
Link,
List,
ListItem,
ListItemIcon,
ListSubheader,
MenuItem,
Stack,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TablePagination,
TableRow,
TextField,
Tooltip,
Typography,
} from '@mui/material'
import {relativeFrequency, sortByLength} from './lib/utils'
import {type ChangeEvent, useContext, useState, useMemo, useCallback, useEffect, Fragment} from 'react'
import {ResourceContext, type Synset} from './resources'
import {BuildContext, BuildEditContext, type DictionaryActions, termsByCategory, type NumberObject} from './building'
import {InfoDrawerActions, InfoDrawerSetter} from './infoDrawer'
import {SynsetLink, unpackSynsetMembers} from './synset'
import {extractExpanded} from './wordParts'
import {getFuzzyParent, getProcessedTerm} from './processTerms'
import {Add, ArrowDownward, ArrowUpward, Check, LensBlur, Remove} from '@mui/icons-material'
import type {Dict} from './storage'
type LogicalObject = {[index: string]: boolean}
export type NetworkLookup = {
expanded: boolean
map: Map<string, boolean>
any: LogicalObject
lemma: LogicalObject
lemma_map: Map<string, boolean>
lemma_related: LogicalObject
lemma_synset: LogicalObject
related: LogicalObject
related_map: Map<string, boolean>
related_lemma: LogicalObject
related_related: LogicalObject
related_synset: LogicalObject
synset: LogicalObject
synset_map: Map<string, boolean>
synset_lemma: LogicalObject
synset_related: LogicalObject
synset_synset: LogicalObject
}
export type FixedTerm = {
type: 'fixed'
term_type: 'fixed'
term: string
recognized: boolean
index: number
lemma: string[]
forms?: string[]
related: string[]
synsets: Synset[]
synset_terms: string[]
frequency?: number
in_dict?: boolean
lookup: NetworkLookup
}
export type FuzzyTerm = {
type: 'fuzzy'
term_type: 'glob' | 'regex'
term: string
categories: {[index: string]: number}
recognized: boolean
regex: RegExp
matches: string[]
common_matches?: string[]
}
export function TermSenseEdit({
id,
field,
processed,
label,
editCell,
}: {
processed: FixedTerm | FuzzyTerm
id: string
field: string
label?: string
editCell?: (params: {id: string; field: string; value: string}) => void
}) {
const Dict = useContext(BuildContext)
const edit = useContext(BuildEditContext)
const dictEntry = Dict[id || processed.term]
const data = useContext(ResourceContext)
const {terms, senseMap, sense_keys, synsetInfo} = data
const getCoarseSense = useCallback(
(key: string, synset: Synset) => {
const labels = key in senseMap ? senseMap[key] : synset.csi_labels
return 'string' === typeof labels ? labels : labels[0]
},
[senseMap],
)
const [open, setOpen] = useState(false)
const [rankedSynsets, setRankedSynsets] = useState<{key: string; score: number; synset: Synset}[]>([])
const loading = open && !rankedSynsets.length
useEffect(() => {
if (open && terms && sense_keys && synsetInfo && processed.type === 'fixed' && processed.synsets.length) {
const getRanked = async () => {
const siblings = termsByCategory(Object.keys(dictEntry.categories), Dict)
const siblingsExtended: {[index: string]: boolean} = {}
Object.keys(siblings).forEach(id => {
const processed = getProcessedTerm(id, data, Dict, true) as FixedTerm
if (processed.lookup) processed.lookup.map.forEach((_, ext) => (siblingsExtended[ext] = true))
})
const clusterRanks: NumberObject = {}
const out = processed.synsets.map(synset => {
let score = 0
unpackSynsetMembers(synset, terms, synsetInfo).forEach(term => {
Iif (term in siblings) score++
Iif (term in siblingsExtended) score += 0.01
})
if (synset.count) score += synset.count * 0.001
if (!synset.csi_labels) synset.csi_labels = 'no category'
const key = sense_keys[synset.index]
const cluster = getCoarseSense(key, synset)
if (!(cluster in clusterRanks) || clusterRanks[cluster] < score) {
clusterRanks[cluster] = score
}
return {key, score, synset}
})
const synsetCategories = out.map(({key, synset}) => getCoarseSense(key, synset)).sort()
setRankedSynsets(
out.sort((a, b) => {
const clusterA = getCoarseSense(a.key, a.synset)
const clusterRankA = clusterRanks[clusterA]
const clusterNameA = -synsetCategories.indexOf(clusterA)
const clusterB = getCoarseSense(b.key, b.synset)
const clusterRankB = clusterRanks[clusterB]
const clusterNameB = -synsetCategories.indexOf(clusterB)
return (
clusterRankB * 100 +
clusterNameB * 0.1 +
b.score * 0.01 -
(clusterRankA * 100 + clusterNameA * 0.1 + a.score * 0.01)
)
}),
)
}
setTimeout(getRanked, 150)
} else {
setRankedSynsets([])
}
}, [open, terms, senseMap, sense_keys, synsetInfo, processed, Dict, data, dictEntry, getCoarseSense])
if (terms && sense_keys && synsetInfo && processed.type === 'fixed' && processed.synsets.length) {
return (
<Autocomplete
size="small"
slotProps={{
popper: {className: 'synset-select'},
listbox: {
style: {cursor: 'pointer'},
onClick: e => {
const target = e.target
if ('tagName' in target && 'innerText' in target && target.tagName === 'DIV') {
const newValue = target.innerText as string
Iif (editCell) editCell({id, field, value: newValue})
edit({
type: 'update',
term_id: id,
term: processed.term,
term_type: processed.term_type,
sense: newValue,
})
}
},
},
}}
options={rankedSynsets}
loading={loading}
open={open}
onOpen={() => setOpen(true)}
onClose={() => setOpen(false)}
value={dictEntry.sense}
groupBy={rank => getCoarseSense(rank.key, rank.synset)}
getOptionLabel={option => ('string' === typeof option ? option : option.key)}
renderOption={(props, rank) => {
const {key, synset, score} = rank
return (
<MenuItem {...props} key={key} value={key}>
<Tooltip title={synset.definition} placement="right">
<Typography sx={{width: '100%'}}>
<span className="number-annotation">{'(' + score.toFixed(2) + ') '}</span>
{sense_keys[synset.index]}
{synset.count && <span className="number-annotation">{' ' + synset.count}</span>}
</Typography>
</Tooltip>
</MenuItem>
)
}}
renderInput={params => (
<TextField
label={label}
{...params}
slotProps={{
input: {
...params.InputProps,
endAdornment: (
<Fragment>
{loading && <CircularProgress size={20} />}
{params.InputProps.endAdornment}
</Fragment>
),
},
}}
></TextField>
)}
onChange={(_, value) => {
const newValue = (value && 'object' === typeof value && value.key) || ''
Eif (editCell) editCell({id, field, value: newValue})
edit({
type: 'update',
term_id: id,
term: processed.term,
term_type: processed.term_type,
sense: newValue,
})
}}
autoSelect
blurOnSelect
selectOnFocus
clearOnEscape
handleHomeEndKeys
fullWidth
freeSolo
></Autocomplete>
)
} else {
return (
<TextField
size="small"
value={dictEntry.sense}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
if (editCell) editCell({id, field, value: e.target.value})
edit({
type: 'update',
term_id: id,
term: processed.term,
term_type: processed.term_type,
sense: e.target.value,
})
}}
label={label}
></TextField>
)
}
}
const columns = ['Match', 'Frequency', 'Senses', 'Related', 'In Dictionary'] as const
const arrowStyle = {position: 'absolute', fontSize: '1.5em', height: '1.2em', opacity: 0.4}
function sortByField({column, asc}: {column: string; asc: boolean}) {
switch (column) {
case 'Match':
return asc ?
(a: FixedTerm, b: FixedTerm) => {
return a.term > b.term ? -1 : 1
}
: (a: FixedTerm, b: FixedTerm) => {
return b.term > a.term ? -1 : 1
}
case 'Frequency':
return asc ?
(a: FixedTerm, b: FixedTerm) => {
return (a.frequency || 0) - (b.frequency || 0)
}
: (a: FixedTerm, b: FixedTerm) => {
return (b.frequency || 0) - (a.frequency || 0)
}
case 'Senses':
return asc ?
(a: FixedTerm, b: FixedTerm) => {
return a.synsets.length - b.synsets.length
}
: (a: FixedTerm, b: FixedTerm) => {
return b.synsets.length - a.synsets.length
}
case 'Related':
return asc ?
(a: FixedTerm, b: FixedTerm) => {
return a.related.length - b.related.length
}
: (a: FixedTerm, b: FixedTerm) => {
return b.related.length - a.related.length
}
case 'In Dictionary':
return asc ?
(a: FixedTerm, b: FixedTerm) => {
return (a.in_dict || 0) > (b.in_dict || 0) ? -1 : 1
}
: (a: FixedTerm, b: FixedTerm) => {
return (b.in_dict || 0) > (a.in_dict || 0) ? -1 : 1
}
}
}
function TermFuzzy({processed}: {processed: FuzzyTerm}) {
const dict = useContext(BuildContext)
const editDictionary = useContext(BuildEditContext)
const data = useContext(ResourceContext)
const [page, setPage] = useState(0)
const [perPage, setPerPage] = useState(10)
const [sortCol, setSortCol] = useState({column: 'Frequency', asc: false})
const cols = useMemo(
() => [
<TableCell key="term_action" width={1}></TableCell>,
...columns.map(col => (
<TableCell
key={col}
width={col === 'Match' ? 999 : 1}
component="th"
align={col === 'Match' ? 'left' : 'right'}
sx={{cursor: 'pointer', pr: 3}}
onClick={() => {
const alreadySorting = sortCol.column === col
setSortCol(
alreadySorting && sortCol.asc ?
{column: 'Frequency', asc: false}
: {column: col, asc: sortCol.column === col},
)
}}
>
{col}
{sortCol.column === col ?
sortCol.asc ?
<ArrowUpward sx={arrowStyle} />
: <ArrowDownward sx={arrowStyle} />
: <></>}
</TableCell>
)),
],
[setSortCol, sortCol],
)
const nMatches = processed.matches.length
const processedMatches = useMemo(() => {
return processed.matches.map(term => {
const p = getProcessedTerm(term, data) as FixedTerm
p.frequency = relativeFrequency(p.index, data.terms && data.terms.length)
p.in_dict = p.term in dict
return p
})
}, [processed, data, dict])
Iif (page > nMatches / perPage) {
setPage(0)
return <></>
}
processedMatches.sort(sortByField(sortCol))
const pageMatches: FixedTerm[] = []
Eif (nMatches) {
for (let i = page * perPage, n = Math.min(processedMatches.length, i + perPage); i < n; i++) {
pageMatches.push(processedMatches[i])
}
}
if (!processed.common_matches) {
let root = ''
processed.matches.forEach(match => {
if (!root || match.length < root.length) root = match
})
processed.common_matches = extractExpanded(root, ';;' + processed.matches.join(';;') + ';;')
}
return nMatches ?
<TableContainer sx={{height: '100%', position: 'relative'}}>
<Table stickyHeader size="small">
<TableHead>
<TableRow>{cols}</TableRow>
</TableHead>
<TableBody>
{pageMatches.map((processedMatch, index) => {
const match = processedMatch.term
return (
<TableRow key={match + index} sx={{height: 33}} hover>
<TableCell sx={{p: 0}}>
{processedMatch.in_dict ?
<IconButton
aria-label="remove"
size="small"
edge="start"
sx={{p: 0, opacity: 0.6}}
onClick={() => {
editDictionary({type: 'remove', term_id: match})
}}
>
<Remove />
</IconButton>
: <IconButton
aria-label="add"
size="small"
edge="start"
sx={{p: 0, opacity: 0.6}}
onClick={() => {
editDictionary({type: 'add', term_id: match, term: match, term_type: 'fixed'})
}}
>
<Add />
</IconButton>
}
</TableCell>
<TableCell>{<TermLink term={match}></TermLink>}</TableCell>
<TableCell align="right">
{(processedMatch.frequency && processedMatch.frequency.toFixed(2)) || '0.00'}
</TableCell>
<TableCell align="right">{processedMatch.synsets.length}</TableCell>
<TableCell align="right">{processedMatch.related.length}</TableCell>
<TableCell align="right">{processedMatch.in_dict ? 'yes' : 'no'}</TableCell>
</TableRow>
)
})}
</TableBody>
</Table>
<TablePagination
sx={{width: '100%', bottom: '-1px', position: 'sticky', backgroundColor: '#1e1e1e'}}
component="div"
rowsPerPageOptions={[10, 20, 50, 100, 1000]}
count={nMatches}
rowsPerPage={perPage}
page={page}
onPageChange={(_, page: number) => {
setPage(page)
}}
onRowsPerPageChange={(e: ChangeEvent<HTMLInputElement>) => {
setPerPage(parseInt(e.target.value))
setPage(0)
}}
/>
</TableContainer>
: <Typography>No matches</Typography>
}
const iconStyle = {minWidth: '20px', opacity: 0.9, '& .MuiSvgIcon-root': {fontSize: '1em'}}
export function termListItem(
id: string,
dict: Dict,
editor: (action: DictionaryActions) => void,
showTerm: (action: InfoDrawerActions) => void,
) {
const capturedBy = getFuzzyParent(id)
const inCurrent = id in dict
const term = (inCurrent && dict[id].term) || id
return (
<ListItem
key={id}
disableGutters
disablePadding
sx={{pr: 3}}
secondaryAction={
inCurrent ?
<IconButton
aria-label="remove"
size="small"
edge="end"
sx={iconStyle}
onClick={() => {
editor({type: 'remove', term_id: id})
}}
>
<Remove />
</IconButton>
: <IconButton
aria-label="add"
size="small"
edge="end"
sx={iconStyle}
onClick={() => {
editor({type: 'add', term_id: id, term, term_type: 'fixed'})
}}
>
<Add />
</IconButton>
}
>
<ListItemIcon sx={iconStyle}>
{inCurrent ?
<Tooltip title="in current dictionary" placement="left">
<Check color="success" />
</Tooltip>
: capturedBy && capturedBy in dict ?
<Tooltip title={'captured by ' + capturedBy + ' in current dictionary'} placement="left">
<IconButton
sx={{p: 0, '& .MuiSvgIcon-root': {fontSize: '.7em'}}}
onClick={() => {
showTerm({type: 'add', state: {type: 'term', value: capturedBy}})
}}
>
<LensBlur color="secondary" />
</IconButton>
</Tooltip>
: <></>}
</ListItemIcon>
<TermLink term={term}></TermLink>
</ListItem>
)
}
function formatLink(id: string) {
switch (id.substring(0, 1)) {
case 'd':
return 'https://wikidata.org/wiki/' + id.substring(2)
case 'p':
return 'https://dbpedia.org/resource/' + id.substring(2)
case 'w':
return 'https://en.wiktionary.org/wiki/' + id.substring(2)
}
}
const linkNames = {d: 'Wikidata', p: 'DBpedia', w: 'Wiktionary'}
function formatLinkName(id: string) {
return linkNames[id.substring(0, 1) as 'd' | 'p' | 'w'] + ': ' + id.substring(2)
}
const capitalLetter = /([A-Z])/g
function TermFixed({processed}: {processed: FixedTerm}) {
const containerStyle = {p: 1, pl: 0, maxHeight: '100%', overflowY: 'auto', overflowX: 'hidden', whiteSpace: 'nowrap'}
const dict = useContext(BuildContext)
const editDictionary = useContext(BuildEditContext)
const updateInfoDrawerState = useContext(InfoDrawerSetter)
const {terms, senseMap, conceptNet, termLookup, collapsedTerms, sense_keys} = useContext(ResourceContext)
const byIndex = termLookup ? (a: string, b: string) => termLookup[a] - termLookup[b] : () => 0
if (!processed.forms) {
processed.forms = extractExpanded(processed.term, collapsedTerms ? collapsedTerms.all : '')
processed.forms.sort(sortByLength)
}
const synset_clusters: {[index: string]: Synset[]} = {}
const clusterMax: {[index: string]: number} = {}
Eif (processed.synsets) {
processed.synsets.map(synset => {
const key = sense_keys ? sense_keys[synset.index] : ''
const labels = key in senseMap ? senseMap[key] : synset.csi_labels || 'no category'
const label = 'string' === typeof labels ? labels : labels[0]
const count = synset.count || 0
if (label in synset_clusters) {
synset_clusters[label].push(synset)
if (count > clusterMax[label]) clusterMax[label] = count
} else {
synset_clusters[label] = [synset]
clusterMax[label] = count
}
})
}
const concept = conceptNet && conceptNet.terms['' + (processed.index + 1)]
const links = conceptNet && conceptNet.links['' + (processed.index + 1)]
return (
<Stack direction="row" spacing={2} sx={{height: '100%', pb: 1}}>
<Stack>
<Tooltip title="100 - index / n terms * 100; terms are loosely sorted by frequency and space coverage">
<Typography>Frequency</Typography>
</Tooltip>
<Box sx={{p: 1}}>
<span className="number">{relativeFrequency(processed.index, terms && terms.length).toFixed(2)}</span>
</Box>
{(!!concept || !!processed.synsets.length || !!links) && (
<>
<Typography>Sources</Typography>
<Box sx={{p: 1}}>
<List sx={{p: 0, fontSize: '.8em', whiteSpace: 'nowrap', '& a': {cursor: 'pointer'}}}>
{!!concept && (
<ListItem disableGutters disablePadding>
<Link
href={'https://conceptnet.io/c/en/' + processed.term.replace(' ', '_')}
target="_blank"
rel="noreferrer"
>
ConceptNet
</Link>
</ListItem>
)}
{!!processed.synsets.length && (
<ListItem disableGutters disablePadding>
<Link href={'https://en-word.net/lemma/' + processed.term} target="_blank" rel="noreferrer">
OEWordNet
</Link>
</ListItem>
)}
{links &&
('string' === typeof links ? [links] : links).map(link => (
<ListItem key={link} disableGutters disablePadding>
<Link href={formatLink(link)} target="_blank" rel="noreferrer">
{formatLinkName(link)}
</Link>
</ListItem>
))}
</List>
</Box>
</>
)}
</Stack>
{terms && !!processed.lemma.length && (
<Stack>
<Tooltip title="Term forms produced by lemmatizing original terms with the RNNTagger, the grouping by root.">
<Typography>Lemmatizer</Typography>
</Tooltip>
<Box sx={containerStyle}>
<List disablePadding sx={{p: 0}}>
{processed.lemma
.filter(term => term !== processed.term)
.map(term => termListItem(term, dict, editDictionary, updateInfoDrawerState))}
</List>
</Box>
</Stack>
)}
{!!processed.forms.length && (
<Stack>
<Tooltip title="Term forms produced by rule-based matches (e.g., with added or removed common affixes) to other terms.">
<Typography>Expansion</Typography>
</Tooltip>
<Box sx={containerStyle}>
<List disablePadding sx={{p: 0}}>
{processed.forms.map(term => termListItem(term, dict, editDictionary, updateInfoDrawerState))}
</List>
</Box>
</Stack>
)}
{!!processed.related.length && (
<Stack>
<Tooltip title="Similar terms within latent semantic spaces (embeddings); based on top 100 terms across a proportion of different spaces.">
<Typography>Related Terms</Typography>
</Tooltip>
<Box sx={containerStyle}>
<List disablePadding sx={{p: 0}}>
{processed.related.map(term => termListItem(term, dict, editDictionary, updateInfoDrawerState))}
</List>
</Box>
</Stack>
)}
{sense_keys && !!processed.synsets.length && (
<>
<Stack>
<Typography>Senses</Typography>
<Box sx={{...containerStyle, p: 0}}>
<List subheader={<li />} className="term-sense-list">
{Object.keys(synset_clusters)
.sort((a, b) => {
return clusterMax[b] - clusterMax[a]
})
.map(cluster => {
const infos = synset_clusters[cluster]
return (
<li key={cluster}>
<ul>
<ListSubheader>{cluster}</ListSubheader>
{infos
.sort((a, b) => {
return (b.count || 0) - (a.count || 0)
})
.map((info, i) => (
<ListItem key={i} disablePadding>
<SynsetLink senseKey={sense_keys[info.index]} info={info} />
</ListItem>
))}
</ul>
</li>
)
})}
</List>
</Box>
</Stack>
{!!processed.synset_terms.length && (
<Stack>
<Typography sx={{whiteSpace: 'nowrap'}}>Extended Synset Members</Typography>
<Box sx={containerStyle}>
<List disablePadding sx={{p: 0}}>
{processed.synset_terms
.sort(byIndex)
.map(term => termListItem(term, dict, editDictionary, updateInfoDrawerState))}
</List>
</Box>
</Stack>
)}
</>
)}
{concept && terms && (
<Stack direction="row" spacing={2}>
{Object.keys(concept)
.sort((a, b) => {
const ca = concept[a]
const cb = concept[b]
return ('number' === typeof cb ? 1 : cb.length) - ('number' === typeof ca ? 1 : ca.length)
})
.map(k => {
const entry = concept[k]
const conceptTerms = 'number' === typeof entry ? [entry] : entry
return (
<Stack key={k}>
<Typography sx={{whiteSpace: 'nowrap'}}>{k.replace(capitalLetter, ' $&').trimStart()}</Typography>
<Box sx={containerStyle}>
<List disablePadding sx={{p: 0}}>
{conceptTerms.map(index =>
termListItem(terms[index - 1], dict, editDictionary, updateInfoDrawerState),
)}
</List>
</Box>
</Stack>
)
})}
</Stack>
)}
</Stack>
)
}
export function TermLink({term}: {term: string}) {
const updateInfoDrawerState = useContext(InfoDrawerSetter)
return (
<Button
fullWidth
variant="text"
sx={{p: 0, justifyContent: 'flex-start', textTransform: 'none', whiteSpace: 'nowrap'}}
onClick={() => updateInfoDrawerState({type: 'add', state: {type: 'term', value: term}})}
>
{term}
</Button>
)
}
export function TermDisplay({term}: {term: string}) {
const data = useContext(ResourceContext)
const dict = useContext(BuildContext)
const processed = getProcessedTerm(term, data, dict)
return processed.type === 'fixed' ? <TermFixed processed={processed} /> : <TermFuzzy processed={processed} />
}
|