Skip to content

Commit 0a6b0ae

Browse files
committed
added OCR to extract text from images when creating concepts
1 parent b6ed18a commit 0a6b0ae

13 files changed

Lines changed: 39 additions & 47493 deletions

File tree

WebAnnotator.ccfm

Lines changed: 5 additions & 197 deletions
Large diffs are not rendered by default.

input/.babelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
},
1111
"debug": false
1212
}]],
13-
"plugins": [
14-
["@babel/plugin-proposal-class-properties"],
13+
"plugins": [
14+
["@babel/plugin-proposal-class-properties"],
1515
"@babel/plugin-proposal-export-default-from",
1616
"@babel/plugin-syntax-async-generators"
1717
],

input/app/scripts/codebook/operations/update/UpdateCodebook.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Annotation from '../../../annotationManagement/Annotation'
1010
import Code from '../../model/Code'
1111
// PVSCL:ENDCOND
1212
import LanguageUtils from '../../../utils/LanguageUtils'
13-
import ImageUtilsUtils from '../../../utils/ImageUtils'
13+
import ImageUtilsOCR from '../../../utils/ImageUtilsOCR'
1414

1515

1616
class UpdateCodebook {
@@ -94,20 +94,28 @@ class UpdateCodebook {
9494
// Get user selected content
9595
let selection = document.getSelection()
9696
// If selection is child of sidebar, return null
97-
if ($(selection.anchorNode).parents('#annotatorSidebarWrapper').toArray().length !== 0 || selection.toString().length < 1) {
98-
if (selection.anchorNode.innerText) {
99-
retrievedThemeName = selection.anchorNode.innerText
100-
} else {
101-
if (selection.anchorNode.nodeName === 'IMG') {
102-
retrievedThemeName = await ImageUtilsUtils.getStringFromImage(selection.anchorNode)
97+
if (selection.anchorNode) {
98+
if ($(selection.anchorNode).parents('#annotatorSidebarWrapper').toArray().length !== 0 || selection.toString().length < 1) {
99+
if (selection.anchorNode.innerText) {
100+
retrievedThemeName = selection.anchorNode.innerText
103101
} else {
104-
if (selection.anchorNode.lastChild.nodeName === 'IMG') {
105-
retrievedThemeName = await ImageUtilsUtils.getStringFromImage(selection.anchorNode.lastChild)
102+
if (selection.anchorNode.nodeName === 'IMG') {
103+
retrievedThemeName = await ImageUtilsOCR.getStringFromImage(selection.anchorNode)
104+
} else {
105+
if (selection.anchorNode.childNodes) {
106+
let childArray = Array.from(selection.anchorNode.childNodes)
107+
let imgChild = childArray.filter((node) => {
108+
return node.nodeName === 'IMG'
109+
})
110+
if (imgChild[0]) {
111+
retrievedThemeName = await ImageUtilsOCR.getStringFromImage(imgChild[0])
112+
}
113+
}
106114
}
107115
}
116+
} else {
117+
retrievedThemeName = selection.toString().trim().replace(/^\w/, c => c.toUpperCase())
108118
}
109-
} else {
110-
retrievedThemeName = selection.toString().trim().replace(/^\w/, c => c.toUpperCase())
111119
}
112120
Alerts.multipleInputAlert({
113121
title: 'You are creating a new ' + Config.tags.grouped.group + ': ',

0 commit comments

Comments
 (0)