-
Notifications
You must be signed in to change notification settings - Fork 11
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 #111 from Myyyvothrr/main
PDF/bytes reader
- Loading branch information
Showing
4 changed files
with
65 additions
and
1 deletion.
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
30 changes: 30 additions & 0 deletions
30
...ava/org/texttechnologylab/DockerUnifiedUIMAInterface/io/reader/bytes/DUUIBytesReader.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,30 @@ | ||
package org.texttechnologylab.DockerUnifiedUIMAInterface.io.reader.bytes; | ||
|
||
import org.apache.uima.collection.CollectionException; | ||
import org.apache.uima.fit.descriptor.ConfigurationParameter; | ||
import org.apache.uima.jcas.JCas; | ||
import org.apache.uima.jcas.cas.ByteArray; | ||
import org.dkpro.core.api.io.JCasResourceCollectionReader_ImplBase; | ||
import org.dkpro.core.api.resources.CompressionUtils; | ||
|
||
import java.io.InputStream; | ||
|
||
public class DUUIBytesReader extends JCasResourceCollectionReader_ImplBase { | ||
public static final String PARAM_MIME_TYPE = "mimeType"; | ||
@ConfigurationParameter(name = PARAM_MIME_TYPE, mandatory = false) | ||
protected String mimeType; | ||
|
||
@Override | ||
public void getNext(JCas jCas) throws CollectionException { | ||
Resource res = nextFile(); | ||
initCas(jCas, res); | ||
try (InputStream is = CompressionUtils.getInputStream(res.getLocation(), res.getInputStream())) { | ||
byte[] content = is.readAllBytes(); | ||
ByteArray data = new ByteArray(jCas, content.length); | ||
data.copyFromArray(content, 0, 0, content.length); | ||
jCas.setSofaDataArray(data, mimeType); | ||
} catch (Exception e) { | ||
throw new CollectionException(e); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...in/java/org/texttechnologylab/DockerUnifiedUIMAInterface/io/reader/pdf/DUUIPDFReader.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,16 @@ | ||
package org.texttechnologylab.DockerUnifiedUIMAInterface.io.reader.pdf; | ||
|
||
import org.apache.uima.UimaContext; | ||
import org.apache.uima.resource.ResourceInitializationException; | ||
import org.texttechnologylab.DockerUnifiedUIMAInterface.io.reader.bytes.DUUIBytesReader; | ||
|
||
public class DUUIPDFReader extends DUUIBytesReader { | ||
@Override | ||
public void initialize(UimaContext aContext) throws ResourceInitializationException { | ||
super.initialize(aContext); | ||
|
||
if (mimeType == null) { | ||
mimeType = "application/pdf"; | ||
} | ||
} | ||
} |