private static <T extends Resource> T getProvider(Map<String, String> providerConfMap, Class<T> type) throws ResourceInitializationException { Resource resource = GLOBAL_CONF_TO_RESOURCE.get(providerConfMap); if (resource == null) { resource = BaseExperimentBuilder .buildResource(BaseExperimentBuilder.buildHandleFromMap(providerConfMap), type); } if (resource == null) { throw new ResourceInitializationException(); } GLOBAL_CONF_TO_RESOURCE.put(providerConfMap, resource); return type.cast(resource); }
public static <T extends Resource> List<T> createResourceList(Object o, Class<T> type) { List<T> resources = null; if (o instanceof String) { String description = (String) o; Yaml yaml = new Yaml(); @SuppressWarnings("unchecked") List<Map<String, String>> ao = (List<Map<String, String>>) yaml.load(description); resources = createResourceList(ao, type); } else { // TODO: Remove this deprecated call at some point in time String[] expListenerNames = (String[]) o; resources = createResourceList(expListenerNames, type); } return resources; } }
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> tuples) throws ResourceInitializationException { String pp = (String) tuples.get("persistence-provider"); if (pp == null) { throw new ResourceInitializationException(new IllegalArgumentException( "Must provide a parameter of type <persistence-provider>")); } this.persistence = BaseExperimentBuilder.loadProvider(pp, RetrievalEvalPersistenceProvider.class); return true; }
public static <T extends Resource> T loadProvider(AnyObject ao, Class<T> type) throws ResourceInitializationException { ResourceHandle handle = buildHandleFromObject(ao); try { return buildResource(handle, type); } catch (Exception e) { throw new ResourceInitializationException( ResourceInitializationException.ERROR_INITIALIZING_FROM_DESCRIPTOR, new Object[] { type.getCanonicalName(), ao }, e); } }
public static <T extends Resource> T buildResource(ResourceHandle handle, Class<T> type) throws ResourceInitializationException { Map<String, Object> tuples = Maps.newLinkedHashMap(); try { Class<? extends Resource> resourceClass = loadFromClassOrInherit(handle, Resource.class, tuples); return buildResource(resourceClass, tuples, type); } catch (Exception e) { throw new ResourceInitializationException( ResourceInitializationException.ERROR_INITIALIZING_FROM_DESCRIPTOR, new Object[] { type.getCanonicalName(), handle }, e); } }
public ECDDriver(String resource, String uuid) throws Exception { TypeSystemDescription typeSystem = TypeSystemDescriptionFactory.createTypeSystemDescription(); this.builder = new BaseExperimentBuilder(uuid, resource, typeSystem); this.config = builder.getConfiguration(); }
public static AnalysisEngine[] createAnnotators(String description) { Yaml yaml = new Yaml(); @SuppressWarnings("unchecked") List<Map<String, String>> names = (List<Map<String, String>>) yaml.load(description); List<AnalysisEngine> annotators = Lists.newArrayList(); for (Map<String, String> name : names) { try { Map<String, Object> tuples = Maps.newHashMap(); ResourceHandle handle = buildHandleFromMap(name); Class<? extends JCasAnnotator_ImplBase> aClass = loadFromClassOrInherit(handle, JCasAnnotator_ImplBase.class, tuples); Object[] params = getParamList(tuples); AnalysisEngineDescription aeDesc = AnalysisEngineFactory.createPrimitiveDescription(aClass, params); annotators.add(UIMAFramework.produceAnalysisEngine(aeDesc)); } catch (Exception e) { System.err.printf("[ERROR] %s Caused by:\n", e); Throwables.getRootCause(e).printStackTrace(); } } return annotators.toArray(new AnalysisEngine[0]); }
@Override public <T extends Resource> T initializeResource(AnyObject config, String node, Class<T> type) throws Exception { AnyObject descriptor = config.getAnyObject(node); if (descriptor == null) { return null; } Map<String, Object> tuples = Maps.newLinkedHashMap(); Class<? extends Resource> cseClass = getFromClassOrInherit(descriptor, Resource.class, tuples); return buildResource(cseClass, tuples, type); }
@Override public void initialize() throws ResourceInitializationException { this.dataset = (String) getConfigParameterValue("dataset"); this.experimentUuid = (String) getConfigParameterValue(BaseExperimentBuilder.EXPERIMENT_UUID_PROPERTY); this.stageId = (Integer) getConfigParameterValue(BaseExperimentBuilder.STAGE_ID_PROPERTY); String decoratorsNames = (String) getConfigParameterValue("decorators"); if (decoratorsNames != null) { this.decorators = BaseExperimentBuilder.createAnnotators(decoratorsNames); } String pp = (String) getConfigParameterValue("persistence-provider"); if (pp == null) { throw new ResourceInitializationException(new IllegalArgumentException( String.format("%s must be provided with a parameter of type <persistence-provider>", getClass().getSimpleName()))); } this.persistence = BaseExperimentBuilder.loadProvider(pp, ExperimentPersistenceProvider.class); }
public static AnalysisEngineDescription createAnalysisEngineDescription( Map<String, Object> tuples, Class<? extends AnalysisComponent> comp) throws ResourceInitializationException { Object[] params = getParamList(tuples); AnalysisEngineDescription aeDesc = AnalysisEngineFactory.createPrimitiveDescription(comp, params); StringBuilder sb = new StringBuilder(comp.getSimpleName()); if (params.length > 0) { appendMethodSignature(sb, tuples); } String name = sb.toString().replaceAll("\n", " ").trim(); aeDesc.getAnalysisEngineMetaData().setName(name); return aeDesc; }
@Override public AnalysisEngine buildPipeline(AnyObject config, String pipeline, int stageId, FixedFlow funnel, boolean outputNewCASes) throws Exception { loadTypePriorities(config); Iterable<AnyObject> iterable = config.getIterable(pipeline); FlowControllerDescription fcd = FlowControllerFactory .createFlowControllerDescription(FixedFlowController797182.class); AnalysisEngineDescription aee = buildPipeline(stageId, iterable, fcd); if (funnel != null) { FixedFlow fc = (FixedFlow) aee.getAnalysisEngineMetaData().getFlowConstraints(); funnel.setFixedFlow(fc.getFixedFlow()); aee.getAnalysisEngineMetaData().setFlowConstraints(funnel); } aee.getAnalysisEngineMetaData().getOperationalProperties().setOutputsNewCASes(outputNewCASes); aee.getAnalysisEngineMetaData().setName(pipeline); return AnalysisEngineFactory.createAggregate(aee); }
@Override public AnalysisEngine buildPipeline(AnyObject config, String pipeline, int stageId) throws Exception { try { return buildPipeline(config, pipeline, stageId, null, true); } catch (Exception e) { throw new ResourceInitializationException( ResourceInitializationException.ERROR_INITIALIZING_FROM_DESCRIPTOR, new Object[] { pipeline, config }, e); } }
private AnalysisEngineDescription buildPipeline(int stageId, Iterable<AnyObject> pipeline, FlowControllerDescription fcd) throws Exception { AggregateBuilder builder = new AggregateBuilder(null, null, fcd); int phase = 1; for (AnyObject aeDescription : pipeline) { AnalysisEngineDescription description = buildComponent(stageId, phase, aeDescription); builder.add(description); phase++; } return builder.createAggregateDescription(); }
public static void runPipeline(String pipelinePath, String datasetName, String sequenceId, String question, String outputXmiPath) throws Exception { String uuid = UUID.randomUUID().toString(); TypeSystemDescription typeSystem = TypeSystemDescriptionFactory.createTypeSystemDescription(); ExperimentBuilder builder = new BaseExperimentBuilder(uuid, pipelinePath, typeSystem); AdHocDriver driver = new AdHocDriver(builder); AdHocSource source = new BaseAdHocSource() { public void publish(String quuid, String question) throws InterruptedException { DataElement result = new DataElement(datasetName, sequenceId, question, quuid); getReader().putQuestion(result); } }; XmiPrintCallbackListener callback = new XmiPrintCallbackListener(new File(outputXmiPath)); AdHocCollectionReader reader = driver.setupAndRun(source, callback); String quuid = UUID.randomUUID().toString(); source.publish(quuid, question); callback.await(); reader.shutdown(); }
@Override public AnalysisEngine buildPostProcess(AnyObject config, String pipeline, int stageId) throws Exception { try { return buildPipeline(config, pipeline, stageId, null, false); } catch (Exception e) { throw new ResourceInitializationException( ResourceInitializationException.ERROR_INITIALIZING_FROM_DESCRIPTOR, new Object[] { pipeline, config }, e); } }
public static <T extends Resource> T loadProvider(String provider, Class<T> type) throws ResourceInitializationException { Yaml yaml = new Yaml(); @SuppressWarnings("unchecked") Map<String, String> map = (Map<String, String>) yaml.load(provider); ResourceHandle handle = buildHandleFromMap(map); try { return buildResource(handle, type); } catch (Exception e) { throw new ResourceInitializationException( ResourceInitializationException.ERROR_INITIALIZING_FROM_DESCRIPTOR, new Object[] { type.getCanonicalName(), provider }, e); } }
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> tuples) throws ResourceInitializationException { String pp = (String) tuples.get("persistence-provider"); if (pp == null) { throw new ResourceInitializationException(new IllegalArgumentException( "Must provide a parameter of type <persistence-provider>")); } this.persistence = BaseExperimentBuilder.loadProvider(pp, RetrievalEvalPersistenceProvider.class); return true; }
public AsyncDriver(String resource, String uuid, OpMode op) throws Exception { this.opMode = op; this.localConfig = ConfigurationLoader.load(resource); if (opMode == OpMode.PRODUCER || opMode == OpMode.REPORT) { resource += "-producer"; this.config = ConfigurationLoader.load(resource); } else { resource += "-consumer"; this.config = ConfigurationLoader.load(resource); } TypeSystemDescription typeSystem = TypeSystemDescriptionFactory.createTypeSystemDescription(); this.builder = new BaseExperimentBuilder(uuid, resource, typeSystem); this.asyncConfig = builder.initializeResource(config, "async-configuration", AsyncConfiguration.class); }
@Override public void initialize(UimaContext context) throws ResourceInitializationException { Object listenerNames = (Object) context.getConfigParameterValue("listeners"); if (listenerNames != null) { listeners = BaseExperimentBuilder.createResourceList(listenerNames, TraceListener.class); } Object experimentListenerNames = context.getConfigParameterValue("experiment-listeners"); if (experimentListenerNames != null) { this.experimentListeners = BaseExperimentBuilder.createResourceList(experimentListenerNames, ExperimentListener.class); } }
@Override public AnalysisEngine buildPipeline(AnyObject config, String pipeline, int stageId, FixedFlow funnel) throws Exception { try { return buildPipeline(config, pipeline, stageId, funnel, true); } catch (Exception e) { Throwables.propagateIfInstanceOf(e, ResourceInitializationException.class); throw new ResourceInitializationException( ResourceInitializationException.ERROR_INITIALIZING_FROM_DESCRIPTOR, new Object[] { pipeline, config }, e); } }