feat: read & write processes text
This commit is contained in:
parent
c60ad1e4da
commit
626dce13dc
@ -47,6 +47,10 @@ func GetProcessedAreaCollection() *ProcessedAreaCollection {
|
|||||||
return processedAreaCollectionInstnace
|
return processedAreaCollectionInstnace
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetProcessedAreaCollection(collection ProcessedAreaCollection) {
|
||||||
|
processedAreaCollectionInstnace = &collection
|
||||||
|
}
|
||||||
|
|
||||||
func (collection *ProcessedAreaCollection) AddProcessedArea(area ProcessedArea) {
|
func (collection *ProcessedAreaCollection) AddProcessedArea(area ProcessedArea) {
|
||||||
collection.Areas = append(collection.Areas, area)
|
collection.Areas = append(collection.Areas, area)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import processImageArea from '../../useCases/processImageArea'
|
|||||||
import classNames from '../../utils/classNames'
|
import classNames from '../../utils/classNames'
|
||||||
import LanguageSelect from './LanguageSelect'
|
import LanguageSelect from './LanguageSelect'
|
||||||
|
|
||||||
const zoomStep = 0.05
|
const zoomStep = 0.025
|
||||||
const maxZoomLevel = 4
|
const maxZoomLevel = 4
|
||||||
|
|
||||||
const DocumentRenderer = () => {
|
const DocumentRenderer = () => {
|
||||||
|
|||||||
@ -12,8 +12,6 @@ import {
|
|||||||
RequestDeleteAreaById,
|
RequestDeleteAreaById,
|
||||||
RequestChangeGroupOrder,
|
RequestChangeGroupOrder,
|
||||||
RequestChangeSessionProjectByName,
|
RequestChangeSessionProjectByName,
|
||||||
RequestSaveDocumentCollection,
|
|
||||||
RequestSaveGroupCollection,
|
|
||||||
} from '../../wailsjs/wailsjs/go/ipc/Channel'
|
} from '../../wailsjs/wailsjs/go/ipc/Channel'
|
||||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
||||||
import { AddAreaProps, AreaProps, ProjectContextType, ProjectProps, UpdateDocumentRequest, UserProps } from './types'
|
import { AddAreaProps, AreaProps, ProjectContextType, ProjectProps, UpdateDocumentRequest, UserProps } from './types'
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import { createScheduler, createWorker } from 'tesseract.js'
|
import { createScheduler, createWorker } from 'tesseract.js'
|
||||||
import { GetAreaById, GetDocumentById, RequestAddProcessedArea } from '../wailsjs/wailsjs/go/ipc/Channel'
|
import { GetAreaById, GetDocumentById, RequestAddProcessedArea, RequestSaveProcessedTextCollection } from '../wailsjs/wailsjs/go/ipc/Channel'
|
||||||
import { ipc } from '../wailsjs/wailsjs/go/models'
|
import { ipc } from '../wailsjs/wailsjs/go/models'
|
||||||
import loadImage from './loadImage'
|
import loadImage from './loadImage'
|
||||||
|
import { saveProcessedText } from './saveData'
|
||||||
|
|
||||||
const processImageArea = async (documentId: string, areaId: string) => {
|
const processImageArea = async (documentId: string, areaId: string) => {
|
||||||
const foundDocument = await GetDocumentById(documentId)
|
const foundDocument = await GetDocumentById(documentId)
|
||||||
@ -61,6 +62,8 @@ const processImageArea = async (documentId: string, areaId: string) => {
|
|||||||
}))
|
}))
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
saveProcessedText()
|
||||||
|
|
||||||
return addProcessesAreaRequest
|
return addProcessesAreaRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import { RequestSaveDocumentCollection, RequestSaveGroupCollection } from '../wailsjs/wailsjs/go/ipc/Channel'
|
import { RequestSaveDocumentCollection, RequestSaveGroupCollection, RequestSaveProcessedTextCollection } from '../wailsjs/wailsjs/go/ipc/Channel'
|
||||||
|
|
||||||
const saveDocuments = async () => {
|
const saveDocuments = async () => {
|
||||||
try {
|
try {
|
||||||
const sucessfulSave = RequestSaveDocumentCollection()
|
const sucessfulSave = await RequestSaveDocumentCollection()
|
||||||
if (!sucessfulSave) console.error('Could not save DocumentCollection')
|
if (!sucessfulSave) console.error('Could not save DocumentCollection')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Could not save DocumentCollection:', err)
|
console.error('Could not save DocumentCollection:', err)
|
||||||
@ -11,14 +11,24 @@ const saveDocuments = async () => {
|
|||||||
|
|
||||||
const saveGroups = async () => {
|
const saveGroups = async () => {
|
||||||
try {
|
try {
|
||||||
const sucessfulSave = RequestSaveGroupCollection()
|
const sucessfulSave = await RequestSaveGroupCollection()
|
||||||
if (!sucessfulSave) console.error('Could not save GroupCollection')
|
if (!sucessfulSave) console.error('Could not save GroupCollection')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Could not save GroupCollection:', err)
|
console.error('Could not save GroupCollection:', err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const saveProcessedText = async () => {
|
||||||
|
try {
|
||||||
|
const sucessfulSave = await RequestSaveProcessedTextCollection()
|
||||||
|
if (!sucessfulSave) console.error('Could not save ProcessedTextCollection')
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Could not save ProcessedTextCollection: ', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
saveDocuments,
|
saveDocuments,
|
||||||
saveGroups,
|
saveGroups,
|
||||||
|
saveProcessedText,
|
||||||
}
|
}
|
||||||
2
frontend/wailsjs/wailsjs/go/ipc/Channel.d.ts
vendored
2
frontend/wailsjs/wailsjs/go/ipc/Channel.d.ts
vendored
@ -46,6 +46,8 @@ export function RequestSaveDocumentCollection():Promise<boolean>;
|
|||||||
|
|
||||||
export function RequestSaveGroupCollection():Promise<boolean>;
|
export function RequestSaveGroupCollection():Promise<boolean>;
|
||||||
|
|
||||||
|
export function RequestSaveProcessedTextCollection():Promise<boolean>;
|
||||||
|
|
||||||
export function RequestUpdateArea(arg1:ipc.Area):Promise<ipc.Area>;
|
export function RequestUpdateArea(arg1:ipc.Area):Promise<ipc.Area>;
|
||||||
|
|
||||||
export function RequestUpdateCurrentUser(arg1:ipc.User):Promise<ipc.User>;
|
export function RequestUpdateCurrentUser(arg1:ipc.User):Promise<ipc.User>;
|
||||||
|
|||||||
@ -90,6 +90,10 @@ export function RequestSaveGroupCollection() {
|
|||||||
return window['go']['ipc']['Channel']['RequestSaveGroupCollection']();
|
return window['go']['ipc']['Channel']['RequestSaveGroupCollection']();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function RequestSaveProcessedTextCollection() {
|
||||||
|
return window['go']['ipc']['Channel']['RequestSaveProcessedTextCollection']();
|
||||||
|
}
|
||||||
|
|
||||||
export function RequestUpdateArea(arg1) {
|
export function RequestUpdateArea(arg1) {
|
||||||
return window['go']['ipc']['Channel']['RequestUpdateArea'](arg1);
|
return window['go']['ipc']['Channel']['RequestUpdateArea'](arg1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -472,3 +472,56 @@ func (c *Channel) RequestSaveGroupCollection() bool {
|
|||||||
|
|
||||||
return successfulWrite
|
return successfulWrite
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Channel) RequestSaveProcessedTextCollection() bool {
|
||||||
|
processedAreaCollection := document.GetProcessedAreaCollection()
|
||||||
|
projectName := c.GetCurrentSession().Project.Name
|
||||||
|
|
||||||
|
areasToWrite := make([]storage.LocalProcessedArea, 0)
|
||||||
|
for _, a := range processedAreaCollection.Areas {
|
||||||
|
linesOfAreaToWrite := make([]storage.LocalProcessedLine, 0)
|
||||||
|
for _, l := range a.Lines {
|
||||||
|
wordsOfLineToWrite := make([]storage.LocalProcessedWord, 0)
|
||||||
|
|
||||||
|
for _, w := range l.Words {
|
||||||
|
symbolsOfWordToWrite := make([]storage.LocalProcessedSymbol, 0)
|
||||||
|
|
||||||
|
for _, s := range w.Symbols {
|
||||||
|
symbolsOfWordToWrite = append(symbolsOfWordToWrite, storage.LocalProcessedSymbol{
|
||||||
|
Text: s.Text,
|
||||||
|
Confidence: s.Confidence,
|
||||||
|
BoundingBox: storage.LocalProcessedBoundingBox(s.BoundingBox),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
wordsOfLineToWrite = append(wordsOfLineToWrite, storage.LocalProcessedWord{
|
||||||
|
FullText: w.FullText,
|
||||||
|
Confidence: w.Confidence,
|
||||||
|
Direction: w.Direction,
|
||||||
|
BoundingBox: storage.LocalProcessedBoundingBox(w.BoundingBox),
|
||||||
|
Symbols: symbolsOfWordToWrite,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
linesOfAreaToWrite = append(linesOfAreaToWrite, storage.LocalProcessedLine{
|
||||||
|
FullText: l.FullText,
|
||||||
|
Words: wordsOfLineToWrite,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
areasToWrite = append(areasToWrite, storage.LocalProcessedArea{
|
||||||
|
Id: a.Id,
|
||||||
|
DocumentId: a.DocumentId,
|
||||||
|
FullText: a.FullText,
|
||||||
|
Order: a.Order,
|
||||||
|
Lines: linesOfAreaToWrite,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
processedAreaCollectionToWrite := storage.LocalProcessedAreaCollection{
|
||||||
|
Areas: areasToWrite,
|
||||||
|
}
|
||||||
|
|
||||||
|
successfulWrite := storage.WriteLocalProcessedAreaCollection(processedAreaCollectionToWrite, projectName)
|
||||||
|
return successfulWrite
|
||||||
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package ipc
|
package ipc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
app "textualize/core/App"
|
app "textualize/core/App"
|
||||||
consts "textualize/core/Consts"
|
consts "textualize/core/Consts"
|
||||||
document "textualize/core/Document"
|
document "textualize/core/Document"
|
||||||
@ -225,8 +224,53 @@ func (c *Channel) RequestChangeSessionProjectByName(projectName string) bool {
|
|||||||
}
|
}
|
||||||
document.SetGroupCollection(newGroupCollection)
|
document.SetGroupCollection(newGroupCollection)
|
||||||
|
|
||||||
fmt.Println("newSESSION_______")
|
// Processed Texts
|
||||||
fmt.Println(document.GetDocumentCollection())
|
|
||||||
|
localProcessedAreaCollection := storage.ReadLocalProcessedAreaCollection(projectName)
|
||||||
|
newAreas := make([]document.ProcessedArea, 0)
|
||||||
|
for _, a := range localProcessedAreaCollection.Areas {
|
||||||
|
linesOfArea := make([]document.ProcessedLine, 0)
|
||||||
|
for _, l := range a.Lines {
|
||||||
|
wordsOfLine := make([]document.ProcessedWord, 0)
|
||||||
|
|
||||||
|
for _, w := range l.Words {
|
||||||
|
symbolsOfWord := make([]document.ProcessedSymbol, 0)
|
||||||
|
|
||||||
|
for _, s := range w.Symbols {
|
||||||
|
symbolsOfWord = append(symbolsOfWord, document.ProcessedSymbol{
|
||||||
|
Text: s.Text,
|
||||||
|
Confidence: s.Confidence,
|
||||||
|
BoundingBox: document.ProcessedBoundingBox(s.BoundingBox),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
wordsOfLine = append(wordsOfLine, document.ProcessedWord{
|
||||||
|
FullText: w.FullText,
|
||||||
|
Confidence: w.Confidence,
|
||||||
|
Direction: w.Direction,
|
||||||
|
BoundingBox: document.ProcessedBoundingBox(w.BoundingBox),
|
||||||
|
Symbols: symbolsOfWord,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
linesOfArea = append(linesOfArea, document.ProcessedLine{
|
||||||
|
FullText: l.FullText,
|
||||||
|
Words: wordsOfLine,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
newAreas = append(newAreas, document.ProcessedArea{
|
||||||
|
Id: a.Id,
|
||||||
|
DocumentId: a.DocumentId,
|
||||||
|
FullText: a.FullText,
|
||||||
|
Order: a.Order,
|
||||||
|
Lines: linesOfArea,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
document.SetProcessedAreaCollection(document.ProcessedAreaCollection{
|
||||||
|
Areas: newAreas,
|
||||||
|
})
|
||||||
|
|
||||||
return session.GetInstance().Project.Id == foundProject.Id
|
return session.GetInstance().Project.Id == foundProject.Id
|
||||||
}
|
}
|
||||||
|
|||||||
2
main.go
2
main.go
@ -7,8 +7,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
ipc "textualize/Ipc"
|
|
||||||
app "textualize/core/App"
|
app "textualize/core/App"
|
||||||
|
ipc "textualize/ipc"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v2"
|
"github.com/wailsapp/wails/v2"
|
||||||
"github.com/wailsapp/wails/v2/pkg/logger"
|
"github.com/wailsapp/wails/v2/pkg/logger"
|
||||||
|
|||||||
@ -68,3 +68,41 @@ type LocalGroupCollection struct {
|
|||||||
Groups []LocalGroup `json:"groups"`
|
Groups []LocalGroup `json:"groups"`
|
||||||
ProjectId string `json:"projectId"`
|
ProjectId string `json:"projectId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LocalProcessedBoundingBox struct {
|
||||||
|
X0 int32 `json:"x0"`
|
||||||
|
Y0 int32 `json:"y0"`
|
||||||
|
X1 int32 `json:"x1"`
|
||||||
|
Y1 int32 `json:"y1"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LocalProcessedSymbol struct {
|
||||||
|
Text string `json:"text"`
|
||||||
|
Confidence float32 `json:"confidence"`
|
||||||
|
BoundingBox LocalProcessedBoundingBox `json:"boundingBox"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LocalProcessedWord struct {
|
||||||
|
FullText string `json:"fullText"`
|
||||||
|
Symbols []LocalProcessedSymbol `json:"symbols"`
|
||||||
|
Confidence float32 `json:"confidence"`
|
||||||
|
Direction string `json:"direction"`
|
||||||
|
BoundingBox LocalProcessedBoundingBox `json:"boundingBox"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LocalProcessedLine struct {
|
||||||
|
FullText string `json:"fullText"`
|
||||||
|
Words []LocalProcessedWord `json:"words"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LocalProcessedArea struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
DocumentId string `json:"documentId"`
|
||||||
|
FullText string `json:"fullText"`
|
||||||
|
Order int `json:"order"`
|
||||||
|
Lines []LocalProcessedLine `json:"lines"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LocalProcessedAreaCollection struct {
|
||||||
|
Areas []LocalProcessedArea
|
||||||
|
}
|
||||||
|
|||||||
41
storage/Local/ProcessedText.go
Normal file
41
storage/Local/ProcessedText.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func WriteLocalProcessedAreaCollection(processedTextCollection LocalProcessedAreaCollection, projectName string) bool {
|
||||||
|
file, _ := json.MarshalIndent(processedTextCollection, "", " ")
|
||||||
|
path := GetLocalStoragePath()
|
||||||
|
|
||||||
|
if path == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
subdirectory := "/projects/" + projectName
|
||||||
|
isLocalStorageDirectoryCreated := createLocalStorageSubDirIfNeeded(subdirectory)
|
||||||
|
if !isLocalStorageDirectoryCreated {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
err := os.WriteFile(GetLocalStoragePath()+subdirectory+"/ProcessedTexts.json", file, 0644)
|
||||||
|
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadLocalProcessedAreaCollection(projectName string) LocalProcessedAreaCollection {
|
||||||
|
file, err := os.ReadFile(GetLocalStoragePath() + "/projects/" + projectName + "/ProcessedTexts.json")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return LocalProcessedAreaCollection{}
|
||||||
|
}
|
||||||
|
|
||||||
|
response := LocalProcessedAreaCollection{}
|
||||||
|
errorUnmarshaling := json.Unmarshal([]byte(file), &response)
|
||||||
|
if errorUnmarshaling != nil {
|
||||||
|
return LocalProcessedAreaCollection{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user