feat: read & write processes text
This commit is contained in:
parent
c60ad1e4da
commit
626dce13dc
@ -47,6 +47,10 @@ func GetProcessedAreaCollection() *ProcessedAreaCollection {
|
||||
return processedAreaCollectionInstnace
|
||||
}
|
||||
|
||||
func SetProcessedAreaCollection(collection ProcessedAreaCollection) {
|
||||
processedAreaCollectionInstnace = &collection
|
||||
}
|
||||
|
||||
func (collection *ProcessedAreaCollection) AddProcessedArea(area ProcessedArea) {
|
||||
collection.Areas = append(collection.Areas, area)
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import processImageArea from '../../useCases/processImageArea'
|
||||
import classNames from '../../utils/classNames'
|
||||
import LanguageSelect from './LanguageSelect'
|
||||
|
||||
const zoomStep = 0.05
|
||||
const zoomStep = 0.025
|
||||
const maxZoomLevel = 4
|
||||
|
||||
const DocumentRenderer = () => {
|
||||
|
||||
@ -12,8 +12,6 @@ import {
|
||||
RequestDeleteAreaById,
|
||||
RequestChangeGroupOrder,
|
||||
RequestChangeSessionProjectByName,
|
||||
RequestSaveDocumentCollection,
|
||||
RequestSaveGroupCollection,
|
||||
} from '../../wailsjs/wailsjs/go/ipc/Channel'
|
||||
import { ipc } from '../../wailsjs/wailsjs/go/models'
|
||||
import { AddAreaProps, AreaProps, ProjectContextType, ProjectProps, UpdateDocumentRequest, UserProps } from './types'
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
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 loadImage from './loadImage'
|
||||
import { saveProcessedText } from './saveData'
|
||||
|
||||
const processImageArea = async (documentId: string, areaId: string) => {
|
||||
const foundDocument = await GetDocumentById(documentId)
|
||||
@ -61,6 +62,8 @@ const processImageArea = async (documentId: string, areaId: string) => {
|
||||
}))
|
||||
}))
|
||||
|
||||
saveProcessedText()
|
||||
|
||||
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 () => {
|
||||
try {
|
||||
const sucessfulSave = RequestSaveDocumentCollection()
|
||||
const sucessfulSave = await RequestSaveDocumentCollection()
|
||||
if (!sucessfulSave) console.error('Could not save DocumentCollection')
|
||||
} catch (err) {
|
||||
console.error('Could not save DocumentCollection:', err)
|
||||
@ -11,14 +11,24 @@ const saveDocuments = async () => {
|
||||
|
||||
const saveGroups = async () => {
|
||||
try {
|
||||
const sucessfulSave = RequestSaveGroupCollection()
|
||||
const sucessfulSave = await RequestSaveGroupCollection()
|
||||
if (!sucessfulSave) console.error('Could not save GroupCollection')
|
||||
} catch (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 {
|
||||
saveDocuments,
|
||||
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 RequestSaveProcessedTextCollection():Promise<boolean>;
|
||||
|
||||
export function RequestUpdateArea(arg1:ipc.Area):Promise<ipc.Area>;
|
||||
|
||||
export function RequestUpdateCurrentUser(arg1:ipc.User):Promise<ipc.User>;
|
||||
|
||||
@ -90,6 +90,10 @@ export function RequestSaveGroupCollection() {
|
||||
return window['go']['ipc']['Channel']['RequestSaveGroupCollection']();
|
||||
}
|
||||
|
||||
export function RequestSaveProcessedTextCollection() {
|
||||
return window['go']['ipc']['Channel']['RequestSaveProcessedTextCollection']();
|
||||
}
|
||||
|
||||
export function RequestUpdateArea(arg1) {
|
||||
return window['go']['ipc']['Channel']['RequestUpdateArea'](arg1);
|
||||
}
|
||||
|
||||
@ -472,3 +472,56 @@ func (c *Channel) RequestSaveGroupCollection() bool {
|
||||
|
||||
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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
app "textualize/core/App"
|
||||
consts "textualize/core/Consts"
|
||||
document "textualize/core/Document"
|
||||
@ -225,8 +224,53 @@ func (c *Channel) RequestChangeSessionProjectByName(projectName string) bool {
|
||||
}
|
||||
document.SetGroupCollection(newGroupCollection)
|
||||
|
||||
fmt.Println("newSESSION_______")
|
||||
fmt.Println(document.GetDocumentCollection())
|
||||
// Processed Texts
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
2
main.go
2
main.go
@ -7,8 +7,8 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
ipc "textualize/Ipc"
|
||||
app "textualize/core/App"
|
||||
ipc "textualize/ipc"
|
||||
|
||||
"github.com/wailsapp/wails/v2"
|
||||
"github.com/wailsapp/wails/v2/pkg/logger"
|
||||
|
||||
@ -68,3 +68,41 @@ type LocalGroupCollection struct {
|
||||
Groups []LocalGroup `json:"groups"`
|
||||
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