Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Frontend
Commits
f6fd71f5
Commit
f6fd71f5
authored
1 year ago
by
ml bonhomme
Browse files
Options
Downloads
Patches
Plain Diff
Typescriptify entity helpers
parent
f0ca4107
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1502
Typescriptify entity helpers
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/components/Element/Transcription/Token.vue
+11
-8
11 additions, 8 deletions
src/components/Element/Transcription/Token.vue
src/helpers/entity.ts
+17
-8
17 additions, 8 deletions
src/helpers/entity.ts
src/types.ts
+9
-0
9 additions, 0 deletions
src/types.ts
with
37 additions
and
16 deletions
src/components/Element/Transcription/Token.vue
+
11
−
8
View file @
f6fd71f5
...
...
@@ -32,16 +32,19 @@
</span>
</template>
<
script
>
<
script
lang=
"ts"
>
import
{
mapState
}
from
'
pinia
'
import
{
parseEntities
}
from
'
@/helpers
'
import
{
EntityTranscriptionLight
,
parseEntities
}
from
'
@/helpers
'
import
{
useDisplayStore
}
from
'
@/stores
'
import
{
defineComponent
}
from
'
vue
'
import
type
{
PropType
}
from
'
vue
'
import
{
Entity
,
EntityType
}
from
'
@/types
'
export
default
{
export
default
defineComponent
(
{
name
:
'
Token
'
,
props
:
{
entity
:
{
type
:
Object
,
type
:
Object
as
PropType
<
Entity
>
,
default
:
null
},
text
:
{
...
...
@@ -54,7 +57,7 @@ export default {
required
:
true
},
children
:
{
type
:
Array
,
type
:
Array
as
PropType
<
EntityTranscriptionLight
[]
>
,
default
:
()
=>
[]
},
// Show a warning about an entity overflowing its parent
...
...
@@ -64,10 +67,10 @@ export default {
}
},
methods
:
{
tagStyle
(
type
)
{
tagStyle
(
type
:
EntityType
)
{
return
{
'
background-color
'
:
`#
${
type
.
color
}
`
}
},
entityStyle
(
type
)
{
entityStyle
(
type
:
EntityType
)
{
return
{
'
text-decoration
'
:
`underline #
${
type
.
color
}
`
}
}
},
...
...
@@ -80,7 +83,7 @@ export default {
return
parseEntities
(
this
.
text
,
this
.
children
,
this
.
offset
)
}
}
}
}
)
</
script
>
<
style
scoped
lang=
"scss"
>
...
...
This diff is collapsed.
Click to expand it.
src/helpers/entity.
j
s
→
src/helpers/entity.
t
s
+
17
−
8
View file @
f6fd71f5
import
{
EntityTranscription
}
from
'
@/types
'
import
{
orderBy
}
from
'
lodash
'
export
interface
Token
{
offset
:
number
,
text
:
string
,
entity
?:
object
,
children
:
EntityTranscriptionLight
[],
overflow
?:
boolean
}
export
type
EntityTranscriptionLight
=
Omit
<
EntityTranscription
,
'
worker_run
'
|
'
worker_version_id
'
|
'
confidence
'
>
/**
* Parse EntityTranscriptions to place them on a transcription text using a series of Token components.
* @typedef EntityTranscription {offset: number, length: number, entity: object}
* @param {string} text Transcription text to place the entities on.
* @param {EntityTranscription[]} entities EntityTranscriptions from the API to place onto the text.
* @param {number} textOffset Global offset to apply to the text when parsing only a portion of the text.
* @returns {{offset: number, text: string, entity?: object, children: EntityTranscription[], overflow?: boolean}[]}
* Sets of properties to be used on the Token component for display.
* @param text Transcription text to place the entities on.
* @param entities EntityTranscriptions from the API to place onto the text.
* @param textOffset Global offset to apply to the text when parsing only a portion of the text.
* @returns Sets of properties to be used on the Token component for display.
*/
export
const
parseEntities
=
(
text
,
entities
,
textOffset
=
0
)
=>
{
export
const
parseEntities
=
(
text
:
string
,
entities
:
EntityTranscriptionLight
[]
,
textOffset
=
0
)
=>
{
/**
* The current position in the text.
* If we go through an entity, this position is set to the end of that entity;
...
...
@@ -18,7 +27,7 @@ export const parseEntities = (text, entities, textOffset = 0) => {
* The Vue component will take care of calling this function again to parse recursively.
*/
let
cursor
=
0
const
tokens
=
[]
const
tokens
:
Token
[]
=
[]
for
(
const
{
offset
,
length
,
entity
}
of
orderBy
(
entities
,
[
'
offset
'
,
'
length
'
,
'
id
'
],
[
'
asc
'
,
'
desc
'
,
'
asc
'
]))
{
if
(
cursor
>
offset
)
{
...
...
This diff is collapsed.
Click to expand it.
src/types.ts
+
9
−
0
View file @
f6fd71f5
...
...
@@ -138,6 +138,15 @@ export interface Entity {
worker_run
:
WorkerRunSummary
|
null
}
export
interface
EntityTranscription
{
offset
:
number
,
length
:
number
,
entity
:
Entity
,
worker_run
:
WorkerRunSummary
|
null
,
worker_version_id
:
UUID
|
null
,
confidence
:
number
}
export
interface
AllowedMetaData
{
id
:
UUID
type
:
string
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment