-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2134 from openturing/feature/ocr-metadata
Feature/ocr metadata
- Loading branch information
Showing
20 changed files
with
514 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 39 additions & 6 deletions
45
turing-app/src/main/java/com/viglet/turing/api/ocr/TurOcrAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,55 @@ | ||
/* | ||
* | ||
* Copyright (C) 2016-2024 the original author or authors. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.viglet.turing.api.ocr; | ||
|
||
import com.viglet.turing.commons.file.TurFileAttributes; | ||
import com.viglet.turing.filesystem.commons.TurFileUtils; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
|
||
/** | ||
* @author Alexandre Oliveira | ||
* @since 0.3.9 | ||
*/ | ||
@Slf4j | ||
@RestController | ||
@RequestMapping("/api/ocr") | ||
@Tag(name = "OCR", description = "OCR API") | ||
public class TurOcrAPI { | ||
|
||
@PostMapping | ||
public String convertToText(@RequestParam("file") MultipartFile multipartFile) { | ||
@PostMapping("/file") | ||
public TurFileAttributes fileToText(@RequestParam("file") MultipartFile multipartFile) { | ||
return TurFileUtils.documentToText(multipartFile); | ||
} | ||
|
||
@PostMapping("/url") | ||
public TurFileAttributes urlToText(@RequestBody TurOcrFromUrl turOcrFromUrl) { | ||
try { | ||
return TurFileUtils.urlContentToText(URI.create(turOcrFromUrl.getUrl()).toURL()); | ||
} | ||
catch (MalformedURLException e) { | ||
log.error(e.getMessage(), e); | ||
} | ||
return new TurFileAttributes(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
turing-app/src/main/java/com/viglet/turing/api/ocr/TurOcrFromUrl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* | ||
* Copyright (C) 2016-2024 the original author or authors. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.viglet.turing.api.ocr; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
/** | ||
* @author Alexandre Oliveira | ||
* @since 0.3.9 | ||
*/ | ||
@Getter | ||
@Setter | ||
public class TurOcrFromUrl { | ||
private String url; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
turing-commons/src/main/java/com/viglet/turing/commons/file/TurFileAttributes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* | ||
* Copyright (C) 2016-2024 the original author or authors. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.viglet.turing.commons.file; | ||
|
||
import lombok.*; | ||
|
||
import java.util.Date; | ||
import java.util.Map; | ||
|
||
/** | ||
* | ||
* @author Alexandre Oliveira | ||
* | ||
* @since 0.3.9 | ||
* | ||
**/ | ||
|
||
@Builder(toBuilder = true) | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Setter | ||
@Getter | ||
@ToString | ||
public class TurFileAttributes { | ||
private String content; | ||
private String name; | ||
private String title; | ||
private String extension; | ||
private TurFileSize size; | ||
private Date lastModified; | ||
private Map<String, String> metadata; | ||
|
||
|
||
} |
51 changes: 51 additions & 0 deletions
51
turing-commons/src/main/java/com/viglet/turing/commons/file/TurFileSize.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* | ||
* Copyright (C) 2016-2024 the original author or authors. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.viglet.turing.commons.file; | ||
|
||
import lombok.*; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.RoundingMode; | ||
|
||
/** | ||
* @author Alexandre Oliveira | ||
* @since 0.3.9 | ||
**/ | ||
@Setter | ||
@Getter | ||
@AllArgsConstructor | ||
@ToString | ||
public class TurFileSize { | ||
private final float bytes; | ||
private final float kiloBytes; | ||
private final float megaBytes; | ||
public TurFileSize() { | ||
this(0f); | ||
} | ||
public TurFileSize(float bytes) { | ||
this.bytes = twoDecimalFloat(bytes); | ||
this.kiloBytes = twoDecimalFloat(this.bytes / 1024); | ||
this.megaBytes = twoDecimalFloat(this.kiloBytes / 1024); | ||
} | ||
|
||
private float twoDecimalFloat(float value) { | ||
return BigDecimal.valueOf(value).setScale(2, RoundingMode.HALF_UP).floatValue(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.