Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ __pycache__/
*.pyo
.venv/
*.egg-info/
.ipynb_checkpoints/
12 changes: 8 additions & 4 deletions packages/core/src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,13 @@ export function docFromBlocks(blocks: Array<{ type?: string } & UttSpec>): Node
return docFromUtterances(blocks)
}

function _ensureUttTier(store: AnnotationStore) {
return store.allTiers().find(t => t.isUttTier)
?? store.addTier('utterance', { isUttTier: true })
function _ensureUttTier(store: AnnotationStore, participant: string, tierId?: string | null) {
if (tierId) {
const tier = store.getTier(tierId)
if (tier?.isUttTier) return tier
}
return store.allTiers().find(t => t.isUttTier && t.participant === participant)
?? store.addTier(participant, { isUttTier: true, participant })
}

/**
Expand Down Expand Up @@ -211,7 +215,7 @@ export function createUttSyncPlugin(store: AnnotationStore, yjsSyncKey?: PluginK

const existing = store.getAnnotation(id)
if (!existing) {
const tier = _ensureUttTier(store)
const tier = _ensureUttTier(store, node.attrs.participant as string, node.attrs.tierId as string | null)
store.addAnnotation('', anchors, { tierId: tier.id }, id)
} else {
const oldNode = oldUtts.get(id)
Expand Down
45 changes: 43 additions & 2 deletions packages/core/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ const utteranceNode: NodeSpec = {
attrs: {
id: { default: null },
tier: { default: '' },
tierId: { default: null },
participant: { default: '' },
startTimeSeconds: { default: null },
endTimeSeconds: { default: null },
continuationOfId: { default: null },
},
toDOM(node) {
return ['p', {
class: 'utt',
'data-id': node.attrs.id,
'data-tier': node.attrs.tier,
...(node.attrs.tierId ? { 'data-tier-id': node.attrs.tierId } : {}),
'data-participant': node.attrs.participant,
...(node.attrs.continuationOfId ? { 'data-continuation-of': node.attrs.continuationOfId } : {}),
}, 0]
},
parseDOM: [{
Expand All @@ -28,7 +32,9 @@ const utteranceNode: NodeSpec = {
return {
id: el.getAttribute('data-id'),
tier: el.getAttribute('data-tier') ?? '',
tierId: el.getAttribute('data-tier-id') ?? null,
participant: el.getAttribute('data-participant') ?? '',
continuationOfId: el.getAttribute('data-continuation-of') ?? null,
}
},
}],
Expand Down Expand Up @@ -313,16 +319,51 @@ const commentNode: NodeSpec = {
}],
}

const utteranceWithOverlap = { ...utteranceNode, content: '(text | overlap_bracket | inline_ann)*' }
const anchorNode: NodeSpec = {
inline: true,
atom: true,
selectable: true,
group: 'inline',
attrs: {
id: {},
delimiter: {},
kind: {}, // 'start' | 'end'
},
toDOM(node) {
const kind = node.attrs.kind as string
return ['span', {
class: `anchor-node anchor-node--${kind}`,
'data-anchor-id': node.attrs.id,
'data-anchor-delimiter': node.attrs.delimiter,
'data-anchor-kind': kind,
contenteditable: 'false',
title: `anchor ${kind}: ${node.attrs.id as string}`,
}, node.attrs.delimiter as string]
},
parseDOM: [{
tag: 'span.anchor-node',
getAttrs(dom) {
const el = dom as Element
return {
id: el.getAttribute('data-anchor-id') ?? '',
delimiter: el.getAttribute('data-anchor-delimiter') ?? '*',
kind: el.getAttribute('data-anchor-kind') ?? 'start',
}
},
}],
}

const utteranceWithInlines = { ...utteranceNode, content: '(text | overlap_bracket | anchor | inline_ann)*' }

export const schema = new Schema({
nodes: {
doc: { content: '(utterance | visualization | comment)+' },
text: { group: 'inline' },
utterance: utteranceWithOverlap,
utterance: utteranceWithInlines,
visualization: visualizationNode,
comment: commentNode,
overlap_bracket: overlapBracketNode,
anchor: anchorNode,
image: imageNode,
inline_ann: inlineAnnNode,
},
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export interface SlotSchema {
label?: string
variadic?: boolean
style?: import('./types.js').SlotTextStyle
anchorKind: 'span' | 'utterance' | 'pattern' | 'any'
anchorKind: 'textlet' | 'utterance' | 'tier' | 'pattern' | 'any'
tierId?: ID
required?: boolean
metrics: MetricSchema[]
}
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export interface TierDefJSON {
inlineGloss?: boolean
/** If set, tier lane renders as a track visualization backed by this track. */
trackRef?: { trackSetId: ID; trackId: ID }
/** If true, this tier mirrors PM utterance/block nodes for one participant. */
isUttTier?: boolean
}

export interface LinguisticTypeJSON {
Expand Down Expand Up @@ -99,7 +101,8 @@ export interface SlotSchemaJSON {
id: ID
name: string
label?: string
anchorKind: 'span' | 'utterance' | 'pattern' | 'any'
anchorKind: 'textlet' | 'utterance' | 'tier' | 'pattern' | 'any'
tierId?: ID
required?: boolean
variadic?: boolean
style?: SlotTextStyle
Expand Down
Loading
Loading