forked from texttechnologylab/DockerUnifiedUIMAInterface
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ef4241
commit de2f0b7
Showing
10 changed files
with
456 additions
and
123 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
95 changes: 95 additions & 0 deletions
95
...n/java/org/texttechnologylab/DockerUnifiedUIMAInterface/composer/DUUISegmentedWorker.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,95 @@ | ||
package org.texttechnologylab.DockerUnifiedUIMAInterface.composer; | ||
|
||
import org.apache.uima.UIMAException; | ||
import org.apache.uima.fit.factory.JCasFactory; | ||
import org.apache.uima.jcas.JCas; | ||
import org.apache.uima.resource.metadata.TypeSystemDescription; | ||
import org.texttechnologylab.DockerUnifiedUIMAInterface.DUUIComposer; | ||
import org.texttechnologylab.DockerUnifiedUIMAInterface.io.DUUICollectionDBReader; | ||
import org.texttechnologylab.DockerUnifiedUIMAInterface.pipeline_storage.DUUIPipelineDocumentPerformance; | ||
import org.texttechnologylab.DockerUnifiedUIMAInterface.pipeline_storage.IDUUIStorageBackend; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
public class DUUISegmentedWorker implements Runnable { | ||
private final int threadIndex; | ||
private final AtomicBoolean shutdown; | ||
private final DUUIComposer.PipelinePart pipelinePart; | ||
private final DUUICollectionDBReader collectionReader; | ||
private final TypeSystemDescription typesystem; | ||
private final IDUUIStorageBackend backend; | ||
private final String name; | ||
private final List<String> pipelineUUIDs; | ||
private final int pipelinePosition; | ||
|
||
public DUUISegmentedWorker(int threadIndex, AtomicBoolean shutdown, DUUIComposer.PipelinePart pipelinePart, DUUICollectionDBReader collectionReader, TypeSystemDescription typesystem, IDUUIStorageBackend backend, String name, List<String> pipelineUUIDs) { | ||
this.threadIndex = threadIndex; | ||
this.shutdown = shutdown; | ||
this.pipelinePart = pipelinePart; | ||
this.collectionReader = collectionReader; | ||
this.typesystem = typesystem; | ||
this.backend = backend; | ||
this.name = name; | ||
this.pipelineUUIDs = pipelineUUIDs; | ||
this.pipelinePosition = pipelineUUIDs.indexOf(pipelinePart.getUUID()); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
JCas jCas; | ||
try { | ||
jCas = JCasFactory.createJCas(typesystem); | ||
} catch (UIMAException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
boolean trackErrorDocs = false; | ||
if (backend != null) { | ||
trackErrorDocs = backend.shouldTrackErrorDocs(); | ||
} | ||
|
||
while (true) { | ||
long waitTimeStart = System.nanoTime(); | ||
while (true) { | ||
if (shutdown.get()) { | ||
jCas.reset(); | ||
return; | ||
} | ||
try { | ||
if (!collectionReader.getNextCas(jCas, pipelinePart.getUUID(), pipelinePosition)) { | ||
Thread.sleep(300); | ||
} else { | ||
break; | ||
} | ||
} | ||
catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
long waitTimeEnd = System.nanoTime(); | ||
|
||
boolean status = false; | ||
try { | ||
DUUIPipelineDocumentPerformance perf = new DUUIPipelineDocumentPerformance(name, waitTimeEnd - waitTimeStart, jCas, trackErrorDocs); | ||
|
||
pipelinePart.getDriver().run(pipelinePart.getUUID(), jCas, perf); | ||
|
||
if (backend != null) { | ||
backend.addMetricsForDocument(perf); | ||
} | ||
|
||
status = true; | ||
|
||
} catch (Exception e) { | ||
status = false; | ||
e.printStackTrace(); | ||
System.err.println(e.getMessage()); | ||
System.err.println("Error in pipeline part " + pipelinePart.getUUID() + ", continuing with next document!"); | ||
} | ||
finally { | ||
collectionReader.updateCas(jCas, pipelinePart.getUUID(), status, pipelineUUIDs); | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/io/DUUICollectionDBReader.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,21 @@ | ||
package org.texttechnologylab.DockerUnifiedUIMAInterface.io; | ||
|
||
import org.apache.uima.jcas.JCas; | ||
|
||
import java.util.List; | ||
|
||
public interface DUUICollectionDBReader extends DUUICollectionReader { | ||
/** | ||
* Fill and get the next JCas based on the tool | ||
* | ||
* @param pCas : JCas to be filled | ||
* @param toolUUID : toolUUID | ||
* @param pipelinePosition | ||
* @return true if cas was filled, false if no cas was filled | ||
*/ | ||
public boolean getNextCas(JCas pCas, String toolUUID, int pipelinePosition); | ||
|
||
void updateCas(JCas pCas, String toolUUID, boolean status, List<String> pipelineUUIDs); | ||
|
||
boolean finishedLoading(); | ||
} |
1 change: 0 additions & 1 deletion
1
src/main/java/org/texttechnologylab/DockerUnifiedUIMAInterface/io/DUUICollectionReader.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
Oops, something went wrong.