From 5ac359394ef0ed6bd0ecd2a7dff0295f27080be6 Mon Sep 17 00:00:00 2001 From: Mocretion Date: Wed, 21 Aug 2024 13:13:21 +0200 Subject: [PATCH 1/8] Defaults to sofastring if no parent is set in subimage --- .../tools/MultimodalUtil.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/tools/MultimodalUtil.java b/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/tools/MultimodalUtil.java index bc34867..90c5d98 100644 --- a/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/tools/MultimodalUtil.java +++ b/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/tools/MultimodalUtil.java @@ -445,16 +445,34 @@ private static void executeFFMpeg(String absoluteInputPath, List command } } + /** + * Gets subimages as independent image files + * @param jCas The JCas containing SubImage Annotations + * @return A List of files, each containing a SubImage. Files get deleted on exit + */ public static List getSubImages(JCas jCas){ return getSubImages(jCas, null); } + /** + * Gets subimages as independent image files + * @param jCas The JCas containing SubImage Annotations + * @param overrideExtension Changes the main images extension + * @return A List of files, each containing a SubImage. Files get deleted on exit + */ public static List getSubImages(JCas jCas, String overrideExtension) { List subImages = new ArrayList<>(); JCasUtil.select(jCas, SubImage.class).forEach(subImage -> { - byte[] base64Image = Base64.decodeBase64(subImage.getParent().getSrc()); + String mainImageB64 = ""; + if(subImage.getParent().getSrc() == null){ + mainImageB64 = jCas.getSofaDataString(); + }else{ + mainImageB64 = subImage.getParent().getSrc(); + } + + byte[] base64Image = Base64.decodeBase64(mainImageB64); try { BufferedImage bImage = ImageIO.read(new ByteArrayInputStream(base64Image)); From 56d88cc3bd777fe817b51fa42413a7fce3210997 Mon Sep 17 00:00:00 2001 From: dterefe Date: Tue, 27 Aug 2024 19:58:13 +0200 Subject: [PATCH 2/8] Fixed Dropbox Connector --- .../document_handler/DUUIDropboxDocumentHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/document_handler/DUUIDropboxDocumentHandler.java b/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/document_handler/DUUIDropboxDocumentHandler.java index 739b3fc..27e6cfb 100644 --- a/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/document_handler/DUUIDropboxDocumentHandler.java +++ b/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/document_handler/DUUIDropboxDocumentHandler.java @@ -280,7 +280,7 @@ public List listDocuments(String path, String fileExtension, boole @Override public DUUIFolder getFolderStructure() { - return getFolderStructure("/", "Files"); + return getFolderStructure("", "Files"); } public DUUIFolder getFolderStructure(String path, String name) { From ca4b35213e0381325750d730da943f9e815c869d Mon Sep 17 00:00:00 2001 From: dterefe Date: Tue, 27 Aug 2024 20:27:21 +0200 Subject: [PATCH 3/8] Enabled Docker support for Windows. --- .../DUUIDockerInterface.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/DUUIDockerInterface.java b/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/DUUIDockerInterface.java index 4705f53..e9dca4a 100644 --- a/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/DUUIDockerInterface.java +++ b/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/DUUIDockerInterface.java @@ -9,13 +9,17 @@ import com.github.dockerjava.api.model.*; import com.github.dockerjava.core.DockerClientBuilder; import com.github.dockerjava.core.command.LogContainerResultCallback; +import com.github.dockerjava.httpclient5.ApacheDockerHttpClient; +import com.github.dockerjava.transport.DockerHttpClient; import com.google.common.collect.ImmutableList; import java.io.File; import java.io.IOException; +import java.net.URI; import java.nio.file.Path; import java.nio.file.Paths; import java.security.InvalidParameterException; +import java.time.Duration; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -162,22 +166,21 @@ public class DUUIDockerInterface { */ public DUUIDockerInterface() throws IOException { - // GREAT TODO!!! - //URI dockerClientURI; - //if (System.getProperty("os.name").toLowerCase().contains("windows")) { - // dockerClientURI = URI.create("npipe:////./pipe/docker_engine"); - //} else { - // dockerClientURI = URI.create("tcp://localhost:2375"); - //} - - //_docker = DockerClientBuilder.getInstance() -// .withDockerHttpClient(new ApacheDockerHttpClient.Builder() -// .dockerHost(dockerClientURI).build()).build(); - _docker = DockerClientBuilder.getInstance().build(); - + if (!System.getProperty("os.name").contains("Windows")) { + _docker = DockerClientBuilder.getInstance().build(); + } else { + // Windows + final DockerHttpClient http = new ApacheDockerHttpClient.Builder() + .connectionTimeout(Duration.ofSeconds(5)) + .responseTimeout(Duration.ofMinutes(10)) + .dockerHost(URI.create("npipe:////./pipe/docker_engine")) + // .dockerHost(URI.create("tcp://127.0.0.1:2375")) // if npipe doesn't work. + .build(); + _docker = DockerClientBuilder.getInstance() + .withDockerHttpClient(http) + .build(); -// DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost("tcp://localhost:2375").build(); -// _docker = DockerClientBuilder.getInstance(config).build(); + } } /** From 252c365ac402868dc0156de708b53113bd05bb85 Mon Sep 17 00:00:00 2001 From: dterefe Date: Sat, 28 Sep 2024 18:55:05 +0200 Subject: [PATCH 4/8] Fixed unimplemented serialization methods. --- .../IDUUICommunicationLayer.java | 72 ++++++++++--------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/IDUUICommunicationLayer.java b/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/IDUUICommunicationLayer.java index 7d0da09..20dffe2 100644 --- a/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/IDUUICommunicationLayer.java +++ b/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/IDUUICommunicationLayer.java @@ -18,38 +18,42 @@ public interface IDUUICommunicationLayer { public void deserialize(JCas jc, ByteArrayInputStream input, String targetView) throws IOException, SAXException, CASException; - /** - * Serializes a JCas to a byte array output stream by using the LUA script provided by the component. - * @param jc Input JCas. - * @param out Output stream, i.e. the input to the component. - * @param parameters Parameters for use in the LUA script. - * @throws CompressorException - * @throws IOException - * @throws SAXException - */ - public void serialize(JCas jc, ByteArrayOutputStream out, Map parameters) throws CompressorException, IOException, SAXException; - - /** - * Deserializes a byte array input stream to a JCas by using the LUA script provided by the component. - * @param jc Output JCas, note that the CAS is not reset before deserialization. - * @param input Input stream, i.e. the output of the component. - * @throws IOException - * @throws SAXException - */ - public void deserialize(JCas jc, ByteArrayInputStream input) throws IOException, SAXException; - - /** - * - * @return - */ - public IDUUICommunicationLayer copy(); - - /** - * - * @param results - * @return - */ - public ByteArrayInputStream merge(List results); - - String myLuaTestMerging(); + /** + * Serializes a JCas to a byte array output stream by using the LUA script provided by the component. + * @param jc Input JCas. + * @param out Output stream, i.e. the input to the component. + * @param parameters Parameters for use in the LUA script. + * @throws CompressorException + * @throws IOException + * @throws SAXException + */ + default void serialize(JCas jc, ByteArrayOutputStream out, Map parameters) throws CompressorException, IOException, SAXException, CASException { + serialize(jc, out, parameters, "_InitialView"); + } + + /** + * Deserializes a byte array input stream to a JCas by using the LUA script provided by the component. + * @param jc Output JCas, note that the CAS is not reset before deserialization. + * @param input Input stream, i.e. the output of the component. + * @throws IOException + * @throws SAXException + */ + default void deserialize(JCas jc, ByteArrayInputStream input) throws IOException, SAXException, CASException { + deserialize(jc, input, "_InitialView"); + } + + /** + * + * @return + */ + public IDUUICommunicationLayer copy(); + + /** + * + * @param results + * @return + */ + public ByteArrayInputStream merge(List results); + + String myLuaTestMerging(); } From 0f118408c08c6f116c28455ff6df2f6eaf2b133a Mon Sep 17 00:00:00 2001 From: Mocretion Date: Sun, 29 Sep 2024 16:21:39 +0200 Subject: [PATCH 5/8] removed l due to parsing error --- .../driver/DUUIPipelineComponent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/driver/DUUIPipelineComponent.java b/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/driver/DUUIPipelineComponent.java index ee9dbc6..6d8b827 100644 --- a/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/driver/DUUIPipelineComponent.java +++ b/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/driver/DUUIPipelineComponent.java @@ -665,6 +665,6 @@ public DUUISegmentationStrategy getSegmentationStrategy() { } public long getTimeout() { - return Long.valueOf(_options.getOrDefault(timeout, "60l")); + return Long.valueOf(_options.getOrDefault(timeout, "60")); } } From 912f617cf9a1e374cfeec85ceab964fd52ec7457 Mon Sep 17 00:00:00 2001 From: Mocretion Date: Sun, 29 Sep 2024 16:21:55 +0200 Subject: [PATCH 6/8] Created subimages support alpha channel --- .../tools/MultimodalUtil.java | 62 ++++++++----------- src/test/java/TestDUUI.java | 1 - 2 files changed, 25 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/tools/MultimodalUtil.java b/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/tools/MultimodalUtil.java index 90c5d98..b3f0891 100644 --- a/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/tools/MultimodalUtil.java +++ b/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/tools/MultimodalUtil.java @@ -446,21 +446,26 @@ private static void executeFFMpeg(String absoluteInputPath, List command } /** - * Gets subimages as independent image files + * Gets subimages as independent image files in .png * @param jCas The JCas containing SubImage Annotations * @return A List of files, each containing a SubImage. Files get deleted on exit */ public static List getSubImages(JCas jCas){ - return getSubImages(jCas, null); + return getSubImages(jCas, "png"); } /** * Gets subimages as independent image files * @param jCas The JCas containing SubImage Annotations - * @param overrideExtension Changes the main images extension + * @param extension Changes the subimages images file extension * @return A List of files, each containing a SubImage. Files get deleted on exit */ - public static List getSubImages(JCas jCas, String overrideExtension) { + public static List getSubImages(JCas jCas, String extension) { + + if(extension.startsWith(".")) + extension = extension.substring(1); + String finalExtension = extension; + List subImages = new ArrayList<>(); @@ -486,45 +491,28 @@ public static List getSubImages(JCas jCas, String overrideExtension) { Rectangle bounds = polygon.getBounds(); - BufferedImage bSubImage = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_RGB); - - Graphics2D graphics = bSubImage.createGraphics(); - - polygon.translate(-bounds.x, -bounds.y); - - graphics.setClip(polygon); - graphics.drawImage(bImage, -bounds.x, -bounds.y, null); - - // Create file - - File tempInputFile = new File("tempInputImage"); - tempInputFile.deleteOnExit(); - try (OutputStream stream = new FileOutputStream(tempInputFile)) { - stream.write(base64Image); - } - - String mimeType = Files.probeContentType(tempInputFile.toPath()); - String subType = ""; - - if(overrideExtension == null){ - if(mimeType != null && !mimeType.isEmpty()){ - subType = mimeType.split("/")[1]; - }else{ - subType = "jpg"; - } - }else{ - subType = overrideExtension; - if(subType.startsWith(".")){ - if(subType.length() > 1) - subType = subType.substring(1); + BufferedImage bSubImage; + if(finalExtension.equals("png") || finalExtension.equals("tiff") || finalExtension.equals("gif") || finalExtension.equals("apng")) + bSubImage = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_ARGB); // Alpha channel support + else + bSubImage = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_RGB); // No alpha + + // Copy pixels form main image to new subimage + for (int x = bounds.x; x < bounds.x + bounds.width; x++) { + for (int y = bounds.y; y < bounds.y + bounds.height; y++) { + if(polygon.contains(x, y)){ + int iColor = bImage.getRGB(x, y); + bSubImage.setRGB(x - bounds.x, y - bounds.y, iColor); + } } } - File outputFile = new File(getOutputName(jCas, subImage, subType)); + // Create output file + File outputFile = new File(getOutputName(jCas, subImage, finalExtension)); outputFile.deleteOnExit(); RenderedImage rendImage = bSubImage; - ImageIO.write(rendImage, subType, outputFile); + ImageIO.write(rendImage, finalExtension, outputFile); subImages.add(outputFile); } catch (IOException e) { diff --git a/src/test/java/TestDUUI.java b/src/test/java/TestDUUI.java index e8076dc..a0e858d 100644 --- a/src/test/java/TestDUUI.java +++ b/src/test/java/TestDUUI.java @@ -1171,7 +1171,6 @@ public void multimodalImageCutterTest() throws Exception{ composer.add(new DUUIDockerDriver.Component("duui-yolo:latest") // Image detection .withScale(iWorkers) - .withRunningAfterDestroy(true) .build()); composer.add(new DUUIUIMADriver.Component(createEngineDescription(XmiWriter.class, From 7e0620ae25f5cc637cdc3a7cf866d1d29708db81 Mon Sep 17 00:00:00 2001 From: Mocretion Date: Sat, 5 Oct 2024 18:23:16 +0200 Subject: [PATCH 7/8] Added video title to metadata --- .../DockerUnifiedUIMAInterface/io/reader/DUUIYouTubeReader.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/io/reader/DUUIYouTubeReader.java b/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/io/reader/DUUIYouTubeReader.java index 3c1dbd3..b261ef4 100644 --- a/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/io/reader/DUUIYouTubeReader.java +++ b/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/io/reader/DUUIYouTubeReader.java @@ -463,6 +463,7 @@ private void setVideoMetadata(YouTubeVideo video, JCas jCas) throws IOException, list.addToIndexes(); } + youTube.setName(video._title); youTube.setUrl(video.getVideoUrl()); youTube.setChannelName(video._channelName); youTube.setChannelURL(video._channelUrl); From 3c602f1ecd2c0a2deaf2504319e40147b1667c29 Mon Sep 17 00:00:00 2001 From: Mocretion Date: Sat, 5 Oct 2024 18:30:46 +0200 Subject: [PATCH 8/8] Added video playlist to metadata --- .../DockerUnifiedUIMAInterface/io/reader/DUUIYouTubeReader.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/io/reader/DUUIYouTubeReader.java b/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/io/reader/DUUIYouTubeReader.java index b261ef4..87fa3f4 100644 --- a/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/io/reader/DUUIYouTubeReader.java +++ b/src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/io/reader/DUUIYouTubeReader.java @@ -461,6 +461,8 @@ private void setVideoMetadata(YouTubeVideo video, JCas jCas) throws IOException, FSList list = FSList.create(jCas, playlists); list.addToIndexes(); + + youTube.setPlaylist(list); } youTube.setName(video._title);